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/tap_interface.hpp" |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 17 | #include "vom/tap_interface_cmds.hpp" |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 18 | |
| 19 | #include <vapi/vpe.api.vapi.hpp> |
| 20 | |
| 21 | namespace VOM { |
| 22 | tap_interface::event_handler tap_interface::m_evh; |
| 23 | |
| 24 | /** |
| 25 | * Construct a new object matching the desried state |
| 26 | */ |
| 27 | tap_interface::tap_interface(const std::string& name, |
Neale Ranns | 8e1cc46 | 2018-11-28 09:51:40 -0800 | [diff] [blame] | 28 | const admin_state_t& state, |
| 29 | const route::prefix_t& prefix) |
| 30 | : interface(name, type_t::TAPV2, state) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 31 | , m_prefix(prefix) |
| 32 | , m_l2_address(l2_address_t::ZERO) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | tap_interface::tap_interface(const std::string& name, |
Neale Ranns | 8e1cc46 | 2018-11-28 09:51:40 -0800 | [diff] [blame] | 37 | const admin_state_t& state, |
| 38 | const route::prefix_t& prefix, |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 39 | const l2_address_t& l2_address) |
Neale Ranns | 8e1cc46 | 2018-11-28 09:51:40 -0800 | [diff] [blame] | 40 | : interface(name, type_t::TAPV2, state) |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 41 | , m_prefix(prefix) |
| 42 | , m_l2_address(l2_address) |
| 43 | { |
| 44 | } |
| 45 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 46 | tap_interface::~tap_interface() |
| 47 | { |
| 48 | sweep(); |
| 49 | release(); |
| 50 | } |
| 51 | |
| 52 | tap_interface::tap_interface(const tap_interface& o) |
| 53 | : interface(o) |
| 54 | , m_prefix(o.m_prefix) |
| 55 | , m_l2_address(o.m_l2_address) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | std::queue<cmd*>& |
| 60 | tap_interface::mk_create_cmd(std::queue<cmd*>& q) |
| 61 | { |
Neale Ranns | 8e1cc46 | 2018-11-28 09:51:40 -0800 | [diff] [blame] | 62 | q.push(new tap_interface_cmds::tapv2_create_cmd(m_hdl, name(), m_prefix, |
Mohsin Kazmi | 9aca7b5 | 2018-07-04 15:17:01 +0200 | [diff] [blame] | 63 | m_l2_address)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 64 | |
| 65 | return (q); |
| 66 | } |
| 67 | |
| 68 | std::queue<cmd*>& |
| 69 | tap_interface::mk_delete_cmd(std::queue<cmd*>& q) |
| 70 | { |
Neale Ranns | 8e1cc46 | 2018-11-28 09:51:40 -0800 | [diff] [blame] | 71 | q.push(new tap_interface_cmds::tapv2_delete_cmd(m_hdl)); |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 72 | |
| 73 | return (q); |
| 74 | } |
| 75 | |
| 76 | std::shared_ptr<tap_interface> |
| 77 | tap_interface::singular() const |
| 78 | { |
| 79 | return std::dynamic_pointer_cast<tap_interface>(singular_i()); |
| 80 | } |
| 81 | |
| 82 | std::shared_ptr<interface> |
| 83 | tap_interface::singular_i() const |
| 84 | { |
| 85 | return m_db.find_or_add(name(), *this); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | tap_interface::event_handler::handle_populate(const client_db::key_t& key) |
| 90 | { |
Mohsin Kazmi | 9aca7b5 | 2018-07-04 15:17:01 +0200 | [diff] [blame] | 91 | // It will be polulate by interface handler |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | tap_interface::event_handler::event_handler() |
| 95 | { |
| 96 | OM::register_listener(this); |
| 97 | inspect::register_handler({ "tap" }, "tap_interfaces", this); |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | tap_interface::event_handler::handle_replay() |
| 102 | { |
Mohsin Kazmi | 18e955e | 2018-01-08 12:58:32 +0100 | [diff] [blame] | 103 | // It will be replayed by interface handler |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | dependency_t |
| 107 | tap_interface::event_handler::order() const |
| 108 | { |
| 109 | return (dependency_t::INTERFACE); |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | tap_interface::event_handler::show(std::ostream& os) |
| 114 | { |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 115 | // dumped by the interface handler |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 116 | } |
Neale Ranns | fd92060 | 2017-11-23 12:15:00 -0800 | [diff] [blame] | 117 | |
| 118 | }; // namespace VOM |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * fd.io coding-style-patch-verification: ON |
| 122 | * |
| 123 | * Local Variables: |
| 124 | * eval: (c-set-style "mozilla") |
| 125 | * End: |
| 126 | */ |