Class IpmiAsyncConnector

java.lang.Object
org.metricshub.ipmi.core.api.async.IpmiAsyncConnector
All Implemented Interfaces:
ConnectionListener

public class IpmiAsyncConnector extends Object implements ConnectionListener

Asynchronous API for connecting to BMC via IPMI.

Creating connection consists of the following steps:

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 Details

    • FAILED_TO_RECEIVE_ANSWER_CAUSE_MESSAGE

      public static final String FAILED_TO_RECEIVE_ANSWER_CAUSE_MESSAGE
      See Also:
  • Constructor Details

    • IpmiAsyncConnector

      public IpmiAsyncConnector(int port) throws IOException
      Starts IpmiAsyncConnector and initiates the ConnectionManager at the given port. The wildcard IP address will be used.
      Parameters:
      port - - the port that will be used by IpmiAsyncConnector to communicate with the remote hosts.
      Throws:
      IOException - when properties file was not found
    • IpmiAsyncConnector

      public IpmiAsyncConnector(int port, InetAddress address) throws IOException
      Starts IpmiAsyncConnector and initiates the ConnectionManager at the given port and IP interface.
      Parameters:
      port - - the port that will be used by IpmiAsyncConnector to communicate with the remote hosts.
      address - - the IP address that will be used by IpmiAsyncConnector to communicate with the remote hosts.
      Throws:
      IOException - when properties file was not found
    • IpmiAsyncConnector

      public IpmiAsyncConnector(int port, long pingPeriod) throws IOException
      Starts IpmiAsyncConnector and initiates the ConnectionManager at the given port and ping period.
      Parameters:
      port - the port that will be used by IpmiAsyncConnector 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

      public ConnectionHandle createConnection(InetAddress address, int port) throws IOException
      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 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
      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.
      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 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 sent
      isOneWay - - 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 retry
      messagePayloadType - - 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

      public void registerListener(IpmiResponseListener listener)
      Registers the listener so it will be notified of incoming messages.
      Parameters:
      listener - IpmiResponseListener to processResponse
    • unregisterListener

      public void unregisterListener(IpmiResponseListener listener)
      Unregisters the listener so it will no longer receive notifications of received answers.
      Parameters:
      listener - - the IpmiResponseListener to unregister
    • registerIncomingPayloadListener

      public void registerIncomingPayloadListener(InboundMessageListener listener)
      Registers the listener for incoming messages.
      Parameters:
      listener - the InboundMessageListener to register.
    • unregisterIncomingPayloadListener

      public void unregisterIncomingPayloadListener(InboundMessageListener listener)
      Unregisters the listener so it will no longer receive notifications of received messages.
      Parameters:
      listener - the InboundMessageListener to unregister.
    • processResponse

      public void processResponse(ResponseData responseData, int handle, int tag, Exception exception)
      Description copied from interface: ConnectionListener
      Notifies the ConnectionListeners 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 interface ConnectionListener
      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 message
      tag - - tag of the request-response pair
      exception - - null if everything went correctly or timeout occured, contains exception that occured during decoding if it failed.
    • processRequest

      public void processRequest(IpmiPayload payload)
      Specified by:
      processRequest in interface ConnectionListener
    • 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