Class IpmiConnector
java.lang.Object
org.metricshub.ipmi.core.api.sync.IpmiConnector
Synchronous API for connecting to BMC via IPMI.
Creating connection consists of the following steps:
- Create
Connection
and get associated with itConnectionHandle
viacreateConnection(InetAddress)
- 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[])
Send message register via
sendMessage(ConnectionHandle, PayloadCoder)
To close session call
closeSession(ConnectionHandle)
When done with work, clean up via tearDown()
-
Constructor Summary
ConstructorsConstructorDescriptionIpmiConnector
(int port) StartsIpmiConnector
and initiates theConnectionManager
at the given port.IpmiConnector
(int port, long pingPeriod) StartsIpmiConnector
and initiates theConnectionManager
at the given port.IpmiConnector
(int port, InetAddress address) StartsIpmiConnector
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) Creates connection to the remote host on default IPMI port.createConnection
(InetAddress address, int port) Creates connection to the remote host on specified port.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.createConnection
(InetAddress address, 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.int
Returns configured number of retries.openSession
(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) Establishes the session with the remote host.void
RegistersInboundMessageListener
that will react on any request sent from remote system to the application.retryMessage
(ConnectionHandle connectionHandle, byte tag, PayloadType messagePayloadType) Re-sends message with given tag having givenPayloadType
, using passedConnectionHandle
.sendMessage
(ConnectionHandle connectionHandle, PayloadCoder request) Sends the IPMI message to the remote host.void
sendOneWayMessage
(ConnectionHandle connectionHandle, PayloadCoder request) Sends the IPMI message to the remote host and doesn't wait for any response.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.
-
Constructor Details
-
IpmiConnector
StartsIpmiConnector
and initiates theConnectionManager
at the given port. Wildcard IP address will be used.- Parameters:
port
- - the port that will be used byIpmiAsyncConnector
to communicate with the remote hosts.- Throws:
FileNotFoundException
- when properties file was not foundIOException
- when properties file was not found
-
IpmiConnector
StartsIpmiConnector
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:
FileNotFoundException
- when properties file was not foundIOException
- when properties file was not found
-
IpmiConnector
StartsIpmiConnector
and initiates theConnectionManager
at the given port. Wildcard IP address will be used.- Parameters:
port
- the port that will be used byIpmiAsyncConnector
to communicate with the remote hosts.pingPeriod
- the period in milliseconds used to send the keep alive messages.
0 If keep-alive messages should be disabled.- Throws:
IOException
- When IpmiAsyncConnector cannot be created.
-
-
Method Details
-
createConnection
Creates connection to the remote host on default IPMI port.- 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
Creates connection to the remote host on specified port.- Parameters:
address
- -InetAddress
of the remote hostport
- - remote UDP port- 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, 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
-
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 hostport
- - remote UDP port- 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.- Returns:
- object representing newly created
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
-
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 ResponseData sendMessage(ConnectionHandle connectionHandle, PayloadCoder request) 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 sent- Returns:
ResponseData
for the request- 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
-
sendOneWayMessage
public void sendOneWayMessage(ConnectionHandle connectionHandle, PayloadCoder request) throws Exception Sends the IPMI message to the remote host and doesn't wait for any response.- Parameters:
connectionHandle
- -ConnectionHandle
associated with the remote host.request
- -PayloadCoder
containing the request to be sent- 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
-
retryMessage
public ResponseData retryMessage(ConnectionHandle connectionHandle, byte tag, PayloadType messagePayloadType) throws Exception Re-sends message with given tag having givenPayloadType
, using passedConnectionHandle
.- Parameters:
connectionHandle
- -ConnectionHandle
associated with the remote host.tag
- - tag of the message to retrymessagePayloadType
- -PayloadType
of the message that should be retried- Returns:
ResponseData
for the re-sent request or null if message could not be resent.- Throws:
Exception
- when sending message to the managed system fails
-
registerIncomingMessageListener
RegistersInboundMessageListener
that will react on any request sent from remote system to the application.- Parameters:
listener
- listener to be registered.
-
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
-
getRetries
public int getRetries()Returns configured number of retries.- Returns:
- number of retries when message could not be sent
-