blob: 0e6f7fc0d68adb88656f0df44686a613304e8a3b [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_L2_BINDING_H__
17#define __VOM_L2_BINDING_H__
18
19#include "vom/bridge_domain.hpp"
20#include "vom/hw.hpp"
21#include "vom/inspect.hpp"
22#include "vom/interface.hpp"
23#include "vom/object_base.hpp"
24#include "vom/om.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070025#include "vom/singular_db.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070026
27namespace VOM {
28/**
29 * A Clas representing the binding of an L2 interface to a bridge-domain
30 * and the properties of that binding.
31 */
32class l2_binding : public object_base
33{
34public:
35 struct l2_vtr_op_t : public enum_base<l2_vtr_op_t>
36 {
37 l2_vtr_op_t(const l2_vtr_op_t& l) = default;
38 ~l2_vtr_op_t() = default;
39
40 const static l2_vtr_op_t L2_VTR_DISABLED;
41 const static l2_vtr_op_t L2_VTR_PUSH_1;
42 const static l2_vtr_op_t L2_VTR_PUSH_2;
43 const static l2_vtr_op_t L2_VTR_POP_1;
44 const static l2_vtr_op_t L2_VTR_POP_2;
45 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_1;
46 const static l2_vtr_op_t L2_VTR_TRANSLATE_1_2;
47 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_1;
48 const static l2_vtr_op_t L2_VTR_TRANSLATE_2_2;
49
50 private:
51 l2_vtr_op_t(int v, const std::string s);
52 };
53
54 /**
55 * Construct a new object matching the desried state
56 */
57 l2_binding(const interface& itf, const bridge_domain& bd);
58
59 /**
60 * Copy Constructor
61 */
62 l2_binding(const l2_binding& o);
63
64 /**
65 * Destructor
66 */
67 ~l2_binding();
68
69 /**
70 * Return the 'singular instance' of the L2 config that matches this
71 * object
72 */
73 std::shared_ptr<l2_binding> singular() const;
74
75 /**
76 * convert to string format for debug purposes
77 */
78 std::string to_string() const;
79
80 /**
81 * Dump all l2_bindings into the stream provided
82 */
83 static void dump(std::ostream& os);
84
85 /**
86 * Set the VTR operation on the binding/interface
87 */
88 void set(const l2_vtr_op_t& op, uint16_t tag);
89
Neale Ranns812ed392017-10-16 04:20:13 -070090private:
91 /**
92 * Class definition for listeners to OM events
93 */
94 class event_handler : public OM::listener, public inspect::command_handler
95 {
96 public:
97 event_handler();
98 virtual ~event_handler() = default;
99
100 /**
101 * Handle a populate event
102 */
103 void handle_populate(const client_db::key_t& key);
104
105 /**
106 * Handle a replay event
107 */
108 void handle_replay();
109
110 /**
111 * Show the object in the Singular DB
112 */
113 void show(std::ostream& os);
114
115 /**
116 * Get the sortable Id of the listener
117 */
118 dependency_t order() const;
119 };
120
121 /**
122 * event_handler to register with OM
123 */
124 static event_handler m_evh;
125
126 /**
127 * Enquue commonds to the VPP command Q for the update
128 */
129 void update(const l2_binding& obj);
130
131 /**
132 * Find or Add the singular instance in the DB
133 */
134 static std::shared_ptr<l2_binding> find_or_add(const l2_binding& temp);
135
136 /*
137 * It's the OM class that calls singular()
138 */
139 friend class OM;
140
141 /**
142 * It's the singular_db class that calls replay()
143 */
144 friend class singular_db<const handle_t, l2_binding>;
145
146 /**
147 * Sweep/reap the object if still stale
148 */
149 void sweep(void);
150
151 /**
152 * replay the object to create it in hardware
153 */
154 void replay(void);
155
156 /**
157 * A reference counting pointer the interface that this L2 layer
158 * represents. By holding the reference here, we can guarantee that
159 * this object will outlive the interface
160 */
161 const std::shared_ptr<interface> m_itf;
162
163 /**
164 * A reference counting pointer the Bridge-Domain that this L2
165 * interface is bound to. By holding the reference here, we can
166 * guarantee that this object will outlive the BD.
167 */
168 const std::shared_ptr<bridge_domain> m_bd;
169
170 /**
171 * HW configuration for the binding. The bool representing the
172 * do/don't bind.
173 */
174 HW::item<bool> m_binding;
175
176 /**
177 * HW configuration for the VTR option
178 */
179 HW::item<l2_vtr_op_t> m_vtr_op;
180
181 /**
182 * The Dot1q tag for the VTR operation
183 */
184 uint16_t m_vtr_op_tag;
185
186 /**
187 * A map of all L2 interfaces key against the interface's handle_t
188 */
189 static singular_db<const handle_t, l2_binding> m_db;
190};
191};
192
193/*
194 * fd.io coding-style-patch-verification: ON
195 *
196 * Local Variables:
197 * eval: (c-set-style "mozilla")
198 * End:
199 */
200
201#endif