Class IpmiConnector

java.lang.Object
org.metricshub.ipmi.core.api.sync.IpmiConnector

public class IpmiConnector extends Object

Synchronous API for connecting to BMC via IPMI.


Creating connection consists of the following steps:

Send message register via sendMessage(ConnectionHandle, PayloadCoder)


To close session call closeSession(ConnectionHandle)

When done with work, clean up via tearDown()


  • Constructor Details

  • Method Details

    • createConnection

      public ConnectionHandle createConnection(InetAddress address) throws IOException
      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 found
      FileNotFoundException - when properties file was not found
    • createConnection

      public ConnectionHandle createConnection(InetAddress address, int port) throws IOException
      Creates connection to the remote host on specified port.
      Parameters:
      address - - InetAddress of the remote host
      port - - remote UDP port
      Returns:
      handle to the connection to the remote host
      Throws:
      IOException - when properties file was not found
      FileNotFoundException - 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 set CipherSuite and PrivilegeLevel, 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 found
      FileNotFoundException - 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 set CipherSuite and PrivilegeLevel, skipping the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases.
      Parameters:
      address - - InetAddress of the remote host
      port - - remote UDP port
      Returns:
      handle to the connection to the remote host
      Throws:
      IOException - when properties file was not found
      FileNotFoundException - when properties file was not found
    • getAvailableCipherSuites

      public List<CipherSuite> getAvailableCipherSuites(ConnectionHandle connectionHandle) throws Exception
      Gets CipherSuites available for the connection with the remote host.
      Parameters:
      connectionHandle - ConnectionHandle to 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 - - ConnectionHandle associated with the host
      cipherSuite - - CipherSuite that will be used during the connection
      requestedPrivilegeLevel - - 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 username
      password - - password matching the username
      bmcKey - - 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 system
      remotePort - UDP port of the managed system
      user - 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

      public void closeSession(ConnectionHandle connectionHandle) throws Exception
      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 given PayloadType, using passed ConnectionHandle.
      Parameters:
      connectionHandle - - ConnectionHandle associated with the remote host.
      tag - - tag of the message to retry
      messagePayloadType - - 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

      public void registerIncomingMessageListener(InboundMessageListener listener)
      Registers InboundMessageListener that will react on any request sent from remote system to the application.
      Parameters:
      listener - listener to be registered.
    • closeConnection

      public void closeConnection(ConnectionHandle handle)
      Closes the connection with the given handle
    • tearDown

      public void tearDown()
      Finalizes the connector and closes all connections.
    • setTimeout

      public void setTimeout(ConnectionHandle handle, int timeout)
      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