Package org.metricshub.ipmi.core.api.sol
Class SerialOverLan
java.lang.Object
org.metricshub.ipmi.core.api.sol.SerialOverLan
- All Implemented Interfaces:
Closeable,AutoCloseable
A Serial over LAN (SOL) console in a session of the protocol core: activates the SOL payload, reads and writes the
serial port of the server, and invokes the serial port operations. Applications that use
IpmiClient open a console with sol().open() instead.-
Constructor Summary
ConstructorsConstructorDescriptionSerialOverLan(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, byte[] bmcKey, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and port, and opens a newSessionfor SOL communication, with the BMC key of a BMC configured for two-key logins.SerialOverLan(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and port, and opens a newSessionfor SOL communication.SerialOverLan(IpmiConnector connector, String remoteHost, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and default IPMI port, and opens a newSessionfor SOL communication.SerialOverLan(IpmiConnector connector, Session session) Tries to open SOL communication on given existing session.SerialOverLan(IpmiConnector connector, Session session, PrivilegeLevel level, PrivilegeLevel ceiling) Tries to open SOL communication on given existing session, likeSerialOverLan(IpmiConnector, Session), for a session opened withPrivilegeLevel.MaximumAvailablewhose level its owner keeps: the console raises it from the given level, when the BMC refuses to activate the payload at that level, as far as the given ceiling only. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of characters received from the BMC that a read returns without waiting.voidclose()Deactivates the SOL payload, closes the sessions the console opened, and tears down the connector when the console owns it: these are released even when the deactivation fails.Returns the connection the console exchanges its packets on: the one of the session it was given, or the one of the session it opened on the port of the payload when the BMC serves SOL on another port.Returns the privilege the console raised the session of the payload to, when that session was opened withPrivilegeLevel.MaximumAvailableand the BMC refused to activate the payload at its level: the owner of the session (seegetConnectionHandle()) runs it at that level from then on.Returns the session the console exchanges its packets in: the session it was given, or the one it opened on the port of the payload when the BMC serves SOL on another port.booleaninvokeOperations(SolOperation... operations) Invokes given SOL-specific operations on remote serial port.byte[]Read all available bytes from the port.byte[]readBytes(int byteCount) Reads at max given number of bytes from the port.byte[]readBytes(int byteCount, int timeout) Reads at max given number of bytes from the port.int[]Reads all available bytes from the port as integer (in range from 0 to 255) values array.int[]readIntArray(int byteCount) Reads at max given number of integer values (in range from 0 to 255) from the port.int[]readIntArray(int byteCount, int timeout) Reads at max given number of integer values (in range from 0 to 255) from the port.readString(int byteCount) readString(int byteCount, int timeout) readString(Charset charset) readString(Charset charset, int byteCount) readString(Charset charset, int byteCount, int timeout) voidregisterEventListener(SolEventListener listener) Registers newSolEventListenerthat will be informed about SOL events fired by remote system.voidunregisterEventListener(SolEventListener listener) Unregister givenSolEventListener, preventing it from receiving SOL events from remote server.booleanwriteByte(byte singleByte) Writes single byte to the port.booleanwriteBytes(byte[] buffer) Writes bytes array to the port, in packets of the size the BMC accepts.booleanwriteInt(int singleInt) Writes single integer (in range from 0 to 255) to the port.booleanwriteIntArray(int[] buffer) Writes integers (in range from 0 to 255) array to the port.booleanwriteString(String string) booleanwriteString(String string, Charset charset)
-
Constructor Details
-
SerialOverLan
public SerialOverLan(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SOLException, SessionException Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and port, and opens a newSessionfor SOL communication. The console owns the connector: closing the console, or failing to open it, tears the connector down.- Parameters:
connector-IpmiConnectorthat will be used for communicationremoteHost- the host name or IP address of the BMCremotePort- UDP port number of the remote serveruser- IPMI user namepassword- IPMI passwordcipherSuiteSelectionHandler-CipherSuiteSelectionHandlerthat will allow to selectCipherSuiteamong available ones.- Throws:
SOLException- when the SOL payload cannot be activatedSessionException- when the session cannot be opened, or the account is not allowed the Administrator privilege
-
SerialOverLan
public SerialOverLan(IpmiConnector connector, String remoteHost, int remotePort, String user, String password, byte[] bmcKey, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SOLException, SessionException Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and port, and opens a newSessionfor SOL communication, with the BMC key of a BMC configured for two-key logins. The console owns the connector: closing the console, or failing to open it, tears the connector down.- Parameters:
connector-IpmiConnectorthat will be used for communicationremoteHost- the host name or IP address of the BMCremotePort- UDP port number of the remote serveruser- IPMI user namepassword- IPMI password, sent in UTF-8bmcKey- the BMC key (Kg) as raw bytes, at most 20, or null for a one-key logincipherSuiteSelectionHandler-CipherSuiteSelectionHandlerthat will allow to selectCipherSuiteamong available ones.- Throws:
SOLException- when the SOL payload cannot be activatedSessionException- when the session cannot be opened, or the account is not allowed the Administrator privilege
-
SerialOverLan
public SerialOverLan(IpmiConnector connector, String remoteHost, String user, String password, CipherSuiteSelectionHandler cipherSuiteSelectionHandler) throws SOLException, SessionException Creates connection with IPMI using givenIpmiConnector, connected to remote machine on given address and default IPMI port, and opens a newSessionfor SOL communication. The console owns the connector: closing the console, or failing to open it, tears the connector down.- Parameters:
connector-IpmiConnectorthat will be used for communicationremoteHost- the host name or IP address of the BMCuser- IPMI user namepassword- IPMI passwordcipherSuiteSelectionHandler-CipherSuiteSelectionHandlerthat will allow to selectCipherSuiteamong available ones.- Throws:
SOLException- when the SOL payload cannot be activatedSessionException- when the session cannot be opened, or the account is not allowed the Administrator privilege
-
SerialOverLan
public SerialOverLan(IpmiConnector connector, Session session) throws SOLException, SessionException Tries to open SOL communication on given existing session. When it appears that separate session must be opened to handle SOL messages (for example SOL payload must be activated on separate port), the new connection and session are automatically established. Closing the console leaves the given session and the connector open, and closes the session it opened, if any.- Parameters:
connector-IpmiConnectorthat will be used for communicationsession- Existing session that should be reused (if possible) for SOL communication.- Throws:
SOLException- when the SOL payload cannot be activatedSessionException- when the session on the SOL payload port cannot be opened
-
SerialOverLan
public SerialOverLan(IpmiConnector connector, Session session, PrivilegeLevel level, PrivilegeLevel ceiling) throws SOLException, SessionException Tries to open SOL communication on given existing session, likeSerialOverLan(IpmiConnector, Session), for a session opened withPrivilegeLevel.MaximumAvailablewhose level its owner keeps: the console raises it from the given level, when the BMC refuses to activate the payload at that level, as far as the given ceiling only. The levels do not matter for a session opened at a fixed level, and do not apply to the session the console opens on the port of the payload, which it raises from User as far as the account allows.- Parameters:
connector-IpmiConnectorthat will be used for communicationsession- Existing session that should be reused (if possible) for SOL communication.level- the level the session runs at: User, Operator or Administratorceiling- the highest level the console may raise the session to; the given level to never raise it- Throws:
SOLException- when the SOL payload cannot be activatedSessionException- when the session on the SOL payload port cannot be opened
-
-
Method Details
-
getRaisedPrivilegeLevel
Returns the privilege the console raised the session of the payload to, when that session was opened withPrivilegeLevel.MaximumAvailableand the BMC refused to activate the payload at its level: the owner of the session (seegetConnectionHandle()) runs it at that level from then on.- Returns:
- Operator or Administrator, or null when the console did not raise the session
-
getConnectionHandle
Returns the connection the console exchanges its packets on: the one of the session it was given, or the one of the session it opened on the port of the payload when the BMC serves SOL on another port.- Returns:
- the connection handle of the payload session
-
writeByte
public boolean writeByte(byte singleByte) Writes single byte to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.- Parameters:
singleByte- a byte to write- Returns:
- true if byte was successfully sent and acknowledged by remote server, false otherwise.
-
writeBytes
public boolean writeBytes(byte[] buffer) Writes bytes array to the port, in packets of the size the BMC accepts. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server. When it fails, the server may have received the first bytes already.- Parameters:
buffer- an array of bytes to write- Returns:
- true if all bytes were successfully sent and acknowledged by remote server, false otherwise.
-
writeInt
public boolean writeInt(int singleInt) Writes single integer (in range from 0 to 255) to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.- Parameters:
singleInt- an integer value to write (must be in range from 0 to 255)- Returns:
- true if integer was successfully sent and acknowledged by remote server, false otherwise.
-
writeIntArray
public boolean writeIntArray(int[] buffer) Writes integers (in range from 0 to 255) array to the port. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.- Parameters:
buffer- an array of integer values to write (each must be in range from 0 to 255)- Returns:
- true if all integers were successfully sent and acknowledged by remote server, false otherwise.
-
writeString
WritesStringto port, using platform's defaultCharsetwhen convertingStringto byte array. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.- Parameters:
string- a string to write to the port.- Returns:
- true if whole string was successfully sent and acknowledged by remote server, false otherwise.
-
writeString
WritesStringto port, using givenCharsetwhen convertingStringto byte array. This operation blocks until all data can be sent to remote server and is either accepted or rejected by the server.- Parameters:
string- a string to write to portcharset-Charsetthat the string is encoded in- Returns:
- true if whole string was successfully sent and acknowledged by remote server, false otherwise.
-
available
public int available()Returns the number of characters received from the BMC that a read returns without waiting.- Returns:
- the number of bytes buffered, 0 when none
-
getSession
Returns the session the console exchanges its packets in: the session it was given, or the one it opened on the port of the payload when the BMC serves SOL on another port.- Returns:
- the session of the payload
-
readBytes
public byte[] readBytes()Read all available bytes from the port. Returns immediately, without waiting for data to be available.- Returns:
- all bytes that could be read or empty array if no bytes were available.
-
readBytes
public byte[] readBytes(int byteCount) Reads at max given number of bytes from the port. Returns immediately, without waiting for data to be available.- Parameters:
byteCount- maximum number of bytes that should be read- Returns:
- byte array containing bytes that could be read, but no more than given byteCount. Returns empty array if no bytes were available.
-
readBytes
public byte[] readBytes(int byteCount, int timeout) Reads at max given number of bytes from the port. This operation blocks until given number of bytes is available to be read, the buffer of 64 KiB is full, or the given timeout is hit.- Parameters:
byteCount- maximum number of bytes that should be read.timeout- maximum time in milliseconds that we want to wait for all available bytes- Returns:
- byte array containing bytes that could be read, but no more than byteCount. When the timeout is hit, returns just bytes that were available or empty array if no bytes were available.
-
readIntArray
public int[] readIntArray()Reads all available bytes from the port as integer (in range from 0 to 255) values array. Returns immediately, without waiting for data to be available.- Returns:
- all bytes that could be read as int array (each value in range from 0 to 255) or empty array if no data was available.
-
readIntArray
public int[] readIntArray(int byteCount) Reads at max given number of integer values (in range from 0 to 255) from the port. Returns immediately, without waiting for data to be available.- Parameters:
byteCount- maximum number of bytes that should be read- Returns:
- integer array containing integer values that could be read, but no more than given byteCount (each value in range from 0 to 255). Returns empty array if no data was available.
-
readIntArray
public int[] readIntArray(int byteCount, int timeout) Reads at max given number of integer values (in range from 0 to 255) from the port. This operation blocks until given number of bytes is available to be read, the buffer of 64 KiB is full, or the given timeout is hit.- Parameters:
byteCount- maximum number of bytes that should be read.timeout- maximum time in milliseconds that we want to wait for all available data- Returns:
- integer array containing integer values that could be read, but no more than byteCount (each value in range from 0 to 255). When the timeout is hit, returns just data that was available or empty array if no data was available.
-
readString
Read all available bytes from the port and converts them toStringusing platform's defaultCharset. Returns immediately, without waiting for data to be available.- Returns:
- all bytes that could be read as
String.
-
readString
Reads at max given number of bytes from the port, converting them toStringusing platform's defaultCharset. Returns immediately, without waiting for data to be available.- Parameters:
byteCount- maximum number of bytes that should be read- Returns:
- all bytes that could be read as
String, but no more than given byteCount.
-
readString
Reads at max given number of bytes from the port, converting them toStringusing platform's defaultCharset. This operation blocks until given number of bytes is available to be read, the buffer of 64 KiB is full, or the given timeout is hit.- Parameters:
byteCount- maximum number of bytes that should be read.timeout- maximum time in milliseconds that we want to wait for all available bytes- Returns:
- all bytes that could be read as
String, but no more than given byteCount. When the timeout is hit, returns just bytes that were available.
-
readString
-
readString
-
readString
Reads at max given number of bytes from the port, converting them toStringusing givenCharset. This operation blocks until given number of bytes is available to be read, the buffer of 64 KiB is full, or the given timeout is hit.- Parameters:
charset-Charsetthat will be used when converting bytes toStringbyteCount- maximum number of bytes that should be read.timeout- maximum time in milliseconds that we want to wait for all available bytes- Returns:
- all bytes that could be read as
String, but no more than given byteCount. When the timeout is hit, returns just bytes that were available.
-
invokeOperations
Invokes given SOL-specific operations on remote serial port.SolOperation.Break,SolOperation.FlushInboundandSolOperation.FlushOutboundact once;SolOperation.CTS,SolOperation.DCD_DSRandSolOperation.RingWORare line states, which the console holds in every packet it sends until the next call: call this method without them to release them.- Parameters:
operations- a bunch ofSolOperations that should be invoked- Returns:
- true if the packet was sent (its acknowledgement is not awaited: many BMCs never acknowledge a packet without characters), false otherwise.
-
registerEventListener
Registers newSolEventListenerthat will be informed about SOL events fired by remote system.- Parameters:
listener- listener to be registered
-
unregisterEventListener
Unregister givenSolEventListener, preventing it from receiving SOL events from remote server.- Parameters:
listener- listener to be unregistered
-
close
Deactivates the SOL payload, closes the sessions the console opened, and tears down the connector when the console owns it: these are released even when the deactivation fails.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- when the BMC does not confirm the deactivation
-