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 | #ifndef __VOM_SUB_INTERFACE_H__ |
| 17 | #define __VOM_SUB_INTERFACE_H__ |
| 18 | |
| 19 | #include "vom/interface.hpp" |
| 20 | |
| 21 | namespace VOM { |
| 22 | /** |
| 23 | * A Sub-interface. e.g. a VLAN sub-interface on an Ethernet interface |
| 24 | */ |
| 25 | class sub_interface : public interface |
| 26 | { |
| 27 | /* |
| 28 | * Typedef for VLAN ID |
| 29 | */ |
| 30 | typedef uint16_t vlan_id_t; |
| 31 | |
| 32 | public: |
| 33 | /** |
| 34 | * Construct a new object matching the desried state |
| 35 | */ |
| 36 | sub_interface(const interface& parent, admin_state_t state, vlan_id_t vlan); |
| 37 | /** |
| 38 | * Destructor |
| 39 | */ |
| 40 | ~sub_interface(); |
| 41 | /** |
| 42 | * Copy Constructor |
| 43 | */ |
| 44 | sub_interface(const sub_interface& o); |
| 45 | |
| 46 | /** |
| 47 | * Return the matching 'singular instance' of the sub-interface |
| 48 | */ |
| 49 | std::shared_ptr<sub_interface> singular() const; |
| 50 | |
| 51 | /** |
| 52 | * A functor class that creates an interface |
| 53 | */ |
| 54 | class create_cmd : public interface::create_cmd<vapi::Create_vlan_subif> |
| 55 | { |
| 56 | public: |
| 57 | /** |
| 58 | * Cstrunctor taking the reference to the parent |
| 59 | * and the sub-interface's VLAN |
| 60 | */ |
| 61 | create_cmd(HW::item<handle_t>& item, |
| 62 | const std::string& name, |
| 63 | const handle_t& parent, |
| 64 | uint16_t vlan); |
| 65 | |
| 66 | /** |
| 67 | * Issue the command to VPP/HW |
| 68 | */ |
| 69 | rc_t issue(connection& con); |
| 70 | |
| 71 | /** |
| 72 | * convert to string format for debug purposes |
| 73 | */ |
| 74 | std::string to_string() const; |
| 75 | |
| 76 | /** |
| 77 | * Comparison operator - only used for UT |
| 78 | */ |
| 79 | bool operator==(const create_cmd& i) const; |
| 80 | |
| 81 | private: |
| 82 | /** |
| 83 | * Refernece to the parents handle |
| 84 | */ |
| 85 | const handle_t& m_parent; |
| 86 | |
| 87 | /** |
| 88 | * The VLAN of the sub-interface |
| 89 | */ |
| 90 | uint16_t m_vlan; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * A cmd class that Delete an interface |
| 95 | */ |
| 96 | class delete_cmd : public interface::delete_cmd<vapi::Delete_subif> |
| 97 | { |
| 98 | public: |
| 99 | /** |
| 100 | * Constructor |
| 101 | */ |
| 102 | delete_cmd(HW::item<handle_t>& item); |
| 103 | |
| 104 | /** |
| 105 | * Issue the command to VPP/HW |
| 106 | */ |
| 107 | rc_t issue(connection& con); |
| 108 | |
| 109 | /** |
| 110 | * convert to string format for debug purposes |
| 111 | */ |
| 112 | std::string to_string() const; |
| 113 | |
| 114 | /** |
| 115 | * Comparison operator - only used for UT |
| 116 | */ |
| 117 | bool operator==(const delete_cmd& i) const; |
| 118 | }; |
| 119 | |
| 120 | private: |
| 121 | /** |
| 122 | * Construct with handle |
| 123 | */ |
| 124 | sub_interface(const handle_t& handle, |
| 125 | const interface& parent, |
| 126 | admin_state_t state, |
| 127 | vlan_id_t vlan); |
| 128 | /** |
| 129 | * The interface class can construct interfaces with handles |
| 130 | */ |
| 131 | friend class interface; |
| 132 | |
| 133 | /** |
| 134 | * Return the matching 'instance' of the sub-interface |
| 135 | * over-ride from the base class |
| 136 | */ |
| 137 | std::shared_ptr<interface> singular_i() const; |
| 138 | |
| 139 | /** |
| 140 | * Virtual functions to construct an interface create commands. |
| 141 | */ |
| 142 | virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds); |
| 143 | |
| 144 | /** |
| 145 | * Virtual functions to construct an interface delete commands. |
| 146 | */ |
| 147 | virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds); |
| 148 | |
| 149 | /** |
| 150 | * From the name of the parent and the vlan, |
| 151 | * construct the sub-interface's name |
| 152 | */ |
| 153 | static std::string mk_name(const interface& parent, vlan_id_t vlan); |
| 154 | |
| 155 | /** |
| 156 | * Refernece conter lock on the parent |
| 157 | */ |
| 158 | const std::shared_ptr<interface> m_parent; |
| 159 | |
| 160 | /** |
| 161 | * VLAN ID |
| 162 | */ |
| 163 | vlan_id_t m_vlan; |
| 164 | }; |
| 165 | }; |
| 166 | |
| 167 | /* |
| 168 | * fd.io coding-style-patch-verification: ON |
| 169 | * |
| 170 | * Local Variables: |
| 171 | * eval: (c-set-style "mozilla") |
| 172 | * End: |
| 173 | */ |
| 174 | |
| 175 | #endif |