Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 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" |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 17 | #include "vom/sub_interface_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 18 | |
| 19 | namespace VOM { |
| 20 | /** |
| 21 | * Construct a new object matching the desried state |
| 22 | */ |
| 23 | sub_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 | |
| 32 | sub_interface::sub_interface(const handle_t& handle, |
| 33 | const interface& parent, |
| 34 | admin_state_t state, |
| 35 | vlan_id_t vlan) |
| 36 | : interface(handle, |
| 37 | l2_address_t::ZERO, |
| 38 | mk_name(parent, vlan), |
| 39 | parent.type(), |
| 40 | state) |
| 41 | , m_parent(parent.singular()) |
| 42 | , m_vlan(vlan) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | sub_interface::~sub_interface() |
| 47 | { |
| 48 | sweep(); |
| 49 | release(); |
| 50 | } |
| 51 | |
| 52 | sub_interface::sub_interface(const sub_interface& o) |
| 53 | : interface(o) |
| 54 | , m_parent(o.m_parent) |
| 55 | , m_vlan(o.m_vlan) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | std::string |
| 60 | sub_interface::mk_name(const interface& parent, vlan_id_t vlan) |
| 61 | { |
| 62 | return (parent.name() + "." + std::to_string(vlan)); |
| 63 | } |
| 64 | |
| 65 | std::queue<cmd*>& |
| 66 | sub_interface::mk_create_cmd(std::queue<cmd*>& q) |
| 67 | { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 68 | q.push(new sub_interface_cmds::create_cmd(m_hdl, name(), m_parent->handle(), |
| 69 | m_vlan)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 70 | |
| 71 | return (q); |
| 72 | } |
| 73 | |
| 74 | std::queue<cmd*>& |
| 75 | sub_interface::mk_delete_cmd(std::queue<cmd*>& q) |
| 76 | { |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 77 | q.push(new sub_interface_cmds::delete_cmd(m_hdl)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 78 | |
| 79 | return (q); |
| 80 | } |
| 81 | |
| 82 | std::shared_ptr<sub_interface> |
| 83 | sub_interface::singular() const |
| 84 | { |
| 85 | return std::dynamic_pointer_cast<sub_interface>(singular_i()); |
| 86 | } |
| 87 | |
| 88 | std::shared_ptr<interface> |
| 89 | sub_interface::singular_i() const |
| 90 | { |
| 91 | return m_db.find_or_add(name(), *this); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * fd.io coding-style-patch-verification: ON |
| 97 | * |
| 98 | * Local Variables: |
| 99 | * eval: (c-set-style "mozilla") |
| 100 | * End: |
| 101 | */ |