FD.io VPP  v18.07.1-19-g511ce25
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 route_domain& rd,
30  const 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  : m_hw(epg.m_hw)
41  , m_epg_id(epg.m_epg_id)
42  , m_itf(epg.m_itf)
43  , m_rd(epg.m_rd)
44  , m_bd(epg.m_bd)
45 {
46 }
47 
49 {
50  sweep();
51  m_db.release(key(), this);
52 }
53 
56 {
57  return (m_epg_id);
58 }
59 
62 {
63  return (m_epg_id);
64 }
65 
66 bool
68 {
69  return (key() == gbpe.key() && (m_itf == gbpe.m_itf) && (m_rd == gbpe.m_rd) &&
70  (m_bd == gbpe.m_bd));
71 }
72 
73 void
74 gbp_endpoint_group::sweep()
75 {
76  if (m_hw) {
78  }
79  HW::write();
80 }
81 
82 void
84 {
85  if (m_hw) {
87  m_hw, m_epg_id, m_bd->id(), m_rd->table_id(), m_itf->handle()));
88  }
89 }
90 
91 std::string
93 {
94  std::ostringstream s;
95  s << "gbp-endpoint-group:["
96  << "epg:" << m_epg_id << ", " << m_itf->to_string() << ", "
97  << m_bd->to_string() << ", " << m_rd->to_string() << "]";
98 
99  return (s.str());
100 }
101 
102 void
103 gbp_endpoint_group::update(const gbp_endpoint_group& r)
104 {
105  if (rc_t::OK != m_hw.rc()) {
107  m_hw, m_epg_id, m_bd->id(), m_rd->table_id(), m_itf->handle()));
108  }
109 }
110 
111 std::shared_ptr<gbp_endpoint_group>
112 gbp_endpoint_group::find_or_add(const gbp_endpoint_group& temp)
113 {
114  return (m_db.find_or_add(temp.key(), temp));
115 }
116 
117 std::shared_ptr<gbp_endpoint_group>
119 {
120  return (m_db.find(k));
121 }
122 
123 std::shared_ptr<gbp_endpoint_group>
125 {
126  return find_or_add(*this);
127 }
128 
129 void
130 gbp_endpoint_group::dump(std::ostream& os)
131 {
132  db_dump(m_db, os);
133 }
134 
136 {
137  OM::register_listener(this);
138  inspect::register_handler({ "gbp-endpoint-group" }, "GBP Endpoint_Groups",
139  this);
140 }
141 
142 void
143 gbp_endpoint_group::event_handler::handle_replay()
144 {
145  m_db.replay();
146 }
147 
148 void
149 gbp_endpoint_group::event_handler::handle_populate(const client_db::key_t& key)
150 {
151  std::shared_ptr<gbp_endpoint_group_cmds::dump_cmd> cmd =
152  std::make_shared<gbp_endpoint_group_cmds::dump_cmd>();
153 
154  HW::enqueue(cmd);
155  HW::write();
156 
157  for (auto& record : *cmd) {
158  auto& payload = record.get_payload();
159 
160  std::shared_ptr<interface> itf =
161  interface::find(payload.epg.uplink_sw_if_index);
162  std::shared_ptr<route_domain> rd =
163  route_domain::find(payload.epg.ip4_table_id);
164  std::shared_ptr<bridge_domain> bd = bridge_domain::find(payload.epg.bd_id);
165 
166  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.epg.uplink_sw_if_index
167  << ", " << payload.epg.ip4_table_id << ", "
168  << payload.epg.bd_id << "]";
169 
170  if (itf && bd && rd) {
171  gbp_endpoint_group gbpe(payload.epg.epg_id, *itf, *rd, *bd);
172  OM::commit(key, gbpe);
173 
174  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpe.to_string();
175  }
176  }
177 }
178 
180 gbp_endpoint_group::event_handler::order() const
181 {
182  return (dependency_t::ACL);
183 }
184 
185 void
187 {
188  db_dump(m_db, os);
189 }
190 } // namespace VOM
191 
192 /*
193  * fd.io coding-style-patch-verification: ON
194  *
195  * Local Variables:
196  * eval: (c-set-style "mozilla")
197  * End:
198  */
static std::shared_ptr< route_domain > find(const key_t &temp)
Find the instnace of the route domain in the OM.
#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.
gbp_endpoint_group(epg_id_t epg_id, const interface &itf, const route_domain &rd, const bridge_domain &bd)
Construct a GBP endpoint_group.
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:461
uint32_t epg_id_t
EPG IDs are 32 bit integers.
std::string to_string() const
Convert to string for debugging.
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:236
static const log_level_t DEBUG
Definition: logger.hpp:32
static std::shared_ptr< bridge_domain > find(const key_t &key)
Static function to find the bridge_domain in the model.
const key_t key() const
Return the object&#39;s key.
A route-domain is a VRF.
epg_id_t id() const
Get the ID of the EPG.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
bool operator==(const gbp_endpoint_group &bdae) const
comparison operator
std::shared_ptr< gbp_endpoint_group > singular() const
Return the matching &#39;singular instance&#39;.
void replay(void)
replay the object to create it in hardware
A representation of an interface in VPP.
Definition: interface.hpp:41
A base class for all object_base in the VPP object_base-Model.
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:311
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:104
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
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.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static std::shared_ptr< gbp_endpoint_group > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
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.