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