summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-02-15 14:51:42 +0530
committerPatrick Williams <patrick@stwcx.xyz>2017-04-24 11:05:34 +0000
commit5a454a2fbb09677cc5d147a07c56ee9951f02942 (patch)
tree2e102481e2059260380bc8b138800f0b2d82c450
parent86d17b450aa6cbca03f9ec34d25a051fa808e6aa (diff)
downloadphosphor-net-ipmid-5a454a2fbb09677cc5d147a07c56ee9951f02942.tar.gz
phosphor-net-ipmid-5a454a2fbb09677cc5d147a07c56ee9951f02942.zip
Defintion of SOL Manager
The SOL Manager class is responsible for managing SOL instances and configuration parameters. It provides interfaces to start and stop SOL payload instances and get handle to context object. It also provides API to write to the host console socket. Change-Id: Iea51832398d81c8ddf6fadcbb8b7e6735a3b4ebc Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r--Makefile.am3
-rw-r--r--sol/sol_manager.hpp215
2 files changed, 217 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index f9fb32d..4e96444 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,8 @@ netipmid_SOURCES = \
crypt_algo.cpp \
sol/console_buffer.hpp \
sd_event_loop.hpp \
- sol/sol_context.hpp
+ sol/sol_context.hpp \
+ sol/sol_manager.hpp
netipmid_CPPFLAGS = -DNET_IPMID_LIB_PATH=\"/usr/lib/net-ipmid/\"
netipmid_LDFLAGS = $(SYSTEMD_LIBS) $(CRYPTO_LIBS) $(libmapper_LIBS) $(LIBADD_DLOPEN) -export-dynamic
diff --git a/sol/sol_manager.hpp b/sol/sol_manager.hpp
new file mode 100644
index 0000000..a7e4a1c
--- /dev/null
+++ b/sol/sol_manager.hpp
@@ -0,0 +1,215 @@
+#pragma once
+
+#include <map>
+#include <memory>
+#include "console_buffer.hpp"
+#include "session.hpp"
+#include "sol_context.hpp"
+
+namespace sol
+{
+
+constexpr size_t MAX_PAYLOAD_INSTANCES = 16;
+constexpr size_t MAX_PAYLOAD_SIZE = 255;
+constexpr uint8_t MAJOR_VERSION = 0x01;
+constexpr uint8_t MINOR_VERSION = 0x00;
+
+constexpr char CONSOLE_SOCKET_PATH[] = "\0obmc-console";
+constexpr size_t CONSOLE_SOCKET_PATH_LEN = sizeof(CONSOLE_SOCKET_PATH) - 1;
+
+using Instance = uint8_t;
+
+/** @struct CustomFD
+ *
+ * RAII wrapper for file descriptor.
+ */
+struct CustomFD
+{
+ CustomFD(const CustomFD&) = delete;
+ CustomFD& operator=(const CustomFD&) = delete;
+ CustomFD(CustomFD&&) = delete;
+ CustomFD& operator=(CustomFD&&) = delete;
+
+ CustomFD(int fd) :
+ fd(fd) {}
+
+ ~CustomFD()
+ {
+ if(fd >=0)
+ {
+ close(fd);
+ }
+ }
+
+ int operator()() const
+ {
+ return fd;
+ }
+
+ private:
+ int fd = -1;
+};
+
+
+/** @class Manager
+ *
+ * Manager class acts a manager for the SOL payload instances and provides
+ * interfaces to start a payload instance, stop a payload instance and get
+ * reference to the context object.
+ */
+class Manager
+{
+ public:
+
+ /** @brief SOL Payload Instance is the key for the map, the value is the
+ * SOL context.
+ */
+ using SOLPayloadMap = std::map<Instance, std::unique_ptr<Context>>;
+
+ Manager() = default;
+ ~Manager() = default;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = default;
+ Manager& operator=(Manager&&) = default;
+
+ /** @brief Host Console Buffer. */
+ ConsoleData dataBuffer;
+
+
+ /** @brief Character Accumulate Interval
+ *
+ * Character Accumulate Interval in 5 ms increments, 1-based. This sets
+ * the typical amount of time that the BMC will wait before
+ * transmitting a partial SOL character data packet. (Where a partial
+ * packet is defined as a packet that has fewer characters to transmit
+ * than the number of characters specified by the character send
+ * threshold. This parameter can be modified by the set SOL
+ * configuration parameters command.
+ */
+ uint8_t accumulateInterval = 20;
+
+ /** @brief Character Send Threshold
+ *
+ * The BMC will automatically send an SOL character data packet
+ * containing this number of characters as soon as this number of
+ * characters (or greater) has been accepted from the baseboard serial
+ * controller into the BMC. This provides a mechanism to tune the
+ * buffer to reduce latency to when the first characters are received
+ * after an idle interval. In the degenerate case, setting this value
+ * to a ‘1’ would cause the BMC to send a packet as soon as the first
+ * character was received. This parameter can be modified by the set
+ * SOL configuration parameters command.
+ */
+ uint8_t sendThreshold = 1;
+
+ /** @brief Retry Count
+ *
+ * 1-based. 0 = no retries after packet is transmitted. Packet will be
+ * dropped if no ACK/NACK received by time retries expire. The maximum
+ * value for retry count is 7. This parameter can be modified by the
+ * set SOL configuration parameters command.
+ */
+ uint8_t retryCount = 7;
+
+ /** @brief Retry Interval
+ *
+ * Retry Interval, 1-based. Retry Interval in 10 ms increments. Sets
+ * the time that the BMC will wait before the first retry and the time
+ * between retries when sending SOL packets to the remote console. 00h
+ * indicates retries sent back-to-back. This parameter can be modified
+ * by the set SOL configuration parameters command.
+ */
+ uint8_t retryThreshold = 10;
+
+ /** @brief Start a SOL payload instance.
+ *
+ * Starting a payload instance involves creating the context object,
+ * add the accumulate interval timer and retry interval timer to the
+ * event loop.
+ *
+ * @param[in] payloadInstance - SOL payload instance.
+ * @param[in] sessionID - BMC session ID.
+ */
+ void startPayloadInstance(uint8_t payloadInstance,
+ session::SessionID sessionID);
+
+ /** @brief Stop SOL payload instance.
+ *
+ * Stopping a payload instance involves stopping and removing the
+ * accumulate interval timer and retry interval timer from the event
+ * loop, delete the context object.
+ *
+ * @param[in] payloadInstance - SOL payload instance
+ */
+ void stopPayloadInstance(uint8_t payloadInstance);
+
+ /** @brief Get SOL Context by Payload Instance.
+ *
+ * @param[in] payloadInstance - SOL payload instance.
+ *
+ * @return reference to the SOL payload context.
+ */
+ Context& getContext(uint8_t payloadInstance)
+ {
+ auto iter = payloadMap.find(payloadInstance);
+
+ if (iter != payloadMap.end())
+ {
+ return *(iter->second);
+ }
+
+ std::string msg = "Invalid SOL payload instance " + payloadInstance;
+ throw std::runtime_error(msg.c_str());
+ }
+
+ /** @brief Get SOL Context by Session ID.
+ *
+ * @param[in] sessionID - IPMI Session ID.
+ *
+ * @return reference to the SOL payload context.
+ */
+ Context& getContext(session::SessionID sessionID)
+ {
+ for (const auto& kv : payloadMap)
+ {
+ if (kv.second->sessionID == sessionID)
+ {
+ return *kv.second;
+ }
+ }
+
+ std::string msg = "Invalid SOL SessionID " + sessionID;
+ throw std::runtime_error(msg.c_str());
+ }
+
+ /** @brief Check if SOL payload is active.
+ *
+ * @param[in] payloadInstance - SOL payload instance.
+ *
+ * @return true if the instance is active and false it is not active.
+ */
+ auto isPayloadActive(uint8_t payloadInstance) const
+ {
+ return (0 != payloadMap.count(payloadInstance));
+ }
+
+ /** @brief Write data to the host console unix socket.
+ *
+ * @param[in] input - Data from the remote console.
+ *
+ * @return 0 on success and errno on failure.
+ */
+ int writeConsoleSocket(const Buffer& input) const;
+
+ private:
+ SOLPayloadMap payloadMap;
+
+ /** @brief File descriptor for the host console. */
+ std::unique_ptr<CustomFD> consoleFD = nullptr;
+
+ /** @brief Initialize the host console file descriptor. */
+ void initHostConsoleFd();
+};
+
+} //namespace sol
OpenPOWER on IntegriCloud