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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/tap_interface.hpp"
17 #include "vom/cmd.hpp"
19 #include <vapi/vpe.api.vapi.hpp>
22 tap_interface::event_handler tap_interface::m_evh;
25 * Construct a new object matching the desried state
27 tap_interface::tap_interface(const std::string& name,
29 route::prefix_t prefix)
30 : interface(name, type_t::TAP, state)
32 , m_l2_address(l2_address_t::ZERO)
36 tap_interface::tap_interface(const std::string& name,
38 route::prefix_t prefix,
39 const l2_address_t& l2_address)
40 : interface(name, type_t::TAP, state)
42 , m_l2_address(l2_address)
46 tap_interface::tap_interface(const handle_t& hdl,
47 const std::string& name,
49 route::prefix_t prefix)
50 : interface(hdl, l2_address_t::ZERO, name, type_t::TAP, state)
52 , m_l2_address(l2_address_t::ZERO)
56 tap_interface::~tap_interface()
62 tap_interface::tap_interface(const tap_interface& o)
64 , m_prefix(o.m_prefix)
65 , m_l2_address(o.m_l2_address)
70 tap_interface::mk_create_cmd(std::queue<cmd*>& q)
72 q.push(new create_cmd(m_hdl, name(), m_prefix, m_l2_address));
78 tap_interface::mk_delete_cmd(std::queue<cmd*>& q)
80 q.push(new delete_cmd(m_hdl));
85 std::shared_ptr<tap_interface>
86 tap_interface::singular() const
88 return std::dynamic_pointer_cast<tap_interface>(singular_i());
91 std::shared_ptr<interface>
92 tap_interface::singular_i() const
94 return m_db.find_or_add(name(), *this);
98 tap_interface::event_handler::handle_populate(const client_db::key_t& key)
101 * dump VPP current states
103 std::shared_ptr<tap_interface::dump_cmd> cmd(new tap_interface::dump_cmd());
108 for (auto& record : *cmd) {
109 auto& payload = record.get_payload();
111 std::string name = reinterpret_cast<const char*>(payload.dev_name);
113 tap_interface itf(name, interface::admin_state_t::UP,
114 route::prefix_t::ZERO);
116 VOM_LOG(log_level_t::DEBUG) << "tap-dump: " << itf.to_string();
119 * Write each of the discovered interfaces into the OM,
120 * but disable the HW Command q whilst we do, so that no
121 * commands are sent to VPP
123 OM::commit(key, itf);
127 tap_interface::event_handler::event_handler()
129 OM::register_listener(this);
130 inspect::register_handler({ "tap" }, "tap_interfaces", this);
134 tap_interface::event_handler::handle_replay()
140 tap_interface::event_handler::order() const
142 return (dependency_t::INTERFACE);
146 tap_interface::event_handler::show(std::ostream& os)
153 * fd.io coding-style-patch-verification: ON
156 * eval: (c-set-style "mozilla")