Class ConnectionManager

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

public class ConnectionManager extends Object
Manages multiple Connections
  • 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

    • 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.
    • getConnection

      public Connection getConnection(InetAddress address, int port)
      Returns first Connection associated with the address
      Parameters:
      address - - InetAddress of the remote host to get connection with.
      Returns:
      First Connection to the address or null if none found
    • createConnection

      public int createConnection(InetAddress address, int port, int pingPeriod, boolean skipCiphers) throws IOException
      Creates and initiates Connection to the remote host.
      Parameters:
      address - - InetAddress of the remote host
      pingPeriod - - 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 properties file was not found
    • createConnection

      public int createConnection(InetAddress address, int port, int pingPeriod) throws IOException
      Creates and initiates Connection to the remote host.
      Parameters:
      address - - InetAddress of the remote host
      pingPeriod - - frequency of the no-op commands that will be sent to keep up the session
      Returns:
      index of the connection
      Throws:
      IOException - - when properties file was not found
    • 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 properties file was not found
    • 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 properties file was not found
    • 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:
      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
      Queries the managed system for the details of the authentification process. Must be performed after getAvailableCipherSuites(int)
      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 sending message to the managed system fails
    • startSession

      public int startSession(int connection, CipherSuite cipherSuite, PrivilegeLevel privilegeLevel, String username, String 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