Class Connection
java.lang.Object
java.util.TimerTask
org.metricshub.ipmi.core.connection.Connection
- All Implemented Interfaces:
Runnable
,MachineObserver
A connection with the specific remote host.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes the session.void
connect
(InetAddress address, int port, long pingPeriod) Starts the connection to the specifiedInetAddress
void
connect
(InetAddress address, int port, long pingPeriod, boolean skipCiphers) Starts the connection to the specifiedInetAddress
void
Ends the connection.getAvailableCipherSuites
(int tag) Gets from the managed system supportedCipherSuite
s.getChannelAuthenticationCapabilities
(int tag, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) Queries the managed system for the details of the authentification process.static CipherSuite
int
int
int
int
boolean
isActive()
Checks if the connection is activeboolean
Checks if session is currently open.void
notify
(StateMachineAction action) Notifies observer of action performed by the State Machine.void
notifyRequestListeners
(IpmiPayload payload) void
notifyResponseListeners
(int handle, int tag, ResponseData responseData, Exception exception) void
registerListener
(ConnectionListener listener) Registers the listener so it will receive notifications from this connectionint
retry
(int tag, PayloadType messagePayloadType) Attempts to retry sending a message.void
run()
TimerTask
runner - periodically sends no-op messages to keep the session upint
sendMessage
(PayloadCoder payloadCoder, boolean isOneWay) Attempts to send IPMI request to the managed system.void
setTimeout
(int timeout) int
startSession
(int tag, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, String password, byte[] bmcKey) Initiates the session with the managed system.void
unregisterListener
(ConnectionListener listener) Unregisters theConnectionListener
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
Constructor Details
-
Connection
Creates the connection.- Parameters:
messenger
- -Messenger
associated with the properConstants.IPMI_PORT
handle
- - id of the connection
-
-
Method Details
-
getHandle
public int getHandle() -
getTimeout
public int getTimeout() -
setTimeout
public void setTimeout(int timeout) -
registerListener
Registers the listener so it will receive notifications from this connection- Parameters:
listener
- -ConnectionListener
to processResponse
-
unregisterListener
Unregisters theConnectionListener
- Parameters:
listener
-ConnectionListener
to unregister
-
connect
Starts the connection to the specifiedInetAddress
- Parameters:
address
- - IP address of the managed systempingPeriod
- - frequency of the no-op commands that will be sent to keep up the session- Throws:
IOException
- - when properties file was not foundFileNotFoundException
- - when properties file was not found- See Also:
-
connect
public void connect(InetAddress address, int port, long pingPeriod, boolean skipCiphers) throws IOException Starts the connection to the specifiedInetAddress
- Parameters:
address
- - IP address of the managed systempingPeriod
- - frequency of the no-op commands that will be sent to keep up the sessionskipCiphers
- - determines if the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases should be skipped- Throws:
IOException
- - when properties file was not foundFileNotFoundException
- - when properties file was not found- See Also:
-
disconnect
public void disconnect()Ends the connection.- See Also:
-
isActive
public boolean isActive()Checks if the connection is active- Returns:
- true if the connection is active, false otherwise
- See Also:
-
getAvailableCipherSuites
Gets from the managed system supportedCipherSuite
s. Should be performed only immediately afterconnect(InetAddress, int, int)
.- Parameters:
tag
- - the integer from range 0-63 to match request with response- Returns:
- list of the
CipherSuite
s supported by the managed system. - Throws:
ConnectionException
- when connection is in the state that does not allow to perform this operation.Exception
- when sending message to the managed system fails
-
getChannelAuthenticationCapabilities
public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthenticationCapabilities(int tag, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) throws Exception Queries the managed system for the details of the authentification process. Must be performed aftergetAvailableCipherSuites(int)
- Parameters:
tag
- - the integer from range 0-63 to match request with responsecipherSuite
- -CipherSuite
requested for the sessionrequestedPrivilegeLevel
- -PrivilegeLevel
requested for the session- Returns:
GetChannelAuthenticationCapabilitiesResponseData
- Throws:
ConnectionException
- when connection is in the state that does not allow to perform this operation.Exception
- when sending message to the managed system fails
-
startSession
public int startSession(int tag, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, String password, byte[] bmcKey) throws Exception Initiates the session with the managed system. Must be performed aftergetChannelAuthenticationCapabilities(int, CipherSuite, PrivilegeLevel)
orcloseSession()
- Parameters:
tag
- - the integer from range 0-63 to match request with responsecipherSuite
- -CipherSuite
that will be used during the sessionprivilegeLevel
- - requestedPrivilegeLevel
- most of the time it will bePrivilegeLevel.User
username
- - the usernamepassword
- - the password matching the usernamebmcKey
- - the key that should be provided if the two-key authentication is enabled, null otherwise.- Returns:
- id of the new session
- Throws:
ConnectionException
- when connection is in the state that does not allow to perform this operation.Exception
- when sending message to the managed system or initializing one of the cipherSuite's algorithms fails
-
closeSession
Closes the session. Can be performed only if the session is already open.- Throws:
ConnectionException
- when connection is in the state that does not allow to perform this operation.
-
sendMessage
Attempts to send IPMI request to the managed system.- Parameters:
payloadCoder
- -PayloadCoder
representing the requestisOneWay
- - tells whether message is one way or not- Returns:
- ID of the message that will be also attached to the response to pair request with response if queue was not full and message was sent, -1 if sending of the message failed.
- Throws:
ConnectionException
- when connection isn't in state where sending commands is allowedArithmeticException
- whenConnection
runs out of available ID's for the messages. If this happens session needs to be restarted.
-
retry
Attempts to retry sending a message.- Parameters:
tag
- - tag of the message to retrymessagePayloadType
- -PayloadType
of the message that should be retried- Returns:
- new tag if message was retried, -1 if operation failed
- Throws:
ConnectionException
- when connection isn't in state where sending commands is allowed
-
notifyResponseListeners
public void notifyResponseListeners(int handle, int tag, ResponseData responseData, Exception exception) -
notifyRequestListeners
-
notify
Description copied from interface:MachineObserver
Notifies observer of action performed by the State Machine.- Specified by:
notify
in interfaceMachineObserver
- Parameters:
action
- - action performed
-
run
public void run()TimerTask
runner - periodically sends no-op messages to keep the session up -
getRemoteMachineAddress
-
getRemoteMachinePort
public int getRemoteMachinePort() -
isSessionValid
public boolean isSessionValid()Checks if session is currently open. -
getNextSessionSequenceNumber
public int getNextSessionSequenceNumber() -
getDefaultCipherSuite
- Returns:
- Default cipher suite (3)
-