blob: 70371fa0f46968d6e7bee932c0445d8c8fd55ec7 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
2 * Copyright (c) 2017 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_BRIDGE_DOMAIN_H__
17#define __VOM_BRIDGE_DOMAIN_H__
18
19#include "vom/dump_cmd.hpp"
20#include "vom/enum_base.hpp"
21#include "vom/hw.hpp"
22#include "vom/inspect.hpp"
23#include "vom/object_base.hpp"
24#include "vom/om.hpp"
25#include "vom/rpc_cmd.hpp"
26#include "vom/singular_db.hpp"
27
28#include <vapi/l2.api.vapi.hpp>
29
30namespace VOM {
31/**
32 * A base class for all object_base in the VPP object_base-Model.
33 * provides the abstract interface.
34 */
35class bridge_domain : public object_base
36{
37public:
38 /**
39 * The value of the defaultbridge domain
40 */
41 const static uint32_t DEFAULT_TABLE = 0;
42
43 /**
44 * Construct a new object matching the desried state
45 */
46 bridge_domain(uint32_t id);
47 /**
48 * Copy Constructor
49 */
50 bridge_domain(const bridge_domain& o);
51 /**
52 * Destructor
53 */
54 ~bridge_domain();
55
56 /**
57 * Return the matchin 'singular' instance of the bridge-domain
58 */
59 std::shared_ptr<bridge_domain> singular() const;
60
61 /**
62 * convert to string format for debug purposes
63 */
64 std::string to_string(void) const;
65
66 /**
67 * Return VPP's handle for this obejct
68 */
69 uint32_t id() const;
70
71 /**
72 * Static function to find the bridge_domain in the model
73 */
74 static std::shared_ptr<bridge_domain> find(uint32_t id);
75
76 /**
77 * Dump all bridge-doamin into the stream provided
78 */
79 static void dump(std::ostream& os);
80
81 /**
82 * A command class that creates an Bridge-Domain
83 */
84 class create_cmd
85 : public rpc_cmd<HW::item<uint32_t>, rc_t, vapi::Bridge_domain_add_del>
86 {
87 public:
88 /**
89 * Constructor
90 */
91 create_cmd(HW::item<uint32_t>& item);
92
93 /**
94 * Issue the command to VPP/HW
95 */
96 rc_t issue(connection& con);
97 /**
98 * convert to string format for debug purposes
99 */
100 std::string to_string() const;
101
102 /**
103 * Comparison operator - only used for UT
104 */
105 bool operator==(const create_cmd& i) const;
106 };
107
108 /**
109 * A cmd class that Delete an Bridge-Domain
110 */
111 class delete_cmd
112 : public rpc_cmd<HW::item<uint32_t>, rc_t, vapi::Bridge_domain_add_del>
113 {
114 public:
115 /**
116 * Constructor
117 */
118 delete_cmd(HW::item<uint32_t>& item);
119
120 /**
121 * Issue the command to VPP/HW
122 */
123 rc_t issue(connection& con);
124 /**
125 * convert to string format for debug purposes
126 */
127 std::string to_string() const;
128
129 /**
130 * Comparison operator - only used for UT
131 */
132 bool operator==(const delete_cmd& i) const;
133 };
134
135 /**
136 * A cmd class that Dumps all the IPv4 L3 configs
137 */
138 class dump_cmd : public VOM::dump_cmd<vapi::Bridge_domain_dump>
139 {
140 public:
141 /**
142 * Constructor
143 */
144 dump_cmd();
145 dump_cmd(const dump_cmd& d);
146
147 /**
148 * Issue the command to VPP/HW
149 */
150 rc_t issue(connection& con);
151 /**
152 * convert to string format for debug purposes
153 */
154 std::string to_string() const;
155
156 /**
157 * Comparison operator - only used for UT
158 */
159 bool operator==(const dump_cmd& i) const;
160
161 private:
162 /**
163 * HW reutrn code
164 */
165 HW::item<bool> item;
166 };
167
168private:
169 /**
170 * Class definition for listeners to OM events
171 */
172 class event_handler : public OM::listener, public inspect::command_handler
173 {
174 public:
175 event_handler();
176 virtual ~event_handler() = default;
177
178 /**
179 * Handle a populate event
180 */
181 void handle_populate(const client_db::key_t& key);
182
183 /**
184 * Handle a replay event
185 */
186 void handle_replay();
187
188 /**
189 * Show the object in the Singular DB
190 */
191 void show(std::ostream& os);
192
193 /**
194 * Get the sortable Id of the listener
195 */
196 dependency_t order() const;
197 };
198
199 /**
200 * Instance of the event handler to register with OM
201 */
202 static event_handler m_evh;
203
204 /**
205 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
206 */
207 void update(const bridge_domain& obj);
208
209 /**
210 * Find or add an singular of a Bridge-Domain in the object_base Model
211 */
212 static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp);
213
214 /*
215 * It's the OM class that calls singular()
216 */
217 friend class OM;
218
219 /**
220 * It's the singular_db class that calls replay()
221 */
222 friend class singular_db<uint32_t, bridge_domain>;
223
224 /**
225 * Sweep/reap the object if still stale
226 */
227 void sweep(void);
228
229 /**
230 * replay the object to create it in hardware
231 */
232 void replay(void);
233
234 /**
235 * The ID we assign to this BD and the HW result in VPP
236 */
237 HW::item<uint32_t> m_id;
238
239 /**
240 * A map of all interfaces key against the interface's name
241 */
242 static singular_db<uint32_t, bridge_domain> m_db;
243};
244};
245
246/*
247 * fd.io coding-style-patch-verification: ON
248 *
249 * Local Variables:
250 * eval: (c-set-style "mozilla")
251 * End:
252 */
253
254#endif