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 TypeMethodDescriptionvoidCloses the session.voidconnect(InetAddress address, int port, long pingPeriod) Starts the connection to the specifiedInetAddressvoidconnect(InetAddress address, int port, long pingPeriod, boolean skipCiphers) Starts the connection to the specifiedInetAddressvoidEnds the connection.getAvailableCipherSuites(int tag) Gets from the managed system supportedCipherSuites.getChannelAuthenticationCapabilities(int tag, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) Queries the managed system for the details of the authentification process.static CipherSuiteintintintintbooleanisActive()Checks if the connection is activebooleanChecks if session is currently open.voidnotify(StateMachineAction action) Notifies observer of action performed by the State Machine.voidnotifyRequestListeners(IpmiPayload payload) voidnotifyResponseListeners(int handle, int tag, ResponseData responseData, Exception exception) voidregisterListener(ConnectionListener listener) Registers the listener so it will receive notifications from this connectionintretry(int tag, PayloadType messagePayloadType) Attempts to retry sending a message.voidrun()TimerTaskrunner - periodically sends no-op messages to keep the session upintsendMessage(PayloadCoder payloadCoder, boolean isOneWay) Attempts to send IPMI request to the managed system.voidsetTimeout(int timeout) intstartSession(int tag, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, String password, byte[] bmcKey) Initiates the session with the managed system.voidunregisterListener(ConnectionListener listener) Unregisters theConnectionListenerMethods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
Constructor Details
-
Connection
Creates the connection.- Parameters:
messenger- -Messengerassociated with the properConstants.IPMI_PORThandle- - 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- -ConnectionListenerto processResponse
-
unregisterListener
Unregisters theConnectionListener- Parameters:
listener-ConnectionListenerto 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 supportedCipherSuites. 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
CipherSuites 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- -CipherSuiterequested for the sessionrequestedPrivilegeLevel- -PrivilegeLevelrequested 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- -CipherSuitethat will be used during the sessionprivilegeLevel- - requestedPrivilegeLevel- most of the time it will bePrivilegeLevel.Userusername- - 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- -PayloadCoderrepresenting 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- whenConnectionruns 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- -PayloadTypeof 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:MachineObserverNotifies observer of action performed by the State Machine.- Specified by:
notifyin interfaceMachineObserver- Parameters:
action- - action performed
-
run
public void run()TimerTaskrunner - 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)
-