FD.io VPP  v18.07.1-11-g31aa6f2
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,
28  type_t type,
31  : interface(name, type, state)
32  , m_prefix(prefix)
33  , m_l2_address(l2_address_t::ZERO)
34 {
35 }
36 
38  type_t type,
41  const l2_address_t& l2_address)
42  : interface(name, type, state)
43  , m_prefix(prefix)
44  , m_l2_address(l2_address)
45 {
46 }
47 
49 {
50  sweep();
51  release();
52 }
53 
55  : interface(o)
56  , m_prefix(o.m_prefix)
57  , m_l2_address(o.m_l2_address)
58 {
59 }
60 
61 std::queue<cmd*>&
62 tap_interface::mk_create_cmd(std::queue<cmd*>& q)
63 {
64  if (type_t::TAPV2 == type())
65  q.push(new tap_interface_cmds::tapv2_create_cmd(m_hdl, name(), m_prefix,
66  m_l2_address));
67  else
68  q.push(new tap_interface_cmds::tap_create_cmd(m_hdl, name(), m_prefix,
69  m_l2_address));
70 
71  return (q);
72 }
73 
74 std::queue<cmd*>&
75 tap_interface::mk_delete_cmd(std::queue<cmd*>& q)
76 {
77  if (type_t::TAPV2 == type())
79  else
81 
82  return (q);
83 }
84 
85 std::shared_ptr<tap_interface>
87 {
88  return std::dynamic_pointer_cast<tap_interface>(singular_i());
89 }
90 
91 std::shared_ptr<interface>
92 tap_interface::singular_i() const
93 {
94  return m_db.find_or_add(name(), *this);
95 }
96 
97 void
98 tap_interface::event_handler::handle_populate(const client_db::key_t& key)
99 {
100  // It will be polulate by interface handler
101 }
102 
104 {
105  OM::register_listener(this);
106  inspect::register_handler({ "tap" }, "tap_interfaces", this);
107 }
108 
109 void
110 tap_interface::event_handler::handle_replay()
111 {
112  // It will be replayed by interface handler
113 }
114 
116 tap_interface::event_handler::order() const
117 {
118  return (dependency_t::INTERFACE);
119 }
120 
121 void
122 tap_interface::event_handler::show(std::ostream& os)
123 {
124  // dumped by the interface handler
125 }
126 
127 }; // namespace VOM
128 
129 /*
130  * fd.io coding-style-patch-verification: ON
131  *
132  * Local Variables:
133  * eval: (c-set-style "mozilla")
134  * End:
135  */
void release()
release/remove an interface form the singular store
Definition: interface.cpp:234
tap_interface(const std::string &name, type_t type, admin_state_t state, route::prefix_t prefix)
Construct a new object matching the desried state.
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:487
A functor class that creates an interface.
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:163
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 functor class that deletes a Tap interface.
Type def of a L2 address as read from VPP.
Definition: types.hpp:334
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface&#39;s name.
Definition: interface.hpp:519
vhost_vring_state_t state
Definition: vhost_user.h:115
A functor class that creates an interface.
const l2_address_t & l2_address() const
Return the L2 Address.
Definition: interface.cpp:145
The admin state of the interface.
Definition: interface.hpp:142
A representation of an interface in VPP.
Definition: interface.hpp:41
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:265
An interface type.
Definition: interface.hpp:67
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
A functor class that deletes a Tap interface.
typedef prefix
Definition: ip_types.api:40
static const type_t TAPV2
TAPv2 interface type.
Definition: interface.hpp:105
const type_t & type() const
Return the interface type.
Definition: interface.cpp:127
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:271
interfaces are the root of the dependency graph