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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intTimeout of a message, in milliseconds, untilsetTimeout(int)changes it. -
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) Declares the cipher suite and the privilege of the session, and returns the authentication capabilities of the managed system thatgetAvailableCipherSuites(int), which must be performed first, read.static CipherSuiteintintintintintbooleanisActive()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) Notifies the listeners of a payload the remote system sent on its own initiative, with the handle of this connection.voidnotifyResponseListeners(int handleId, 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 a no-op message to keep the session up: a Get Device ID (as ipmitool sends) sent one-way, whose reply is discarded unread and whose timeout is not reported to the listeners.intsendMessage(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, byte[] password, byte[] bmcKey) Initiates the session with the managed system.voidunregisterListener(ConnectionListener listener) Unregisters theConnectionListenerMethods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
Field Details
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTTimeout of a message, in milliseconds, untilsetTimeout(int)changes it.- See Also:
-
-
Constructor Details
-
Connection
Creates the connection.- Parameters:
messenger- -Messengerassociated with the properConstants.IPMI_PORThandle- - id of the connection
-
-
Method Details
-
getHandle
public int getHandle() -
getManagedSystemSessionId
public int getManagedSystemSessionId()- Returns:
- the managed system session ID of the last session opened, which the BMC generated
-
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 the connection cannot be created- 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 the connection cannot be created- 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). Sends Get Channel Authentication Capabilities first, in the IPMI v1.5 format at the User level (IPMI 2.0 section 13.13), and Get Channel Cipher Suites, an RMCP+ request, only when its reply reports IPMI v2.0 connections (table 22-15).- Parameters:
tag- - the integer from range 0-63 to match request with response- Returns:
- list of the
CipherSuites supported by the managed system. - Throws:
Ipmi20UnsupportedException- when the BMC does not support IPMI 2.0 (RMCP+)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 Declares the cipher suite and the privilege of the session, and returns the authentication capabilities of the managed system thatgetAvailableCipherSuites(int), which must be performed first, read. Sends nothing.- Parameters:
tag- - unused: the reply was read bygetAvailableCipherSuites(int)cipherSuite- -CipherSuiterequested for the sessionrequestedPrivilegeLevel- -PrivilegeLevelrequested for the session- Returns:
GetChannelAuthenticationCapabilitiesResponseData, requested at the User level- Throws:
ConnectionException- when connection is in the state that does not allow to perform this operation.Exception- when the state machine fails
-
startSession
public int startSession(int tag, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, byte[] 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 handleId, int tag, ResponseData responseData, Exception exception) -
notifyRequestListeners
Notifies the listeners of a payload the remote system sent on its own initiative, with the handle of this connection.- Parameters:
payload- the payload received
-
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 a no-op message to keep the session up: a Get Device ID (as ipmitool sends) sent one-way, whose reply is discarded unread and whose timeout is not reported to the listeners. When the message queue is full, the keep-alive of this period is skipped. -
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)
-