summaryrefslogtreecommitdiffstats
path: root/sessions_manager.hpp
blob: c23e3abaac6f2b087ddddd912ce0eaa669c626c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once

#include <map>
#include <memory>
#include <mutex>

#include "session.hpp"

namespace session
{

enum class RetrieveOption
{
    BMC_SESSION_ID,
    RC_SESSION_ID,
};

constexpr size_t SESSION_ZERO = 0;
constexpr size_t MAX_SESSIONLESS_COUNT = 1;
constexpr size_t MAX_SESSION_COUNT = 5;

/*
 * @class Manager
 *
 * Manager class acts a manager for the IPMI sessions and provides interfaces
 * to start a session, stop a session and get reference to the session objects.
 *
 */

class Manager
{
    public:

        // BMC Session ID is the key for the map
        using SessionMap = std::map<SessionID, std::shared_ptr<Session>>;

        Manager();
        ~Manager() = default;
        Manager(const Manager&) = delete;
        Manager& operator=(const Manager&) = delete;
        Manager(Manager&&) = default;
        Manager& operator=(Manager&&) = default;

        /*
         * @brief Start an IPMI session
         *
         * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned
         *            in the Open SessionRequest Command
         * @param[in] priv - Privilege level requested
         * @param[in] authAlgo - Authentication Algorithm
         * @param[in] intAlgo - Integrity Algorithm
         *
         * @return session handle on success and nullptr on failure
         *
         */
        std::weak_ptr<Session> startSession(SessionID remoteConsoleSessID,
                Privilege priv, cipher::rakp_auth::Algorithms authAlgo,
                cipher::integrity::Algorithms intAlgo);

        /*
         * @brief Stop IPMI Session
         *
         * @param[in] bmcSessionID - BMC Session ID
         *
         * @return true on success and failure if session ID is invalid
         *
         */
        bool stopSession(SessionID bmcSessionID);

        /*
         * @brief Get Session Handle
         *
         * @param[in] sessionID - Session ID
         * @param[in] option - Select between BMC Session ID and Remote Console
         *            Session ID, Default option is BMC Session ID
         *
         * @return session handle on success and nullptr on failure
         *
         */
        std::weak_ptr<Session> getSession(
               SessionID sessionID,
               RetrieveOption option = RetrieveOption::BMC_SESSION_ID);

    private:

        /*
         * @brief Session Manager keeps the session objects as a sorted
         *        associative container with Session ID as the unique key
         */
        SessionMap sessionsMap;

        /*
         * @brief Clean Session Stale Entries
         *
         *  Removes the inactive sessions entries from the Session Map
         */
        void cleanStaleEntries();
};

} // namespace session
OpenPOWER on IntegriCloud