FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
gbp_ext_itf.cpp
Go to the documentation of this file.
1 /*
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 #include "vom/gbp_ext_itf.hpp"
17 #include "vom/gbp_ext_itf_cmds.hpp"
19 
20 namespace VOM {
21 
22 singular_db<gbp_ext_itf::key_t, gbp_ext_itf> gbp_ext_itf::m_db;
23 
24 gbp_ext_itf::event_handler gbp_ext_itf::m_evh;
25 
27  const gbp_bridge_domain& gbd,
28  const gbp_route_domain& grd)
29  : m_hw(false)
30  , m_itf(itf.singular())
31  , m_bd(gbd.singular())
32  , m_rd(grd.singular())
33 {
34 }
35 
37  : m_hw(gbpe.m_hw)
38  , m_itf(gbpe.m_itf)
39  , m_bd(gbpe.m_bd)
40  , m_rd(gbpe.m_rd)
41 {
42 }
43 
45 {
46  sweep();
47  m_db.release(key(), this);
48 }
49 
52 {
53  return (m_itf->key());
54 }
55 
56 const handle_t&
58 {
59  return m_itf->handle();
60 }
61 
62 bool
64 {
65  return ((key() == gei.key()) && (m_itf == gei.m_itf) && (m_rd == gei.m_rd) &&
66  (m_bd == gei.m_bd));
67 }
68 
69 void
70 gbp_ext_itf::sweep()
71 {
72  if (m_hw) {
73  HW::enqueue(new gbp_ext_itf_cmds::delete_cmd(m_hw, m_itf->handle()));
74  }
75  HW::write();
76 }
77 
78 void
80 {
81  if (m_hw) {
82  HW::enqueue(new gbp_ext_itf_cmds::create_cmd(m_hw, m_itf->handle(),
83  m_bd->id(), m_rd->id()));
84  }
85 }
86 
87 std::string
89 {
90  std::ostringstream s;
91  s << "gbp-ext_itf:[" << m_itf->to_string() << ", " << m_bd->to_string()
92  << ", " << m_rd->to_string() << "]";
93 
94  return (s.str());
95 }
96 
97 void
98 gbp_ext_itf::update(const gbp_ext_itf& r)
99 {
100  if (rc_t::OK != m_hw.rc()) {
101  HW::enqueue(new gbp_ext_itf_cmds::create_cmd(m_hw, m_itf->handle(),
102  m_bd->id(), m_rd->id()));
103  }
104 }
105 
106 std::shared_ptr<gbp_ext_itf>
107 gbp_ext_itf::find_or_add(const gbp_ext_itf& temp)
108 {
109  return (m_db.find_or_add(temp.key(), temp));
110 }
111 
112 std::shared_ptr<gbp_ext_itf>
114 {
115  return (m_db.find(k));
116 }
117 
118 std::shared_ptr<gbp_ext_itf>
120 {
121  return find_or_add(*this);
122 }
123 
124 void
125 gbp_ext_itf::dump(std::ostream& os)
126 {
127  db_dump(m_db, os);
128 }
129 
131 {
132  OM::register_listener(this);
133  inspect::register_handler({ "gbp-ext-itf" }, "GBP External-Itfs", this);
134 }
135 
136 void
137 gbp_ext_itf::event_handler::handle_replay()
138 {
139  m_db.replay();
140 }
141 
142 void
143 gbp_ext_itf::event_handler::handle_populate(const client_db::key_t& key)
144 {
145  std::shared_ptr<gbp_ext_itf_cmds::dump_cmd> cmd =
146  std::make_shared<gbp_ext_itf_cmds::dump_cmd>();
147 
148  HW::enqueue(cmd);
149  HW::write();
150 
151  for (auto& record : *cmd) {
152  auto& payload = record.get_payload();
153 
154  std::shared_ptr<interface> itf =
155  interface::find(payload.ext_itf.sw_if_index);
156  std::shared_ptr<gbp_bridge_domain> gbd =
157  gbp_bridge_domain::find(payload.ext_itf.bd_id);
158  std::shared_ptr<gbp_route_domain> grd =
159  gbp_route_domain::find(payload.ext_itf.rd_id);
160 
161  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.ext_itf.sw_if_index
162  << ", " << payload.ext_itf.bd_id << ", "
163  << payload.ext_itf.rd_id << "]";
164 
165  if (itf && gbd && grd) {
166  gbp_ext_itf ext_itf(*itf, *gbd, *grd);
167  OM::commit(key, ext_itf);
168 
169  VOM_LOG(log_level_t::DEBUG) << "read: " << ext_itf.to_string();
170  } else {
171  VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.ext_itf.sw_if_index
172  << " or BD:" << payload.ext_itf.bd_id
173  << " or RD:" << payload.ext_itf.rd_id;
174  }
175  }
176 }
177 
179 gbp_ext_itf::event_handler::order() const
180 {
181  return (dependency_t::BINDING);
182 }
183 
184 void
185 gbp_ext_itf::event_handler::show(std::ostream& os)
186 {
187  db_dump(m_db, os);
188 }
189 } // namespace VOM
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "mozilla")
196  * End:
197  */
~gbp_ext_itf()
Destructor.
Definition: gbp_ext_itf.cpp:44
#define VOM_LOG(lvl)
Definition: logger.hpp:181
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
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 std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:531
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:255
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
static const log_level_t DEBUG
Definition: logger.hpp:32
gbp_ext_itf(const interface &itf, const gbp_bridge_domain &gbd, const gbp_route_domain &grd)
Construct a GBP ext_itf.
Definition: gbp_ext_itf.cpp:26
static std::shared_ptr< gbp_bridge_domain > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
static std::shared_ptr< gbp_ext_itf > find(const key_t &k)
Find the instnace of the ext_itf interface in the OM.
const handle_t & handle() const
return the ext_itfulation interface&#39;s handle
Definition: gbp_ext_itf.cpp:57
A enternal interface for GBP.
Definition: gbp_ext_itf.hpp:28
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
A entry in the ARP termination table of a Bridge Domain.
bool operator==(const gbp_ext_itf &bdae) const
comparison operator
Definition: gbp_ext_itf.cpp:63
A representation of an interface in VPP.
Definition: interface.hpp:41
std::string to_string() const
Convert to string for debugging.
Definition: gbp_ext_itf.cpp:88
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
void event_handler(void *tls_async)
Definition: tls_async.c:340
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:109
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
std::shared_ptr< gbp_ext_itf > singular() const
Return the matching &#39;singular instance&#39;.
static const log_level_t ERROR
Definition: logger.hpp:29
A entry in the ARP termination table of a Route Domain.
Then L2/objects that bind to interfaces, BD, ACLS, etc.
const key_t key() const
Return the object&#39;s key.
Definition: gbp_ext_itf.cpp:51
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
A cmd class that deletes a GBP ext_itf.
static std::shared_ptr< gbp_route_domain > find(const key_t &k)
Find the instnace of the route_domain domain in the OM.
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
interface::key_t key_t
The key for a GBP ext_itf interface.
Definition: gbp_ext_itf.hpp:34
void replay(void)
replay the object to create it in hardware
Definition: gbp_ext_itf.cpp:79
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
A command class that creates or updates the GBP ext_itf.