FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
tap_interface.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/tap_interface.hpp"
18 
19 #include <vapi/vpe.api.vapi.hpp>
20 
21 namespace VOM {
22 tap_interface::event_handler tap_interface::m_evh;
23 
24 /**
25  * Construct a new object matching the desried state
26  */
27 tap_interface::tap_interface(const std::string& name,
29  route::prefix_t prefix)
30  : interface(name, type_t::TAP, state)
31  , m_prefix(prefix)
32  , m_l2_address(l2_address_t::ZERO)
33 {
34 }
35 
38  route::prefix_t prefix,
39  const l2_address_t& l2_address)
40  : interface(name, type_t::TAP, state)
41  , m_prefix(prefix)
42  , m_l2_address(l2_address)
43 {
44 }
45 
47 {
48  sweep();
49  release();
50 }
51 
53  : interface(o)
54  , m_prefix(o.m_prefix)
55  , m_l2_address(o.m_l2_address)
56 {
57 }
58 
59 std::queue<cmd*>&
60 tap_interface::mk_create_cmd(std::queue<cmd*>& q)
61 {
62  q.push(
63  new tap_interface_cmds::create_cmd(m_hdl, name(), m_prefix, m_l2_address));
64 
65  return (q);
66 }
67 
68 std::queue<cmd*>&
69 tap_interface::mk_delete_cmd(std::queue<cmd*>& q)
70 {
72 
73  return (q);
74 }
75 
76 std::shared_ptr<tap_interface>
78 {
79  return std::dynamic_pointer_cast<tap_interface>(singular_i());
80 }
81 
82 std::shared_ptr<interface>
83 tap_interface::singular_i() const
84 {
85  return m_db.find_or_add(name(), *this);
86 }
87 
88 void
89 tap_interface::event_handler::handle_populate(const client_db::key_t& key)
90 {
91  /*
92  * dump VPP current states
93  */
94  std::shared_ptr<tap_interface_cmds::dump_cmd> cmd =
95  std::make_shared<tap_interface_cmds::dump_cmd>();
96 
97  HW::enqueue(cmd);
98  HW::write();
99 
100  for (auto& record : *cmd) {
101  auto& payload = record.get_payload();
102 
103  std::string name = reinterpret_cast<const char*>(payload.dev_name);
104 
107 
108  VOM_LOG(log_level_t::DEBUG) << "tap-dump: " << itf.to_string();
109 
110  /*
111  * Write each of the discovered interfaces into the OM,
112  * but disable the HW Command q whilst we do, so that no
113  * commands are sent to VPP
114  */
115  OM::commit(key, itf);
116  }
117 }
118 
120 {
121  OM::register_listener(this);
122  inspect::register_handler({ "tap" }, "tap_interfaces", this);
123 }
124 
125 void
126 tap_interface::event_handler::handle_replay()
127 {
128  // It will be replayed by interface handler
129 }
130 
132 tap_interface::event_handler::order() const
133 {
134  return (dependency_t::INTERFACE);
135 }
136 
137 void
138 tap_interface::event_handler::show(std::ostream& os)
139 {
140  // dumped by the interface handler
141 }
142 
143 }; // namespace VOM
144 
145 /*
146  * fd.io coding-style-patch-verification: ON
147  *
148  * Local Variables:
149  * eval: (c-set-style "mozilla")
150  * End:
151  */
void release()
release/remove an interface form the singular store
Definition: interface.cpp:233
#define VOM_LOG(lvl)
Definition: logger.hpp:181
A tap-interface.
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:473
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:162
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
Type def of a L2 address as read from VPP.
Definition: types.hpp:342
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface&#39;s name.
Definition: interface.hpp:505
const l2_address_t & l2_address() const
Return the L2 Address.
Definition: interface.cpp:144
A functor class that creates an interface.
The admin state of the interface.
Definition: interface.hpp:127
A representation of an interface in VPP.
Definition: interface.hpp: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:311
std::shared_ptr< tap_interface > singular() const
Return the matching &#39;singular instance&#39; of the TAP interface.
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
const std::string & name() const
Return the interface type.
Definition: interface.cpp:264
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
A functor class that deletes a Tap interface.
vhost_vring_state_t state
Definition: vhost-user.h:82
An interface type.
Definition: interface.hpp:67
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static const admin_state_t UP
Admin UP state.
Definition: interface.hpp:136
A representation of a method call to VPP.
Definition: cmd.hpp:32
tap_interface(const std::string &name, admin_state_t state, route::prefix_t prefix)
Construct a new object matching the desried state.
static const prefix_t ZERO
The all Zeros prefix.
Definition: prefix.hpp:165
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
virtual std::string to_string(void) const
convert to string format for debug purposes
Definition: interface.cpp:240
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
A prefix defintion.
Definition: prefix.hpp:93
const key_t & key() const
Return the interface type.
Definition: interface.cpp:270
interfaces are the root of the dependency graph