Class ConnectionManager

java.lang.Object
org.metricshub.ipmi.core.connection.ConnectionManager

public class ConnectionManager extends Object
Manages multiple Connections
  • Field Details

    • DEFAULT_PING_PERIOD

      public static final long DEFAULT_PING_PERIOD
      Period of the keep-alive messages of the connections created without an explicit one, in milliseconds.
      See Also:
  • Constructor Details

    • ConnectionManager

      public ConnectionManager(int port, long pingPeriod) throws IOException
      Initiates the connection manager. Wildcard IP address will be used.
      Parameters:
      port - the port at which UdpListener will work
      pingPeriod - frequency of the no-op commands that will be sent to keep up the session. 0 to disable ping requests.
      Throws:
      IOException - If UdpMessenger encountered an error
    • ConnectionManager

      public ConnectionManager(int port) throws IOException
      Initiates the connection manager. Wildcard IP address will be used.
      Parameters:
      port - - the port at which UdpListener will work
      Throws:
      IOException - If UdpMessenger encountered an error
    • ConnectionManager

      public ConnectionManager(int port, InetAddress address) throws IOException
      Initiates the connection manager.
      Parameters:
      port - - the port at which UdpListener will work
      address - - the IP interface UdpListener will bind to
      Throws:
      IOException - If UdpMessenger encountered an error
    • ConnectionManager

      public ConnectionManager(Messenger messenger)
      Initiates the connection manager.
      Parameters:
      messenger - - Messenger to be used in communication
  • Method Details

    • setTimeout

      public void setTimeout(int timeout)
      Sets the timeout of the messages of the connections created from now on.
      Parameters:
      timeout - the time in milliseconds after which a message without a reply is reported as timed out
    • getTimeout

      public int getTimeout()
      Returns the timeout of the messages of the connections created from now on.
      Returns:
      the time in milliseconds after which a message without a reply is reported as timed out
    • close

      public void close()
      Closes all open connections and disconnects UdpListener.
    • generateSessionlessTag

      public static int generateSessionlessTag()
      The tag for messages sent outside the session generated by the ConnectionManager. Auto-incremented.
    • freeTag

      public static void freeTag(int tag)
      Frees the sessionless tag for further use
      Parameters:
      tag - - tag to free
    • getConnection

      public Connection getConnection(int index)
      Returns Connection identified by index.
      Parameters:
      index - - index of the connection to return
    • closeConnection

      public void closeConnection(int index)
      Closes the connection with the given index and releases it; the index is not reused. Closing an already closed connection does nothing.
    • createConnection

      public int createConnection(InetAddress address, int port, int connectionPingPeriod, boolean skipCiphers) throws IOException
      Creates and initiates Connection to the remote host.
      Parameters:
      address - - InetAddress of the remote host
      connectionPingPeriod - - frequency of the no-op commands that will be sent to keep up the session
      skipCiphers - - determines if the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases should be skipped
      Returns:
      index of the connection
      Throws:
      IOException - - when the connection cannot be created
    • createConnection

      public int createConnection(InetAddress address, int port, int connectionPingPeriod) throws IOException
      Creates and initiates Connection to the remote host.
      Parameters:
      address - - InetAddress of the remote host
      connectionPingPeriod - - frequency of the no-op commands that will be sent to keep up the session
      Returns:
      index of the connection
      Throws:
      IOException - - when the connection cannot be created
    • createConnection

      public int createConnection(InetAddress address, int port) throws IOException
      Creates and initiates Connection to the remote host with the default ping frequency.
      Parameters:
      address - - InetAddress of the remote host
      Returns:
      index of the connection
      Throws:
      IOException - when the connection cannot be created
    • createConnection

      public int createConnection(InetAddress address, int port, boolean skipCiphers) throws IOException
      Creates and initiates Connection to the remote host with the default ping frequency.
      Parameters:
      address - - InetAddress of the remote host
      skipCiphers - - determines if the getAvailableCipherSuites and getChannelAuthenticationCapabilities phases should be skipped
      Returns:
      index of the connection
      Throws:
      IOException - when the connection cannot be created
    • getAvailableCipherSuites

      public List<CipherSuite> getAvailableCipherSuites(int connection) throws Exception
      Gets from the managed system supported CipherSuites. Should be performed only immediately after createConnection(java.net.InetAddress, int, int, boolean).
      Parameters:
      connection - - index of the connection to get available Cipher Suites from
      Returns:
      list of the CipherSuites supported by the managed system.
      Throws:
      Ipmi20UnsupportedException - when the BMC does not support IPMI 2.0 (RMCP+): Get Channel Authentication Capabilities, sent first in the IPMI v1.5 format, reports no IPMI v2.0 connections
      ConnectionException - when connection is in the state that does not allow to perform this operation.
      Exception - when sending message to the managed system fails
    • getChannelAuthenticationCapabilities

      public GetChannelAuthenticationCapabilitiesResponseData getChannelAuthenticationCapabilities(int connection, CipherSuite cipherSuite, PrivilegeLevel requestedPrivilegeLevel) throws Exception
      Declares the cipher suite and the privilege of the session, and returns the authentication capabilities of the managed system that getAvailableCipherSuites(int), which must be performed first, read (requested at the User level). Sends nothing.
      Parameters:
      connection - - index of the connection to get Channel Authentication Capabilities from
      cipherSuite - - CipherSuite requested for the session
      requestedPrivilegeLevel - - PrivilegeLevel requested for the session
      Returns:
      GetChannelAuthenticationCapabilitiesResponseData
      Throws:
      ConnectionException - when connection is in the state that does not allow to perform this operation.
      Exception - when the state machine fails
    • startSession

      public int startSession(int connection, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, byte[] password, byte[] bmcKey) throws Exception
      Initiates the session with the managed system. Must be performed after getChannelAuthenticationCapabilities(int, CipherSuite, PrivilegeLevel)
      Parameters:
      connection - - index of the connection that starts the session
      cipherSuite - - CipherSuite that will be used during the session
      privilegeLevel - - requested PrivilegeLevel - most of the time it will be PrivilegeLevel.User
      username - - the username
      password - - the 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
    • registerListener

      public void registerListener(int connection, ConnectionListener listener)
      Registers the listener so it will receive notifications from connection
      Parameters:
      connection - - index of the Connection to listen to
      listener - - ConnectionListener to processResponse