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
Connectionand get associated with itConnectionHandleviacreateConnection(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[])
To send message register for receiving answers via
registerListener(IpmiResponseListener) and send message via
sendMessage(ConnectionHandle, PayloadCoder, boolean)
To close session call closeSession(ConnectionHandle)
-
Field Summary
Fields -
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 handlevoidcloseSession(ConnectionHandle connectionHandle) Closes the session with the remote host if it is currently in open state.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) Gets the authentication capabilities for the connection with the remote host.getExistingSessionForCriteria(InetAddress remoteAddress, int remotePort, String user) Returns session already bound to given connection handle fulfilling given criteria.openSession(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) Establishes the session with the remote host.voidprocessRequest(IpmiPayload payload) 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.voidsetTimeout(ConnectionHandle handle, int timeout) Changes the timeout value for connection with the given handle.voidtearDown()Finalizes the connector and closes all connections.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:
-
-
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 properties file was not found
-
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 properties file was not found
-
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
-
createConnection
Creates connection to the remote host.- Parameters:
address- -InetAddressof the remote host- Returns:
- handle to the connection to the remote host
- Throws:
IOException- when properties file was not foundFileNotFoundException- when properties file was not found
-
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 host- Returns:
- handle to the connection to the remote host
- Throws:
IOException- when properties file was not foundFileNotFoundException- when properties file was not found
-
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:
Exception- when sending message to the managed system fails- See Also:
-
getChannelAuthenticationCapabilities
public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthenticationCapabilities(ConnectionHandle connectionHandle, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) throws Exception Gets the authentication capabilities for the connection with the remote host.- 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 sending message to the managed system fails
-
openSession
public Session openSession(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) throws Exception Establishes the session with the remote host.- 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.- 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
-
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.- 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- - tells whether this message is one way (needs response) 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 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
-
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
- Specified by:
processRequestin interfaceConnectionListener
-
closeConnection
Closes the connection with the given handle -
tearDown
public void tearDown()Finalizes the connector and closes all connections. -
setTimeout
Changes the timeout value for connection with the given handle.- Parameters:
handle- -ConnectionHandleassociated with the remote host.timeout- - new timeout value in ms
-