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
Connectionand get associated with itConnectionHandleviacreateConnection(InetAddress) - 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[])
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) StartsIpmiConnectorand initiates theConnectionManagerat the given port.IpmiConnector(int port, long pingPeriod) StartsIpmiConnectorand initiates theConnectionManagerat the given port.IpmiConnector(int port, InetAddress address) StartsIpmiConnectorand 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) 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 setCipherSuiteandPrivilegeLevel, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.createConnection(InetAddress address, 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.intReturns configured number of retries.openSession(ConnectionHandle connectionHandle, String username, String password, byte[] bmcKey) Establishes the session with the remote host.voidRegistersInboundMessageListenerthat 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.voidsendOneWayMessage(ConnectionHandle connectionHandle, PayloadCoder request) Sends the IPMI message to the remote host and doesn't wait for any response.voidsetTimeout(ConnectionHandle handle, int timeout) Changes the timeout value for connection with the given handle.voidtearDown()Finalizes the connector and closes all connections.
-
Constructor Details
-
IpmiConnector
StartsIpmiConnectorand initiates theConnectionManagerat the given port. Wildcard IP address will be used.- Parameters:
port- - the port that will be used byIpmiAsyncConnectorto communicate with the remote hosts.- Throws:
FileNotFoundException- when properties file was not foundIOException- when properties file was not found
-
IpmiConnector
StartsIpmiConnectorand 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:
FileNotFoundException- when properties file was not foundIOException- when properties file was not found
-
IpmiConnector
StartsIpmiConnectorand initiates theConnectionManagerat the given port. Wildcard IP address will be used.- Parameters:
port- the port that will be used byIpmiAsyncConnectorto 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- -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
Creates connection to the remote host on specified port.- Parameters:
address- -InetAddressof 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 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
-
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 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 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.- 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- -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 ResponseData sendMessage(ConnectionHandle connectionHandle, PayloadCoder request) throws Exception Sends the IPMI message to the remote host.- Parameters:
connectionHandle- -ConnectionHandleassociated with the remote host.request- -PayloadCodercontaining the request to be sent- Returns:
ResponseDatafor 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- -ConnectionHandleassociated with the remote host.request- -PayloadCodercontaining 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- -ConnectionHandleassociated with the remote host.tag- - tag of the message to retrymessagePayloadType- -PayloadTypeof the message that should be retried- Returns:
ResponseDatafor the re-sent request or null if message could not be resent.- Throws:
Exception- when sending message to the managed system fails
-
registerIncomingMessageListener
RegistersInboundMessageListenerthat 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- -ConnectionHandleassociated 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
-