Class IpmiAsyncConnector
java.lang.Object
org.metricshub.ipmi.core.api.async.IpmiAsyncConnector
- All Implemented Interfaces:
ConnectionListener
Asynchronous API for connecting to BMC via IPMI.
Creating connection consists of the following steps:- Create a
Connectionand get itsConnectionHandlewithcreateConnection(InetAddress, int) - Get
CipherSuites that are available for the connection viagetAvailableCipherSuites(ConnectionHandle) - Pick
CipherSuiteandPrivilegeLevelthat will be used during session and getGetChannelAuthenticationCapabilitiesResponseDatato find out allowed authentication options viagetChannelAuthenticationCapabilities(ConnectionHandle, CipherSuite, PrivilegeLevel) - Provide username, password and (if the BMC needs it) the BMC Kg key and
start session via
openSession(ConnectionHandle, String, String, byte[]), which also raises it to the requested Operator or Administrator privilege
Register a listener for the responses with registerListener(IpmiResponseListener), then send messages
with sendMessage(ConnectionHandle, PayloadCoder, boolean): the response to a message that is not one-way,
or its failure (an IpmiError), reaches the listeners with the tag that sendMessage() returned.
To close session call closeSession(ConnectionHandle)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNumber of times a message without a reply is sent again, untilsetRetries(int)changes it.static final String -
Constructor Summary
ConstructorsConstructorDescriptionIpmiAsyncConnector(int port) StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port.IpmiAsyncConnector(int port, long pingPeriod) StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port and ping period.IpmiAsyncConnector(int port, InetAddress address) StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port and IP interface. -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseConnection(ConnectionHandle handle) Closes the connection with the given handle, forgets its session, and wipes the credentials the handle keeps.voidcloseSession(ConnectionHandle connectionHandle) Closes the session with the remote host if it is currently in open state, and wipes the password and the BMC key (Kg) the handle keeps.createConnection(InetAddress address, int port) Creates connection to the remote host.createConnection(InetAddress address, int port, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel) Creates connection to the remote host, with pre setCipherSuiteandPrivilegeLevel, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.getAvailableCipherSuites(ConnectionHandle connectionHandle) GetsCipherSuites available for the connection with the remote host.getChannelAuthenticationCapabilities(ConnectionHandle connectionHandle, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) Declares the cipher suite and the privilege of the session, and returns the authentication capabilities of the remote host thatgetAvailableCipherSuites(ConnectionHandle)read (requested at the User level): sends nothing.getExistingSessionForCriteria(InetAddress remoteAddress, int remotePort, String user) Returns session already bound to given connection handle fulfilling given criteria.intReturns how many times a message without a reply is sent again.intgetTimeout(ConnectionHandle handle) Returns the timeout of a single message on the given connection.openSession(ConnectionHandle connectionHandle, String username, byte[] password, byte[] bmcKey) Establishes the session with the remote host, with the password as bytes: the caller can then clear them once the session is open, which an immutableStringdoes not allow.openSession(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) Establishes the session with the remote host, and raises it to the requested privilege when that is Operator or Administrator (Set Session Privilege Level, IPMI 2.0 section 22.18: every session starts at User).voidprocessRequest(IpmiPayload payload) Deprecated.voidprocessRequest(IpmiPayload payload, int handle) Notifies theConnectionListenerof a payload the remote system sent on its own initiative (Serial over LAN data).voidprocessResponse(ResponseData responseData, int handle, int tag, Exception exception) Notifies theConnectionListeners of the one of the following events: response to the request tagged with id arrived request tagged with id timed outvoidRegisters the listener for incoming messages.voidregisterListener(IpmiResponseListener listener) Registers the listener so it will be notified of incoming messages.intretry(ConnectionHandle connectionHandle, int tag, PayloadType messagePayloadType) Attempts to retry sending a message.intsendMessage(ConnectionHandle connectionHandle, PayloadCoder request, boolean isOneWay) Sends the IPMI message to the remote host.voidsetRetries(int retries) Sets how many times a message without a reply is sent again, or a login whose step got no reply is started again from Open Session.voidsetTimeout(int timeout) Sets the timeout of the messages of the connections created from now on.voidsetTimeout(ConnectionHandle handle, int timeout) Changes the timeout value for connection with the given handle.voidtearDown()Finalizes the connector, closes all connections, and wipes the credentials of their sessions.voidUnregisters the listener so it will no longer receive notifications of received messages.voidunregisterListener(IpmiResponseListener listener) Unregisters the listener so it will no longer receive notifications of received answers.
-
Field Details
-
FAILED_TO_RECEIVE_ANSWER_CAUSE_MESSAGE
- See Also:
-
DEFAULT_RETRIES
public static final int DEFAULT_RETRIESNumber of times a message without a reply is sent again, untilsetRetries(int)changes it.- See Also:
-
-
Constructor Details
-
IpmiAsyncConnector
StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port. The wildcard IP address will be used.- Parameters:
port- - the port that will be used byIpmiAsyncConnectorto communicate with the remote hosts.- Throws:
IOException- when the port cannot be bound
-
IpmiAsyncConnector
StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port and IP interface.- Parameters:
port- - the port that will be used byIpmiAsyncConnectorto communicate with the remote hosts.address- - the IP address that will be used byIpmiAsyncConnectorto communicate with the remote hosts.- Throws:
IOException- when the port cannot be bound
-
IpmiAsyncConnector
StartsIpmiAsyncConnectorand initiates theConnectionManagerat the given port and ping period.- Parameters:
port- the port that will be used byIpmiAsyncConnectorto communicate with the remote hosts.pingPeriod- the period between sending keep-alive messages to the remote host.- Throws:
IOException- When ConnectionManager cannot be created due to an IO error.
-
-
Method Details
-
setRetries
public void setRetries(int retries) Sets how many times a message without a reply is sent again, or a login whose step got no reply is started again from Open Session.- Parameters:
retries- the number of resends, 0 to send every message once- Throws:
IllegalArgumentException- when negative
-
getRetries
public int getRetries()Returns how many times a message without a reply is sent again.- Returns:
- the number of resends
-
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- Throws:
IllegalArgumentException- when the timeout is less than one millisecond
-
createConnection
Creates connection to the remote host.- Parameters:
address- -InetAddressof the remote hostport- - remote UDP port- Returns:
- handle to the connection to the remote host
- Throws:
IOException- when the connection cannot be created
-
createConnection
public ConnectionHandle createConnection(InetAddress address, int port, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel) throws IOException Creates connection to the remote host, with pre setCipherSuiteandPrivilegeLevel, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.- Parameters:
address- -InetAddressof the remote hostport- - remote UDP portcipherSuite- - the cipher suite of the sessionprivilegeLevel- - the privilege level requested for the session- Returns:
- handle to the connection to the remote host
- Throws:
IOException- when the connection cannot be created
-
getAvailableCipherSuites
public List<CipherSuite> getAvailableCipherSuites(ConnectionHandle connectionHandle) throws Exception GetsCipherSuites available for the connection with the remote host.- Parameters:
connectionHandle-ConnectionHandleto the connection created before- Returns:
- list of the
CipherSuites that are allowed during the connection - 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 connectionsException- when sending message to the managed system fails- See Also:
-
getChannelAuthenticationCapabilities
public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthenticationCapabilities(ConnectionHandle connectionHandle, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) throws Exception Declares the cipher suite and the privilege of the session, and returns the authentication capabilities of the remote host thatgetAvailableCipherSuites(ConnectionHandle)read (requested at the User level): sends nothing.- Parameters:
connectionHandle- -ConnectionHandleassociated with the hostcipherSuite- -CipherSuitethat will be used during the connectionrequestedPrivilegeLevel- -PrivilegeLevelthat is requested 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
-
openSession
public Session openSession(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) throws Exception Establishes the session with the remote host, and raises it to the requested privilege when that is Operator or Administrator (Set Session Privilege Level, IPMI 2.0 section 22.18: every session starts at User). ForPrivilegeLevel.MaximumAvailable, the session is requested at Administrator, then at Operator and at User when the BMC refuses the role to the account, and set to User right after the handshake: the caller raises it when a command needs more.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.username- - the usernamepassword- - password matching the usernamebmcKey- - the key that should be provided if the two-key authentication is enabled, null otherwise.- Returns:
- object representing newly created
Session - Throws:
ConnectionException- when connection is in the state that does not allow to perform this operation, or no reply came after all the triesSessionException- when the BMC refuses to raise the session to the requested privilege: the session is closed, and the cause is theIPMIExceptionof the completion codeException- when sending message to the managed system or initializing one of the cipherSuite's algorithms fails
-
openSession
public Session openSession(ConnectionHandle connectionHandle, String username, byte[] password, byte[] bmcKey) throws Exception Establishes the session with the remote host, with the password as bytes: the caller can then clear them once the session is open, which an immutableStringdoes not allow. When the requested privilege is Operator or Administrator, the session is raised to it with Set Session Privilege Level right after the handshake (IPMI 2.0 section 22.18: every session starts at User); a refusal closes the session. ForPrivilegeLevel.MaximumAvailable, the session is requested at Administrator, then at Operator and at User when the BMC refuses the role to the account, and set to User right after the handshake: the caller raises it when a command needs more.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.username- - the usernamepassword- - password matching the username, as sent to the BMC (UTF-8 for a text password), at most 20 bytesbmcKey- - the key that should be provided if the two-key authentication is enabled, null otherwise.- Returns:
- object representing newly created
Session - Throws:
ConnectionException- when connection is in the state that does not allow to perform this operation, or no reply came after all the triesSessionException- when the BMC refuses to raise the session to the requested privilege: the session is closed, and the cause is theIPMIExceptionof the completion codeException- when sending message to the managed system or initializing one of the cipherSuite's algorithms fails
-
getExistingSessionForCriteria
public Session getExistingSessionForCriteria(InetAddress remoteAddress, int remotePort, String user) Returns session already bound to given connection handle fulfilling given criteria.- Parameters:
remoteAddress- IP addres of the managed systemremotePort- UDP port of the managed systemuser- IPMI user for whom the connection is established- Returns:
- session object fulfilling given criteria, or null if no session was registered for such connection.
-
closeSession
Closes the session with the remote host if it is currently in open state, and wipes the password and the BMC key (Kg) the handle keeps.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.- 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
-
sendMessage
public int sendMessage(ConnectionHandle connectionHandle, PayloadCoder request, boolean isOneWay) throws Exception Sends the IPMI message to the remote host.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.request- -PayloadCodercontaining the request to be sentisOneWay- - true for a message whose reply nobody waits for (the reply is discarded, and its timeout is not reported), false to receive the reply through the registered listeners- Returns:
- the tag of the message, which the response delivered to the listeners carries
(
IpmiResponse.getTag()) - Throws:
ConnectionException- when the session is not open, or the message window stayed full, at every tryIllegalStateException- when the connection is closedException- when sending message to the managed system or initializing one of the cipherSuite's algorithms fails
-
retry
public int retry(ConnectionHandle connectionHandle, int tag, PayloadType messagePayloadType) throws ConnectionException Attempts to retry sending a message.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.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
-
registerListener
Registers the listener so it will be notified of incoming messages.- Parameters:
listener-IpmiResponseListenerto processResponse
-
unregisterListener
Unregisters the listener so it will no longer receive notifications of received answers.- Parameters:
listener- - theIpmiResponseListenerto unregister
-
registerIncomingPayloadListener
Registers the listener for incoming messages.- Parameters:
listener- theInboundMessageListenerto register.
-
unregisterIncomingPayloadListener
Unregisters the listener so it will no longer receive notifications of received messages.- Parameters:
listener- theInboundMessageListenerto unregister.
-
processResponse
Description copied from interface:ConnectionListenerNotifies theConnectionListeners of the one of the following events:- response to the request tagged with id arrived
- request tagged with id timed out
- Specified by:
processResponsein interfaceConnectionListener- Parameters:
responseData- -ResponseDataspecific for the request if it was completed successfully, null if it timed out or an error occured during decoding.handle- - the id of the connection that received the messagetag- - tag of the request-response pairexception- - null if everything went correctly or timeout occured, contains exception that occured during decoding if it failed.
-
processRequest
Deprecated.the connections callprocessRequest(IpmiPayload, int)Notifies the inbound listeners that take the payload from any connection, as 1.2.02 did.- Specified by:
processRequestin interfaceConnectionListener- Parameters:
payload- the payload received
-
processRequest
Description copied from interface:ConnectionListenerNotifies theConnectionListenerof a payload the remote system sent on its own initiative (Serial over LAN data). CallsConnectionListener.processRequest(IpmiPayload)by default.- Specified by:
processRequestin interfaceConnectionListener- Parameters:
payload- - the payload receivedhandle- - the id of the connection that received the payload
-
closeConnection
Closes the connection with the given handle, forgets its session, and wipes the credentials the handle keeps. The requests still waiting for a reply on the connection fail with aConnectionException.- Parameters:
handle- the handle of the connection
-
tearDown
public void tearDown()Finalizes the connector, closes all connections, and wipes the credentials of their sessions. -
setTimeout
Changes the timeout value for connection with the given handle.- Parameters:
handle- -ConnectionHandleassociated with the remote host.timeout- - new timeout value in ms
-
getTimeout
Returns the timeout of a single message on the given connection.- Parameters:
handle-ConnectionHandleof the connection- Returns:
- the timeout in milliseconds after which a message without a reply is reported as timed out
-
processRequest(IpmiPayload, int)