FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
gbp_endpoint_group.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 
19 
20 namespace VOM {
21 
22 singular_db<gbp_endpoint_group::key_t, gbp_endpoint_group>
23  gbp_endpoint_group::m_db;
24 
25 gbp_endpoint_group::event_handler gbp_endpoint_group::m_evh;
26 
28  const interface& itf,
29  const gbp_route_domain& rd,
30  const gbp_bridge_domain& bd)
31  : m_hw(false)
32  , m_epg_id(epg_id)
33  , m_itf(itf.singular())
34  , m_rd(rd.singular())
35  , m_bd(bd.singular())
36 {
37 }
38 
40  const gbp_route_domain& rd,
41  const gbp_bridge_domain& bd)
42  : m_hw(false)
43  , m_epg_id(epg_id)
44  , m_itf()
45  , m_rd(rd.singular())
46  , m_bd(bd.singular())
47 {
48 }
49 
51  : m_hw(epg.m_hw)
52  , m_epg_id(epg.m_epg_id)
53  , m_itf(epg.m_itf)
54  , m_rd(epg.m_rd)
55  , m_bd(epg.m_bd)
56 {
57 }
58 
60 {
61  sweep();
62  m_db.release(key(), this);
63 }
64 
67 {
68  return (m_epg_id);
69 }
70 
73 {
74  return (m_epg_id);
75 }
76 
77 bool
79 {
80  return (key() == gg.key() && (m_itf == gg.m_itf) && (m_rd == gg.m_rd) &&
81  (m_bd == gg.m_bd));
82 }
83 
84 void
85 gbp_endpoint_group::sweep()
86 {
87  if (m_hw) {
89  }
90  HW::write();
91 }
92 
93 void
95 {
96  if (m_hw) {
98  m_hw, m_epg_id, m_bd->id(), m_rd->id(),
99  (m_itf ? m_itf->handle() : handle_t::INVALID)));
100  }
101 }
102 
103 std::string
105 {
106  std::ostringstream s;
107  s << "gbp-endpoint-group:["
108  << "epg:" << m_epg_id << ", " << (m_itf ? m_itf->to_string() : "NULL")
109  << ", " << m_bd->to_string() << ", " << m_rd->to_string() << "]";
110 
111  return (s.str());
112 }
113 
114 void
115 gbp_endpoint_group::update(const gbp_endpoint_group& r)
116 {
117  if (rc_t::OK != m_hw.rc()) {
119  m_hw, m_epg_id, m_bd->id(), m_rd->id(),
120  (m_itf ? m_itf->handle() : handle_t::INVALID)));
121  }
122 }
123 
124 std::shared_ptr<gbp_endpoint_group>
125 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
126 {
127  return (m_db.find_or_add(temp.key(), temp));
128 }
129 
130 std::shared_ptr<gbp_endpoint_group>
132 {
133  return (m_db.find(k));
134 }
135 
136 std::shared_ptr<gbp_endpoint_group>
138 {
139  return find_or_add(*this);
140 }
141 
142 void
143 gbp_endpoint_group::dump(std::ostream& os)
144 {
145  db_dump(m_db, os);
146 }
147 
148 const std::shared_ptr<gbp_route_domain>
150 {
151  return m_rd;
152 }
153 
154 const std::shared_ptr<gbp_bridge_domain>
156 {
157  return m_bd;
158 }
159 
161 {
162  OM::register_listener(this);
163  inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
164  this);
165 }
166 
167 void
168 gbp_endpoint_group::event_handler::handle_replay()
169 {
170  m_db.replay();
171 }
172 
173 void
174 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
175 {
176  std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
177  std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
178 
179  HW::enqueue(cmd);
180  HW::write();
181 
182  for (auto& record : *cmd) {
183  auto& payload = record.get_payload();
184 
185  std::shared_ptr<interface> itf =
186  interface::find(payload.epg.uplink_sw_if_index);
187  std::shared_ptr<gbp_route_domain> rd =
188  gbp_route_domain::find(payload.epg.rd_id);
189  std::shared_ptr<gbp_bridge_domain> bd =
190  gbp_bridge_domain::find(payload.epg.bd_id);
191 
192  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
193  << ", " << payload.epg.rd_id << ", "
194  << payload.epg.bd_id << "]";
195 
196  if (itf && bd && rd) {
197  gbp_endpoint_group gbpe(payload.epg.epg_id, *itf, *rd, *bd);
198  OM::commit(key, gbpe);
199 
200  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
201  } else if (bd && rd) {
202  gbp_endpoint_group gbpe(payload.epg.epg_id, *rd, *bd);
203  OM::commit(key, gbpe);
204 
205  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
206  } else {
207  VOM_LOG(log_level_t::ERROR) << "no itf:" << payload.epg.uplink_sw_if_index
208  << " or BD:" << payload.epg.bd_id
209  << " or RD:" << payload.epg.rd_id;
210  }
211  }
212 }
213 
215 gbp_endpoint_group::event_handler::order() const
216 {
217  return (dependency_t::ACL);
218 }
219 
220 void
222 {
223  db_dump(m_db, os);
224 }
225 } // namespace VOM
226 
227 /*
228  * fd.io coding-style-patch-verification: ON
229  *
230  * Local Variables:
231  * eval: (c-set-style "mozilla")
232  * End:
233  */
const key_t key() const
Return the object&#39;s key.
const std::shared_ptr< gbp_bridge_domain > get_bridge_domain()
#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:527
uint32_t epg_id_t
EPG IDs are 32 bit integers.
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
A cmd class that deletes a GBP endpoint_group.
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
static const handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
static std::shared_ptr< gbp_bridge_domain > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
const std::shared_ptr< gbp_route_domain > get_route_domain()
A entry in the ARP termination table of a Bridge Domain.
u16 epg_id
Definition: gbp.api:116
gbp_endpoint_group(epg_id_t epg_id, const interface &itf, const gbp_route_domain &rd, const gbp_bridge_domain &bd)
Construct a GBP endpoint_group.
void replay(void)
replay the object to create it in hardware
A representation of an interface in VPP.
Definition: interface.hpp:41
A entry in the ARP termination table of a Bridge Domain.
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
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
epg_id_t key_t
The key for a GBP endpoint group is its ID.
static const log_level_t ERROR
Definition: logger.hpp:29
A entry in the ARP termination table of a Route Domain.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
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
bool operator==(const gbp_endpoint_group &bdae) const
comparison operator
epg_id_t id() const
Get the ID of the EPG.
static std::shared_ptr< gbp_endpoint_group > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
std::shared_ptr< gbp_endpoint_group > singular() const
Return the matching &#39;singular instance&#39;.
std::string to_string() const
Convert to string for debugging.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
A command class that creates or updates the GBP endpoint_group.