blob: 94baa3d2eccc2bd22505d9f1aa02d255c02cb3ec [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/sub_interface_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19namespace VOM {
20/**
21 * Construct a new object matching the desried state
22 */
23sub_interface::sub_interface(const interface& parent,
24 admin_state_t state,
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
Neale Ranns812ed392017-10-16 04:20:13 -070032sub_interface::~sub_interface()
33{
34 sweep();
35 release();
36}
37
38sub_interface::sub_interface(const sub_interface& o)
39 : interface(o)
40 , m_parent(o.m_parent)
41 , m_vlan(o.m_vlan)
42{
43}
44
Neale Rannsfd920602017-11-23 12:15:00 -080045bool
46sub_interface::operator==(const sub_interface& s) const
47{
48 return (interface::operator==(s) && (m_parent->key() == s.m_parent->key()) &&
49 (m_vlan == s.m_vlan));
50}
51
Neale Ranns812ed392017-10-16 04:20:13 -070052std::string
53sub_interface::mk_name(const interface& parent, vlan_id_t vlan)
54{
55 return (parent.name() + "." + std::to_string(vlan));
56}
57
58std::queue<cmd*>&
59sub_interface::mk_create_cmd(std::queue<cmd*>& q)
60{
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070061 q.push(new sub_interface_cmds::create_cmd(m_hdl, name(), m_parent->handle(),
62 m_vlan));
Neale Ranns812ed392017-10-16 04:20:13 -070063
64 return (q);
65}
66
67std::queue<cmd*>&
68sub_interface::mk_delete_cmd(std::queue<cmd*>& q)
69{
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070070 q.push(new sub_interface_cmds::delete_cmd(m_hdl));
Neale Ranns812ed392017-10-16 04:20:13 -070071
72 return (q);
73}
74
75std::shared_ptr<sub_interface>
76sub_interface::singular() const
77{
78 return std::dynamic_pointer_cast<sub_interface>(singular_i());
79}
80
81std::shared_ptr<interface>
82sub_interface::singular_i() const
83{
Neale Rannsfd920602017-11-23 12:15:00 -080084 return m_db.find_or_add(key(), *this);
Neale Ranns812ed392017-10-16 04:20:13 -070085}
Neale Rannsfd920602017-11-23 12:15:00 -080086
87std::shared_ptr<sub_interface>
88sub_interface::find(const key_t& k)
89{
90 return std::dynamic_pointer_cast<sub_interface>(m_db.find(k));
Neale Ranns812ed392017-10-16 04:20:13 -070091}
92
Neale Rannsfd920602017-11-23 12:15:00 -080093}; // namespace VOM
94
Neale Ranns812ed392017-10-16 04:20:13 -070095/*
96 * fd.io coding-style-patch-verification: ON
97 *
98 * Local Variables:
99 * eval: (c-set-style "mozilla")
100 * End:
101 */