FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
gbp_vxlan.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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_vxlan.hpp"
17 #include "vom/gbp_vxlan_cmds.hpp"
18 #include "vom/interface.hpp"
20 
21 namespace VOM {
22 
23 const std::string GBP_VXLAN_NAME = "gbp-vxlan";
24 
25 /**
26  * A DB of al the interfaces, key on the name
27  */
29 
30 gbp_vxlan::event_handler gbp_vxlan::m_evh;
31 
33  : interface(mk_name(vni),
36  , m_vni(vni)
37  , m_gbd()
38  , m_grd(grd.singular())
39 {
40 }
42  : interface(mk_name(vni),
45  , m_vni(vni)
46  , m_gbd(gbd.singular())
47  , m_grd()
48 {
49 }
50 
52  : interface(vt)
53  , m_vni(vt.m_vni)
54  , m_gbd(vt.m_gbd)
55  , m_grd(vt.m_grd)
56 {
57 }
58 
59 std::string
60 gbp_vxlan::mk_name(uint32_t vni)
61 {
62  std::ostringstream s;
63 
64  s << GBP_VXLAN_NAME << "-" << vni;
65 
66  return (s.str());
67 }
68 
69 const gbp_vxlan::key_t
71 {
72  return (m_vni);
73 }
74 
75 bool
77 {
78  return (m_vni == vt.m_vni);
79 }
80 
81 void
82 gbp_vxlan::sweep()
83 {
84  if (rc_t::OK == m_hdl) {
86  }
87  HW::write();
88 }
89 
90 void
91 gbp_vxlan::replay()
92 {
93  if (rc_t::OK == m_hdl) {
94  if (m_grd)
95  HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, false,
96  m_grd->id()));
97  else if (m_gbd)
99  m_gbd->id()));
100  }
101 }
102 
104 {
105  sweep();
106  m_db.release(key(), this);
107 }
108 
109 std::string
111 {
112  std::ostringstream s;
113  s << "gbp-vxlan:[" << m_vni << "]";
114 
115  return (s.str());
116 }
117 
118 std::shared_ptr<gbp_vxlan>
120 {
121  return (m_db.find(key));
122 }
123 
124 void
125 gbp_vxlan::update(const gbp_vxlan& desired)
126 {
127  /*
128  * the desired state is always that the interface should be created
129  */
130  if (rc_t::OK != m_hdl) {
131  if (m_grd)
132  HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, false,
133  m_grd->id()));
134  else if (m_gbd)
135  HW::enqueue(new gbp_vxlan_cmds::create_cmd(m_hdl, name(), m_vni, true,
136  m_gbd->id()));
137  }
138 }
139 
140 std::shared_ptr<gbp_vxlan>
141 gbp_vxlan::find_or_add(const gbp_vxlan& temp)
142 {
143  return (m_db.find_or_add(temp.key(), temp));
144 }
145 
146 std::shared_ptr<gbp_vxlan>
148 {
149  return find_or_add(*this);
150 }
151 
152 std::shared_ptr<interface>
153 gbp_vxlan::singular_i() const
154 {
155  return find_or_add(*this);
156 }
157 
158 void
159 gbp_vxlan::dump(std::ostream& os)
160 {
161  db_dump(m_db, os);
162 }
163 
164 void
165 gbp_vxlan::event_handler::handle_populate(const client_db::key_t& key)
166 {
167  /*
168  * dump VPP Bridge domains
169  */
170  std::shared_ptr<gbp_vxlan_cmds::dump_cmd> cmd =
171  std::make_shared<gbp_vxlan_cmds::dump_cmd>();
172 
173  HW::enqueue(cmd);
174  HW::write();
175 
176  for (auto& record : *cmd) {
177  auto& payload = record.get_payload();
178 
179  if (GBP_VXLAN_TUNNEL_MODE_L3 == payload.tunnel.mode) {
180  auto rd = gbp_route_domain::find(payload.tunnel.bd_rd_id);
181 
182  if (rd) {
183  gbp_vxlan vt(payload.tunnel.vni, *rd);
184  OM::commit(key, vt);
185  VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
186  }
187  } else {
188  auto bd = gbp_bridge_domain::find(payload.tunnel.bd_rd_id);
189 
190  if (bd) {
191  gbp_vxlan vt(payload.tunnel.vni, *bd);
192  OM::commit(key, vt);
193  VOM_LOG(log_level_t::DEBUG) << "dump: " << vt.to_string();
194  }
195  }
196  }
197 }
198 
200 {
201  OM::register_listener(this);
202  inspect::register_handler({ "gvt", "gbp-vxlan-tunnel" }, "GBP VXLAN Tunnels",
203  this);
204 }
205 
206 void
207 gbp_vxlan::event_handler::handle_replay()
208 {
209  m_db.replay();
210 }
211 
213 gbp_vxlan::event_handler::order() const
214 {
215  return (dependency_t::BINDING);
216 }
217 
218 void
219 gbp_vxlan::event_handler::show(std::ostream& os)
220 {
221  db_dump(m_db, os);
222 }
223 }
224 
225 /*
226  * fd.io coding-style-patch-verification: ON
227  *
228  * Local Variables:
229  * eval: (c-set-style "mozilla")
230  * End:
231  */
static void dump(std::ostream &os)
Dump all L3Configs into the stream provided.
Definition: gbp_vxlan.cpp:159
#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
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:532
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
static const log_level_t DEBUG
Definition: logger.hpp:32
A command class that creates an Bridge-Domain.
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::string & name() const
Return the interface type.
Definition: interface.cpp:264
std::shared_ptr< gbp_vxlan > singular() const
Return the matching &#39;singular instance&#39;.
Definition: gbp_vxlan.cpp:147
A entry in the ARP termination table of a Bridge Domain.
A representation of a GBP_VXLAN Tunnel in VPP.
Definition: gbp_vxlan.hpp:30
virtual std::string to_string() const
Debug rpint function.
Definition: gbp_vxlan.cpp:110
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
A cmd class that Delete an Bridge-Domain.
The admin state of the interface.
Definition: interface.hpp:138
A representation of an interface in VPP.
Definition: interface.hpp:41
gbp_vxlan(uint32_t vni, const gbp_bridge_domain &gbd)
Construct a new object matching the desried state.
Definition: gbp_vxlan.cpp:41
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
An interface type.
Definition: interface.hpp:67
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_vxlan.cpp:70
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.
u32 vni
Definition: vxlan_gbp.api:36
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
uint32_t key_t
The VNI is the key.
Definition: gbp_vxlan.hpp:36
static std::shared_ptr< gbp_vxlan > find(const key_t k)
Find the GBP_VXLAN tunnel in the OM.
Definition: gbp_vxlan.cpp:119
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
const std::string GBP_VXLAN_NAME
Definition: gbp_vxlan.cpp:23
bool operator==(const gbp_vxlan &vt) const
Definition: gbp_vxlan.cpp:76