FD.io VPP  v21.06-3-gbb25fbf28
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 
32 /**
33  * Construct a new object matching the desried state
34  */
37  const route_domain& rd,
38  vlan_id_t vlan)
39  : interface(mk_name(parent, vlan), parent.type(), state, rd)
40  , m_parent(parent.singular())
41  , m_vlan(vlan)
42 {
43 }
44 
46 {
47  sweep();
48  release();
49 }
50 
52  : interface(o)
53  , m_parent(o.m_parent)
54  , m_vlan(o.m_vlan)
55 {
56 }
57 
58 bool
60 {
61  return (interface::operator==(s) && (m_parent->key() == s.m_parent->key()) &&
62  (m_vlan == s.m_vlan));
63 }
64 
66 sub_interface::mk_name(const interface& parent, vlan_id_t vlan)
67 {
68  return (parent.name() + "." + std::to_string(vlan));
69 }
70 
71 std::queue<cmd*>&
72 sub_interface::mk_create_cmd(std::queue<cmd*>& q)
73 {
74  q.push(new sub_interface_cmds::create_cmd(m_hdl, name(), m_parent->handle(),
75  m_vlan));
76 
77  return (q);
78 }
79 
80 std::queue<cmd*>&
81 sub_interface::mk_delete_cmd(std::queue<cmd*>& q)
82 {
83  q.push(new sub_interface_cmds::delete_cmd(m_hdl));
84 
85  return (q);
86 }
87 
88 std::shared_ptr<sub_interface>
90 {
91  return std::dynamic_pointer_cast<sub_interface>(singular_i());
92 }
93 
94 std::shared_ptr<interface>
95 sub_interface::singular_i() const
96 {
97  return m_db.find_or_add(key(), *this);
98 }
99 
100 std::shared_ptr<sub_interface>
102 {
103  return std::dynamic_pointer_cast<sub_interface>(m_db.find(k));
104 }
105 
106 }; // namespace VOM
107 
108 /*
109  * fd.io coding-style-patch-verification: OFF
110  *
111  * Local Variables:
112  * eval: (c-set-style "mozilla")
113  * End:
114  */
VOM::sub_interface::operator==
bool operator==(const sub_interface &s) const
comparison operator - for UT
Definition: sub_interface.cpp:59
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::interface::m_db
static singular_db< key_t, interface > m_db
A map of all interfaces key against the interface's name.
Definition: interface.hpp:572
VOM::interface::m_hdl
HW::item< handle_t > m_hdl
The SW interface handle VPP has asigned to the interface.
Definition: interface.hpp:540
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
VOM::sub_interface::singular
std::shared_ptr< sub_interface > singular() const
Return the matching 'singular instance' of the sub-interface.
Definition: sub_interface.cpp:89
VOM::interface::name
const std::string & name() const
Return the interface type.
Definition: interface.cpp:271
sub_interface_cmds.hpp
sub_interface.hpp
VOM::interface::key
const key_t & key() const
Return the interface type.
Definition: interface.cpp:277
VOM::interface::sweep
virtual void sweep(void)
Sweep/reap the object if still stale.
Definition: interface.cpp:182
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::sub_interface::~sub_interface
~sub_interface()
Destructor.
Definition: sub_interface.cpp:45
VOM::sub_interface::sub_interface
sub_interface(const interface &parent, admin_state_t state, vlan_id_t vlan)
Construct a new object matching the desried state.
Definition: sub_interface.cpp:23
VOM::interface::admin_state_t
The admin state of the interface.
Definition: interface.hpp:138
VOM::route_domain
A route-domain is a VRF.
Definition: route_domain.hpp:31
VOM::sub_interface::find
static std::shared_ptr< sub_interface > find(const key_t &k)
Find a subinterface from its key.
Definition: sub_interface.cpp:101
VOM::interface::key_t
std::string key_t
The key for interface's key.
Definition: interface.hpp:56
VOM::interface::release
void release()
release/remove an interface form the singular store
Definition: interface.cpp:240
VOM::sub_interface
A Sub-interface.
Definition: sub_interface.hpp:25
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
string
const char *const string
Definition: cJSON.h:172