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
Connection
and get associated with itConnectionHandle
viacreateConnection(InetAddress, int)
- Get
CipherSuite
s that are available for the connection viagetAvailableCipherSuites(ConnectionHandle)
- Pick
CipherSuite
andPrivilegeLevel
that will be used during session and getGetChannelAuthenticationCapabilitiesResponseData
to 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) StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port.IpmiAsyncConnector
(int port, long pingPeriod) StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port and ping period.IpmiAsyncConnector
(int port, InetAddress address) StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port and IP interface. -
Method Summary
Modifier and TypeMethodDescriptionvoid
closeConnection
(ConnectionHandle handle) Closes the connection with the given handlevoid
closeSession
(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 setCipherSuite
andPrivilegeLevel
, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.getAvailableCipherSuites
(ConnectionHandle connectionHandle) GetsCipherSuite
s 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.void
processRequest
(IpmiPayload payload) void
processResponse
(ResponseData responseData, int handle, int tag, Exception exception) Notifies theConnectionListener
s of the one of the following events: response to the request tagged with id arrived request tagged with id timed outvoid
Registers the listener for incoming messages.void
registerListener
(IpmiResponseListener listener) Registers the listener so it will be notified of incoming messages.int
retry
(ConnectionHandle connectionHandle, int tag, PayloadType messagePayloadType) Attempts to retry sending a message.int
sendMessage
(ConnectionHandle connectionHandle, PayloadCoder request, boolean isOneWay) Sends the IPMI message to the remote host.void
setTimeout
(ConnectionHandle handle, int timeout) Changes the timeout value for connection with the given handle.void
tearDown()
Finalizes the connector and closes all connections.void
Unregisters the listener so it will no longer receive notifications of received messages.void
unregisterListener
(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
StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port. The wildcard IP address will be used.- Parameters:
port
- - the port that will be used byIpmiAsyncConnector
to communicate with the remote hosts.- Throws:
IOException
- when properties file was not found
-
IpmiAsyncConnector
StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port and IP interface.- Parameters:
port
- - the port that will be used byIpmiAsyncConnector
to communicate with the remote hosts.address
- - the IP address that will be used byIpmiAsyncConnector
to communicate with the remote hosts.- Throws:
IOException
- when properties file was not found
-
IpmiAsyncConnector
StartsIpmiAsyncConnector
and initiates theConnectionManager
at the given port and ping period.- Parameters:
port
- the port that will be used byIpmiAsyncConnector
to 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
- -InetAddress
of 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 setCipherSuite
andPrivilegeLevel
, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.- Parameters:
address
- -InetAddress
of 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 GetsCipherSuite
s available for the connection with the remote host.- Parameters:
connectionHandle
-ConnectionHandle
to the connection created before- Returns:
- list of the
CipherSuite
s 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
- -ConnectionHandle
associated with the hostcipherSuite
- -CipherSuite
that will be used during the connectionrequestedPrivilegeLevel
- -PrivilegeLevel
that 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
- -ConnectionHandle
associated 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
- -ConnectionHandle
associated 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
- -ConnectionHandle
associated with the remote host.request
- -PayloadCoder
containing 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
- -ConnectionHandle
associated with the remote host.tag
- - tag of the message to retrymessagePayloadType
- -PayloadType
of 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
-IpmiResponseListener
to processResponse
-
unregisterListener
Unregisters the listener so it will no longer receive notifications of received answers.- Parameters:
listener
- - theIpmiResponseListener
to unregister
-
registerIncomingPayloadListener
Registers the listener for incoming messages.- Parameters:
listener
- theInboundMessageListener
to register.
-
unregisterIncomingPayloadListener
Unregisters the listener so it will no longer receive notifications of received messages.- Parameters:
listener
- theInboundMessageListener
to unregister.
-
processResponse
Description copied from interface:ConnectionListener
Notifies theConnectionListener
s of the one of the following events:- response to the request tagged with id arrived
- request tagged with id timed out
- Specified by:
processResponse
in interfaceConnectionListener
- Parameters:
responseData
- -ResponseData
specific 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:
processRequest
in 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
- -ConnectionHandle
associated with the remote host.timeout
- - new timeout value in ms
-