FD.io VPP  v21.06-3-gbb25fbf28
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->sclass()));
92  }
93 }
94 
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->sclass()));
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.sclass);
166 
167  VOM_LOG(log_level_t::DEBUG) << "data: [" << payload.recirc.sw_if_index
168  << ", " << payload.recirc.sclass << "]";
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: OFF
196  *
197  * Local Variables:
198  * eval: (c-set-style "mozilla")
199  * End:
200  */
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM::OM::commit
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
VOM::gbp_recirc::operator==
bool operator==(const gbp_recirc &bdae) const
comparison operator
Definition: gbp_recirc.cpp:71
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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
gbp_recirc.hpp
VOM::gbp_recirc::gbp_recirc
gbp_recirc(const interface &itf, const type_t &type, const gbp_endpoint_group &epg)
Construct a GBP recirc.
Definition: gbp_recirc.cpp:34
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::gbp_recirc::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_recirc.cpp:133
VOM::gbp_recirc::~gbp_recirc
~gbp_recirc()
Destructor.
Definition: gbp_recirc.cpp:52
gbp_recirc
typedef gbp_recirc
Definition: gbp.api:224
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
key
typedef key
Definition: ipsec_types.api:88
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::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
VOM::gbp_recirc::handle
const handle_t & handle() const
return the recirculation interface's handle
Definition: gbp_recirc.cpp:65
VOM::gbp_endpoint_group::find
static std::shared_ptr< gbp_endpoint_group > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_endpoint_group.cpp:188
VOM::gbp_recirc::to_string
std::string to_string() const
Convert to string for debugging.
Definition: gbp_recirc.cpp:96
VOM::gbp_recirc
A recirculation interface for GBP use pre/post NAT.
Definition: gbp_recirc.hpp:27
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::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::gbp_recirc::key_t
interface::key_t key_t
The key for a GBP recirc interface.
Definition: gbp_recirc.hpp:33
false
#define false
Definition: cJSON.c:70
singular_db_funcs.hpp
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::gbp_recirc_cmds::delete_cmd
A cmd class that deletes a GBP recirc.
Definition: gbp_recirc_cmds.hpp:65
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
gbp_recirc_cmds.hpp
VOM::gbp_recirc_cmds::create_cmd
A command class that creates or updates the GBP recirc.
Definition: gbp_recirc_cmds.hpp:30
VOM::gbp_recirc::type_t
Definition: gbp_recirc.hpp:35
VOM::gbp_recirc::replay
void replay(void)
replay the object to create it in hardware
Definition: gbp_recirc.cpp:87
VOM::gbp_recirc::type_t::INTERNAL
const static type_t INTERNAL
Internal recirclation interfaces accept per-NAT translation traffic from the external/NAT EPG and inj...
Definition: gbp_recirc.hpp:42
VOM::dependency_t::BINDING
@ BINDING
Then L2/objects that bind to interfaces, BD, ACLS, etc.
VOM::gbp_recirc::key
const key_t key() const
Return the object's key.
Definition: gbp_recirc.cpp:59
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
VOM::gbp_endpoint_group
A entry in the ARP termination table of a Bridge Domain.
Definition: gbp_endpoint_group.hpp:32
VOM::gbp_recirc::type_t::EXTERNAL
const static type_t EXTERNAL
External recirculation interfaces accept post-NAT translation traffic from the internal EPG and injec...
Definition: gbp_recirc.hpp:49
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
VOM::gbp_recirc::find
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
VOM::interface::find
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:538
VOM::gbp_recirc::singular
std::shared_ptr< gbp_recirc > singular() const
Return the matching 'singular instance'.
Definition: gbp_recirc.cpp:127
string
const char *const string
Definition: cJSON.h:172