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_TAP_INTERFACE_H__ |
| 17 | #define __VOM_TAP_INTERFACE_H__ |
| 18 | |
| 19 | #include "vom/interface.hpp" |
| 20 | |
| 21 | namespace VOM { |
| 22 | /** |
| 23 | * A tap-interface. e.g. a tap interface |
| 24 | */ |
| 25 | class tap_interface : public interface |
| 26 | { |
| 27 | public: |
| 28 | tap_interface(const std::string& name, |
| 29 | admin_state_t state, |
| 30 | route::prefix_t prefix); |
| 31 | |
| 32 | tap_interface(const std::string& name, |
| 33 | admin_state_t state, |
| 34 | route::prefix_t prefix, |
| 35 | const l2_address_t& l2_address); |
| 36 | |
| 37 | ~tap_interface(); |
| 38 | tap_interface(const tap_interface& o); |
| 39 | |
| 40 | /** |
| 41 | * Return the matching 'singular instance' of the TAP interface |
| 42 | */ |
| 43 | std::shared_ptr<tap_interface> singular() const; |
| 44 | |
| 45 | /** |
| 46 | * A functor class that creates an interface |
| 47 | */ |
| 48 | class create_cmd : public interface::create_cmd<vapi::Tap_connect> |
| 49 | { |
| 50 | public: |
| 51 | create_cmd(HW::item<handle_t>& item, |
| 52 | const std::string& name, |
| 53 | route::prefix_t& prefix, |
| 54 | const l2_address_t& l2_address); |
| 55 | |
| 56 | /** |
| 57 | * Issue the command to VPP/HW |
| 58 | */ |
| 59 | rc_t issue(connection& con); |
| 60 | /** |
| 61 | * convert to string format for debug purposes |
| 62 | */ |
| 63 | std::string to_string() const; |
| 64 | |
| 65 | private: |
| 66 | route::prefix_t& m_prefix; |
| 67 | const l2_address_t& m_l2_address; |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * |
| 72 | */ |
| 73 | class delete_cmd : public interface::delete_cmd<vapi::Tap_delete> |
| 74 | { |
| 75 | public: |
| 76 | delete_cmd(HW::item<handle_t>& item); |
| 77 | |
| 78 | /** |
| 79 | * Issue the command to VPP/HW |
| 80 | */ |
| 81 | rc_t issue(connection& con); |
| 82 | /** |
| 83 | * convert to string format for debug purposes |
| 84 | */ |
| 85 | std::string to_string() const; |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * A cmd class that Dumps all the Vpp Interfaces |
| 90 | */ |
| 91 | class dump_cmd : public VOM::dump_cmd<vapi::Sw_interface_tap_dump> |
| 92 | { |
| 93 | public: |
| 94 | /** |
| 95 | * Default Constructor |
| 96 | */ |
| 97 | dump_cmd(); |
| 98 | |
| 99 | /** |
| 100 | * Issue the command to VPP/HW |
| 101 | */ |
| 102 | rc_t issue(connection& con); |
| 103 | /** |
| 104 | * convert to string format for debug purposes |
| 105 | */ |
| 106 | std::string to_string() const; |
| 107 | |
| 108 | /** |
| 109 | * Comparison operator - only used for UT |
| 110 | */ |
| 111 | bool operator==(const dump_cmd& i) const; |
| 112 | }; |
| 113 | |
| 114 | private: |
| 115 | /** |
| 116 | * Class definition for listeners to OM events |
| 117 | */ |
| 118 | class event_handler : public OM::listener, public inspect::command_handler |
| 119 | { |
| 120 | public: |
| 121 | event_handler(); |
| 122 | virtual ~event_handler() = default; |
| 123 | |
| 124 | /** |
| 125 | * Handle a populate event |
| 126 | */ |
| 127 | void handle_populate(const client_db::key_t& key); |
| 128 | |
| 129 | /** |
| 130 | * Handle a replay event |
| 131 | */ |
| 132 | void handle_replay(); |
| 133 | |
| 134 | /** |
| 135 | * Show the object in the Singular DB |
| 136 | */ |
| 137 | void show(std::ostream& os); |
| 138 | |
| 139 | /** |
| 140 | * Get the sortable Id of the listener |
| 141 | */ |
| 142 | dependency_t order() const; |
| 143 | }; |
| 144 | static event_handler m_evh; |
| 145 | |
| 146 | /** |
| 147 | * Construct with a handle |
| 148 | */ |
| 149 | tap_interface(const handle_t& hdl, |
| 150 | const std::string& name, |
| 151 | admin_state_t state, |
| 152 | route::prefix_t prefix); |
| 153 | |
| 154 | /** |
| 155 | * Ip Prefix |
| 156 | */ |
| 157 | route::prefix_t m_prefix; |
| 158 | |
| 159 | l2_address_t m_l2_address; |
| 160 | |
| 161 | /** |
| 162 | * interface is a friend so it can construct with handles |
| 163 | */ |
| 164 | friend class interface; |
| 165 | |
| 166 | /** |
| 167 | * Return the matching 'instance' of the sub-interface |
| 168 | * over-ride from the base class |
| 169 | */ |
| 170 | std::shared_ptr<interface> singular_i() const; |
| 171 | |
| 172 | /** |
| 173 | * Virtual functions to construct an interface create commands. |
| 174 | */ |
| 175 | virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds); |
| 176 | |
| 177 | /** |
| 178 | * Virtual functions to construct an interface delete commands. |
| 179 | */ |
| 180 | virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds); |
| 181 | |
| 182 | /* |
| 183 | * It's the OM class that call singular() |
| 184 | */ |
| 185 | friend class OM; |
| 186 | }; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * fd.io coding-style-patch-verification: ON |
| 191 | * |
| 192 | * Local Variables: |
| 193 | * eval: (c-set-style "mozilla") |
| 194 | * End: |
| 195 | */ |
| 196 | |
| 197 | #endif |