FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
gbp_recirc.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_recirc.hpp"
17 #include "vom/gbp_recirc_cmds.hpp"
19 
20 namespace VOM {
21 
22 gbp_recirc::type_t::type_t(int v, const std::string s)
23  : enum_base<gbp_recirc::type_t>(v, s)
24 {
25 }
26 
27 const gbp_recirc::type_t gbp_recirc::type_t::INTERNAL(0, "internal");
28 const gbp_recirc::type_t gbp_recirc::type_t::EXTERNAL(1, "external");
29 
30 singular_db<gbp_recirc::key_t, gbp_recirc> gbp_recirc::m_db;
31 
32 gbp_recirc::event_handler gbp_recirc::m_evh;
33 
35  const type_t& type,
36  const gbp_endpoint_group& epg)
37  : m_hw(false)
38  , m_itf(itf.singular())
39  , m_type(type)
40  , m_epg(epg.singular())
41 {
42 }
43 
45  : m_hw(gbpe.m_hw)
46  , m_itf(gbpe.m_itf)
47  , m_type(gbpe.m_type)
48  , m_epg(gbpe.m_epg)
49 {
50 }
51 
53 {
54  sweep();
55  m_db.release(key(), this);
56 }
57 
60 {
61  return (m_itf->key());
62 }
63 
64 const handle_t&
66 {
67  return m_itf->handle();
68 }
69 
70 bool
72 {
73  return ((key() == gbpe.key()) && (m_type == gbpe.m_type) &&
74  (m_itf == gbpe.m_itf) && (m_epg == gbpe.m_epg));
75 }
76 
77 void
78 gbp_recirc::sweep()
79 {
80  if (m_hw) {
81  HW::enqueue(new gbp_recirc_cmds::delete_cmd(m_hw, m_itf->handle()));
82  }
83  HW::write();
84 }
85 
86 void
88 {
89  if (m_hw) {
91  m_hw, m_itf->handle(), (m_type == type_t::EXTERNAL), m_epg->id()));
92  }
93 }
94 
95 std::string
97 {
98  std::ostringstream s;
99  s << "gbp-recirc:[" << m_itf->to_string() << ", type:" << m_type.to_string()
100  << ", " << m_epg->to_string() << "]";
101 
102  return (s.str());
103 }
104 
105 void
106 gbp_recirc::update(const gbp_recirc& r)
107 {
108  if (rc_t::OK != m_hw.rc()) {
110  m_hw, m_itf->handle(), (m_type == type_t::EXTERNAL), m_epg->id()));
111  }
112 }
113 
114 std::shared_ptr<gbp_recirc>
115 gbp_recirc::find_or_add(const gbp_recirc& temp)
116 {
117  return (m_db.find_or_add(temp.key(), temp));
118 }
119 
120 std::shared_ptr<gbp_recirc>
122 {
123  return (m_db.find(k));
124 }
125 
126 std::shared_ptr<gbp_recirc>
128 {
129  return find_or_add(*this);
130 }
131 
132 void
133 gbp_recirc::dump(std::ostream& os)
134 {
135  db_dump(m_db, os);
136 }
137 
139 {
140  OM::register_listener(this);
141  inspect::register_handler({ "gbp-recirc" }, "GBP Recircs", this);
142 }
143 
144 void
145 gbp_recirc::event_handler::handle_replay()
146 {
147  m_db.replay();
148 }
149 
150 void
151 gbp_recirc::event_handler::handle_populate(const client_db::key_t& key)
152 {
153  std::shared_ptr<gbp_recirc_cmds::dump_cmd> cmd =
154  std::make_shared<gbp_recirc_cmds::dump_cmd>();
155 
156  HW::enqueue(cmd);
157  HW::write();
158 
159  for (auto& record : *cmd) {
160  auto& payload = record.get_payload();
161 
162  std::shared_ptr<interface> itf =
163  interface::find(payload.recirc.sw_if_index);
164  std::shared_ptr<gbp_endpoint_group> epg =
165  gbp_endpoint_group::find(payload.recirc.epg_id);
166 
167  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.recirc.sw_if_index
168  << ", " << payload.recirc.epg_id << "]";
169 
170  if (itf && epg) {
171  gbp_recirc recirc(
172  *itf, (payload.recirc.is_ext ? type_t::EXTERNAL : type_t::INTERNAL),
173  *epg);
174  OM::commit(key, recirc);
175 
176  VOM_LOG(log_level_t::DEBUG) << "read: " << recirc.to_string();
177  }
178  }
179 }
180 
182 gbp_recirc::event_handler::order() const
183 {
184  return (dependency_t::BINDING);
185 }
186 
187 void
188 gbp_recirc::event_handler::show(std::ostream& os)
189 {
190  db_dump(m_db, os);
191 }
192 } // namespace VOM
193 
194 /*
195  * fd.io coding-style-patch-verification: ON
196  *
197  * Local Variables:
198  * eval: (c-set-style "mozilla")
199  * End:
200  */
void replay(void)
replay the object to create it in hardware
Definition: gbp_recirc.cpp:87
#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:461
bool operator==(const gbp_recirc &bdae) const
comparison operator
Definition: gbp_recirc.cpp:71
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:236
static const log_level_t DEBUG
Definition: logger.hpp:32
std::shared_ptr< gbp_recirc > singular() const
Return the matching &#39;singular instance&#39;.
Definition: gbp_recirc.cpp:127
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_recirc.cpp:133
~gbp_recirc()
Destructor.
Definition: gbp_recirc.cpp:52
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
const handle_t & handle() const
return the recirculation interface&#39;s handle
Definition: gbp_recirc.cpp:65
interface::key_t key_t
The key for a GBP recirc interface.
Definition: gbp_recirc.hpp:33
#define v
Definition: acl.c:491
A recirculation interface for GBP use pre/post NAT.
Definition: gbp_recirc.hpp:27
A cmd class that deletes a GBP recirc.
A command class that creates or updates the GBP recirc.
A representation of an interface in VPP.
Definition: interface.hpp:41
A entry in the ARP termination table of a Bridge Domain.
static const type_t EXTERNAL
External recirculation interfaces accept post-NAT translation traffic from the internal EPG and injec...
Definition: gbp_recirc.hpp:49
A type declaration of an interface handle in VPP.
Definition: types.hpp:228
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
gbp_recirc(const interface &itf, const type_t &type, const gbp_endpoint_group &epg)
Construct a GBP recirc.
Definition: gbp_recirc.cpp:34
static std::shared_ptr< gbp_recirc > find(const key_t &k)
Find the instnace of the recirc interface in the OM.
Definition: gbp_recirc.cpp:121
Then L2/objects that bind to interfaces, BD, ACLS, etc.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
static const type_t INTERNAL
Internal recirclation interfaces accept per-NAT translation traffic from the external/NAT EPG and inj...
Definition: gbp_recirc.hpp:42
std::string to_string() const
Convert to string for debugging.
Definition: gbp_recirc.cpp:96
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.
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
const key_t key() const
Return the object&#39;s key.
Definition: gbp_recirc.cpp:59