Class ConnectionManager
java.lang.Object
org.metricshub.ipmi.core.connection.ConnectionManager
Manages multiple
Connections-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longPeriod of the keep-alive messages of the connections created without an explicit one, in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionConnectionManager(int port) Initiates the connection manager.ConnectionManager(int port, long pingPeriod) Initiates the connection manager.ConnectionManager(int port, InetAddress address) Initiates the connection manager.ConnectionManager(Messenger messenger) Initiates the connection manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes all open connections and disconnectsUdpListener.voidcloseConnection(int index) Closes the connection with the given index and releases it; the index is not reused.intcreateConnection(InetAddress address, int port) Creates and initiatesConnectionto the remote host with the default ping frequency.intcreateConnection(InetAddress address, int port, boolean skipCiphers) Creates and initiatesConnectionto the remote host with the default ping frequency.intcreateConnection(InetAddress address, int port, int connectionPingPeriod) Creates and initiatesConnectionto the remote host.intcreateConnection(InetAddress address, int port, int connectionPingPeriod, boolean skipCiphers) Creates and initiatesConnectionto the remote host.static voidfreeTag(int tag) Frees the sessionless tag for further usestatic intThe tag for messages sent outside the session generated by theConnectionManager.getAvailableCipherSuites(int connection) Gets from the managed system supportedCipherSuites.getChannelAuthenticationCapabilities(int connection, 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 (requested at the User level).getConnection(int index) ReturnsConnectionidentified by index.intReturns the timeout of the messages of the connections created from now on.voidregisterListener(int connection, ConnectionListener listener) Registers the listener so it will receive notifications from connectionvoidsetTimeout(int timeout) Sets the timeout of the messages of the connections created from now on.intstartSession(int connection, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, byte[] password, byte[] bmcKey) Initiates the session with the managed system.
-
Field Details
-
DEFAULT_PING_PERIOD
public static final long DEFAULT_PING_PERIODPeriod of the keep-alive messages of the connections created without an explicit one, in milliseconds.- See Also:
-
-
Constructor Details
-
ConnectionManager
Initiates the connection manager. Wildcard IP address will be used.- Parameters:
port- the port at whichUdpListenerwill workpingPeriod- frequency of the no-op commands that will be sent to keep up the session. 0 to disable ping requests.- Throws:
IOException- If UdpMessenger encountered an error
-
ConnectionManager
Initiates the connection manager. Wildcard IP address will be used.- Parameters:
port- - the port at whichUdpListenerwill work- Throws:
IOException- If UdpMessenger encountered an error
-
ConnectionManager
Initiates the connection manager.- Parameters:
port- - the port at whichUdpListenerwill workaddress- - the IP interfaceUdpListenerwill bind to- Throws:
IOException- If UdpMessenger encountered an error
-
ConnectionManager
Initiates the connection manager.- Parameters:
messenger- -Messengerto be used in communication
-
-
Method Details
-
setTimeout
public void setTimeout(int timeout) Sets the timeout of the messages of the connections created from now on.- Parameters:
timeout- the time in milliseconds after which a message without a reply is reported as timed out
-
getTimeout
public int getTimeout()Returns the timeout of the messages of the connections created from now on.- Returns:
- the time in milliseconds after which a message without a reply is reported as timed out
-
close
public void close()Closes all open connections and disconnectsUdpListener. -
generateSessionlessTag
public static int generateSessionlessTag()The tag for messages sent outside the session generated by theConnectionManager. Auto-incremented. -
freeTag
public static void freeTag(int tag) Frees the sessionless tag for further use- Parameters:
tag- - tag to free
-
getConnection
ReturnsConnectionidentified by index.- Parameters:
index- - index of the connection to return
-
closeConnection
public void closeConnection(int index) Closes the connection with the given index and releases it; the index is not reused. Closing an already closed connection does nothing. -
createConnection
public int createConnection(InetAddress address, int port, int connectionPingPeriod, boolean skipCiphers) throws IOException Creates and initiatesConnectionto the remote host.- Parameters:
address- -InetAddressof the remote hostconnectionPingPeriod- - 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- Returns:
- index of the connection
- Throws:
IOException- - when the connection cannot be created
-
createConnection
public int createConnection(InetAddress address, int port, int connectionPingPeriod) throws IOException Creates and initiatesConnectionto the remote host.- Parameters:
address- -InetAddressof the remote hostconnectionPingPeriod- - frequency of the no-op commands that will be sent to keep up the session- Returns:
- index of the connection
- Throws:
IOException- - when the connection cannot be created
-
createConnection
Creates and initiatesConnectionto the remote host with the default ping frequency.- Parameters:
address- -InetAddressof the remote host- Returns:
- index of the connection
- Throws:
IOException- when the connection cannot be created
-
createConnection
Creates and initiatesConnectionto the remote host with the default ping frequency.- Parameters:
address- -InetAddressof the remote hostskipCiphers- - determines if the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases should be skipped- Returns:
- index of the connection
- Throws:
IOException- when the connection cannot be created
-
getAvailableCipherSuites
Gets from the managed system supportedCipherSuites. Should be performed only immediately aftercreateConnection(java.net.InetAddress, int, int, boolean).- Parameters:
connection- - index of the connection to get available Cipher Suites from- Returns:
- list of the
CipherSuites supported by the managed system. - Throws:
Ipmi20UnsupportedException- when the BMC does not support IPMI 2.0 (RMCP+): Get Channel Authentication Capabilities, sent first in the IPMI v1.5 format, reports no IPMI v2.0 connectionsConnectionException- 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 connection, 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 (requested at the User level). Sends nothing.- Parameters:
connection- - index of the connection to get Channel Authentication Capabilities fromcipherSuite- -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 the state machine fails
-
startSession
public int startSession(int connection, 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)- Parameters:
connection- - index of the connection that starts the sessioncipherSuite- -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.- 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
-
registerListener
Registers the listener so it will receive notifications from connection- Parameters:
connection- - index of theConnectionto listen tolistener- -ConnectionListenerto processResponse
-