FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
l2_emulation.cpp
Go to the documentation of this file.
1 /*
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 #include "vom/l2_emulation.hpp"
18 
19 namespace VOM {
20 /**
21  * A DB of all the L2 Configs
22  */
23 singular_db<l2_emulation::key_t, l2_emulation> l2_emulation::m_db;
24 
25 l2_emulation::event_handler l2_emulation::m_evh;
26 
27 /**
28  * Construct a new object matching the desried state
29  */
31  : m_itf(itf.singular())
32  , m_emulation(0)
33 {
34 }
35 
37  : m_itf(o.m_itf)
38  , m_emulation(0)
39 {
40 }
41 
44 {
45  return (m_itf->key());
46 }
47 
48 bool
50 {
51  return ((*m_itf == *l.m_itf));
52 }
53 
54 std::shared_ptr<l2_emulation>
56 {
57  return (m_db.find(key));
58 }
59 
60 void
61 l2_emulation::sweep()
62 {
63  if (m_emulation && handle_t::INVALID != m_itf->handle()) {
65  new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle()));
66  }
67 
68  // no need to undo the VTR operation.
69  HW::write();
70 }
71 
72 void
73 l2_emulation::replay()
74 {
75  if (m_emulation && handle_t::INVALID != m_itf->handle()) {
77  new l2_emulation_cmds::disable_cmd(m_emulation, m_itf->handle()));
78  }
79 }
80 
82 {
83  sweep();
84 
85  // not in the DB anymore.
86  m_db.release(m_itf->key(), this);
87 }
88 
89 std::string
91 {
92  std::ostringstream s;
93  s << "L2-emulation:[" << m_itf->to_string() << "]";
94 
95  return (s.str());
96 }
97 
98 void
99 l2_emulation::update(const l2_emulation& desired)
100 {
101  /*
102  * the desired state is always that the interface should be created
103  */
104  if (rc_t::OK != m_emulation.rc()) {
105  HW::enqueue(
106  new l2_emulation_cmds::enable_cmd(m_emulation, m_itf->handle()));
107  }
108 }
109 
110 std::shared_ptr<l2_emulation>
111 l2_emulation::find_or_add(const l2_emulation& temp)
112 {
113  return (m_db.find_or_add(temp.m_itf->key(), temp));
114 }
115 
116 std::shared_ptr<l2_emulation>
118 {
119  return find_or_add(*this);
120 }
121 
122 void
123 l2_emulation::dump(std::ostream& os)
124 {
125  m_db.dump(os);
126 }
127 
128 l2_emulation::event_handler::event_handler()
129 {
130  OM::register_listener(this);
131  inspect::register_handler({ "l2e" }, "L2 Emulation", this);
132 }
133 
134 void
135 l2_emulation::event_handler::handle_replay()
136 {
137  m_db.replay();
138 }
139 
140 void
141 l2_emulation::event_handler::handle_populate(const client_db::key_t& key)
142 {
143  /**
144  * This is done while populating the bridge-domain
145  */
146 }
147 
149 l2_emulation::event_handler::order() const
150 {
151  return (dependency_t::BINDING);
152 }
153 
154 void
155 l2_emulation::event_handler::show(std::ostream& os)
156 {
157  m_db.dump(os);
158 }
159 }
160 
161 /*
162  * fd.io coding-style-patch-verification: ON
163  *
164  * Local Variables:
165  * eval: (c-set-style "mozilla")
166  * End:
167  */
bool operator==(const l2_emulation &l) const
Comparison operator - for UT.
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
std::shared_ptr< l2_emulation > singular() const
Return the &#39;singular instance&#39; of the L2 config that matches this object.
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:199
l2_emulation(const interface &itf)
Construct a new object matching the desried state.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
const key_t & key() const
Return the binding&#39;s key.
static void dump(std::ostream &os)
Dump all l2_emulations into the stream provided.
A Clas representing the binding of an L2 interface to a bridge-domain and the properties of that bind...
std::string to_string() const
convert to string format for debug purposes
~l2_emulation()
Destructor.
A representation of an interface in VPP.
Definition: interface.hpp:41
A functor class that enable L2 emulation to an interface.
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:106
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:189
static std::shared_ptr< l2_emulation > find(const key_t &key)
Static function to find the bridge_domain in the model.
Then L2/objects that bind to interfaces, BD, ACLS, etc.
interface::key_t key_t
Key type for an L2 emulation in the singular DB.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
A cmd class that Unbinds L2 configuration from an interface.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124