FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
sub_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/sub_interface.hpp"
18 
19 namespace VOM {
20 /**
21  * Construct a new object matching the desried state
22  */
25  vlan_id_t vlan)
26  : interface(mk_name(parent, vlan), parent.type(), state)
27  , m_parent(parent.singular())
28  , m_vlan(vlan)
29 {
30 }
31 
33 {
34  sweep();
35  release();
36 }
37 
39  : interface(o)
40  , m_parent(o.m_parent)
41  , m_vlan(o.m_vlan)
42 {
43 }
44 
45 bool
47 {
48  return (interface::operator==(s) && (m_parent->key() == s.m_parent->key()) &&
49  (m_vlan == s.m_vlan));
50 }
51 
52 std::string
53 sub_interface::mk_name(const interface& parent, vlan_id_t vlan)
54 {
55  return (parent.name() + "." + std::to_string(vlan));
56 }
57 
58 std::queue<cmd*>&
59 sub_interface::mk_create_cmd(std::queue<cmd*>& q)
60 {
61  q.push(new sub_interface_cmds::create_cmd(m_hdl, name(), m_parent->handle(),
62  m_vlan));
63 
64  return (q);
65 }
66 
67 std::queue<cmd*>&
68 sub_interface::mk_delete_cmd(std::queue<cmd*>& q)
69 {
71 
72  return (q);
73 }
74 
75 std::shared_ptr<sub_interface>
77 {
78  return std::dynamic_pointer_cast<sub_interface>(singular_i());
79 }
80 
81 std::shared_ptr<interface>
82 sub_interface::singular_i() const
83 {
84  return m_db.find_or_add(key(), *this);
85 }
86 
87 std::shared_ptr<sub_interface>
89 {
90  return std::dynamic_pointer_cast<sub_interface>(m_db.find(k));
91 }
92 
93 }; // namespace VOM
94 
95 /*
96  * fd.io coding-style-patch-verification: ON
97  *
98  * Local Variables:
99  * eval: (c-set-style "mozilla")
100  * End:
101  */
void release()
release/remove an interface form the singular store
Definition: interface.cpp:205
~sub_interface()
Destructor.
A Sub-interface.
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:439
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:150
sub_interface(const interface &parent, admin_state_t state, vlan_id_t vlan)
Construct a new object matching the desried state.
static std::shared_ptr< sub_interface > find(const key_t &k)
Find a subinterface from its key.
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface&#39;s name.
Definition: interface.hpp:471
A functor class that creates an interface.
A cmd class that Delete an interface.
The admin state of the interface.
Definition: interface.hpp:108
A representation of an interface in VPP.
Definition: interface.hpp:41
const std::string & name() const
Return the interface type.
Definition: interface.cpp:230
vhost_vring_state_t state
Definition: vhost-user.h:82
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
bool operator==(const sub_interface &s) const
comparison operator - for UT
std::string key_t
The key for interface&#39;s key.
Definition: interface.hpp:47
std::shared_ptr< sub_interface > singular() const
Return the matching &#39;singular instance&#39; of the sub-interface.
const key_t & key() const
Return the interface type.
Definition: interface.cpp:236