blob: bfac4881a441dd11ec6ebe3a735c6c08a742218a [file] [log] [blame]
Mohsin Kazmied76ee22018-03-02 12:31:37 +01001/*
2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __VOM_BOND_GROUP_BINDING_H__
17#define __VOM_BOND_GROUP_BINDING_H__
18
19#include <set>
20
21#include "vom/bond_interface.hpp"
22#include "vom/bond_member.hpp"
23#include "vom/hw.hpp"
24#include "vom/inspect.hpp"
25#include "vom/interface.hpp"
26#include "vom/object_base.hpp"
27#include "vom/om.hpp"
28#include "vom/singular_db.hpp"
29
30namespace VOM {
31/**
32 * A representation of bond interface binding
33 */
34class bond_group_binding : public object_base
35{
36public:
37 /**
38 * The KEY can be used to uniquely identify the Bond Binding.
39 * (other choices for keys, like the summation of the properties
40 * of the rules, are rather too cumbersome to use
41 */
42 typedef std::string key_t;
43
44 /**
45 * The container type for enslaved itfs
46 */
47 typedef std::set<bond_member> enslaved_itf_t;
48
49 /**
50 * Construct a new object matching the desried state
51 */
52 bond_group_binding(const bond_interface& itf, const enslaved_itf_t& mem);
53
54 /**
55 * Copy Constructor
56 */
57 bond_group_binding(const bond_group_binding& o);
58
59 /**
60 * Destructor
61 */
62 ~bond_group_binding();
63
64 /**
65 * Return the 'singular' of the bond interface binding that matches this
66 * object
67 */
68 std::shared_ptr<bond_group_binding> singular() const;
69
70 /**
71 * convert to string format for debug purposes
72 */
73 std::string to_string() const;
74
75 /**
76 * get the key to this object
77 */
78 const key_t key() const;
79
80 /**
81 * Dump all bond interface bindings into the stream provided
82 */
83 static void dump(std::ostream& os);
84
85private:
86 /**
87 * Class definition for listeners to OM events
88 */
89 class event_handler : public OM::listener, public inspect::command_handler
90 {
91 public:
92 event_handler();
93 virtual ~event_handler() = default;
94
95 /**
96 * Handle a populate event
97 */
98 void handle_populate(const client_db::key_t& key);
99
100 /**
101 * Handle a replay event
102 */
103 void handle_replay();
104
105 /**
106 * Show the object in the Singular DB
107 */
108 void show(std::ostream& os);
109
110 /**
111 * Get the sortable Id of the listener
112 */
113 dependency_t order() const;
114 };
115
116 /**
117 * event_handler to register with OM
118 */
119 static event_handler m_evh;
120
121 /**
122 * Enqueue command to the VPP command Q for the update
123 */
124 void update(const bond_group_binding& obj);
125
126 /**
127 * Find or add bond interface binding to the OM
128 */
129 static std::shared_ptr<bond_group_binding> find_or_add(
130 const bond_group_binding& temp);
131
132 /*
133 * It's the OM class that calls singular()
134 */
135 friend class OM;
136
137 /**
138 * It's the singular_db class that calls replay()
139 */
140 friend class singular_db<key_t, bond_group_binding>;
141
142 /**
143 * Sweep/reap the object if still stale
144 */
145 void sweep(void);
146
147 /**
148 * replay the object to create it in hardware
149 */
150 void replay(void);
151
152 /**
153 * A reference counting pointer to the bond interface.
154 * By holding the reference here, we can guarantee that
155 * this object will outlive the interface
156 */
157 std::shared_ptr<bond_interface> m_itf;
158
159 /**
160 * A list of member interfaces.
161 */
162 const enslaved_itf_t m_mem_itfs;
163
164 /**
165 * HW configuration for the binding. The bool representing the
166 * do/don't bind.
167 */
168 HW::item<bool> m_binding;
169
170 /**
171 * A map of all bond interface bindings keyed against the interface +
172 * "binding".
173 */
174 static singular_db<key_t, bond_group_binding> m_db;
175};
176};
177
178/*
179 * fd.io coding-style-patch-verification: ON
180 *
181 * Local Variables:
182 * eval: (c-set-style "mozilla")
183 * End:
184 */
185
186#endif