blob: d7f16f5c1325170e25a396daeafcaa6ab806a1c0 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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 Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/tap_interface_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018
19#include <vapi/vpe.api.vapi.hpp>
20
21namespace VOM {
22tap_interface::event_handler tap_interface::m_evh;
23
24/**
25 * Construct a new object matching the desried state
26 */
27tap_interface::tap_interface(const std::string& name,
28 admin_state_t state,
29 route::prefix_t prefix)
30 : interface(name, type_t::TAP, state)
31 , m_prefix(prefix)
32 , m_l2_address(l2_address_t::ZERO)
33{
34}
35
36tap_interface::tap_interface(const std::string& name,
37 admin_state_t state,
38 route::prefix_t prefix,
39 const l2_address_t& l2_address)
40 : interface(name, type_t::TAP, state)
41 , m_prefix(prefix)
42 , m_l2_address(l2_address)
43{
44}
45
Neale Ranns812ed392017-10-16 04:20:13 -070046tap_interface::~tap_interface()
47{
48 sweep();
49 release();
50}
51
52tap_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
59std::queue<cmd*>&
60tap_interface::mk_create_cmd(std::queue<cmd*>& q)
61{
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070062 q.push(
63 new tap_interface_cmds::create_cmd(m_hdl, name(), m_prefix, m_l2_address));
Neale Ranns812ed392017-10-16 04:20:13 -070064
65 return (q);
66}
67
68std::queue<cmd*>&
69tap_interface::mk_delete_cmd(std::queue<cmd*>& q)
70{
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070071 q.push(new tap_interface_cmds::delete_cmd(m_hdl));
Neale Ranns812ed392017-10-16 04:20:13 -070072
73 return (q);
74}
75
76std::shared_ptr<tap_interface>
77tap_interface::singular() const
78{
79 return std::dynamic_pointer_cast<tap_interface>(singular_i());
80}
81
82std::shared_ptr<interface>
83tap_interface::singular_i() const
84{
85 return m_db.find_or_add(name(), *this);
86}
87
88void
89tap_interface::event_handler::handle_populate(const client_db::key_t& key)
90{
91 /*
Neale Rannsfd920602017-11-23 12:15:00 -080092 * dump VPP current states
93 */
Neale Ranns1d781552017-11-27 04:52:35 -080094 std::shared_ptr<tap_interface_cmds::dump_cmd> cmd =
95 std::make_shared<tap_interface_cmds::dump_cmd>();
Neale Ranns812ed392017-10-16 04:20:13 -070096
97 HW::enqueue(cmd);
98 HW::write();
99
100 for (auto& record : *cmd) {
101 auto& payload = record.get_payload();
102
103 std::string name = reinterpret_cast<const char*>(payload.dev_name);
104
105 tap_interface itf(name, interface::admin_state_t::UP,
106 route::prefix_t::ZERO);
107
108 VOM_LOG(log_level_t::DEBUG) << "tap-dump: " << itf.to_string();
109
110 /*
Neale Rannsfd920602017-11-23 12:15:00 -0800111 * Write each of the discovered interfaces into the OM,
112 * but disable the HW Command q whilst we do, so that no
113 * commands are sent to VPP
114 */
Neale Ranns812ed392017-10-16 04:20:13 -0700115 OM::commit(key, itf);
116 }
117}
118
119tap_interface::event_handler::event_handler()
120{
121 OM::register_listener(this);
122 inspect::register_handler({ "tap" }, "tap_interfaces", this);
123}
124
125void
126tap_interface::event_handler::handle_replay()
127{
Mohsin Kazmi18e955e2018-01-08 12:58:32 +0100128 // It will be replayed by interface handler
Neale Ranns812ed392017-10-16 04:20:13 -0700129}
130
131dependency_t
132tap_interface::event_handler::order() const
133{
134 return (dependency_t::INTERFACE);
135}
136
137void
138tap_interface::event_handler::show(std::ostream& os)
139{
Neale Rannsfd920602017-11-23 12:15:00 -0800140 // dumped by the interface handler
Neale Ranns812ed392017-10-16 04:20:13 -0700141}
Neale Rannsfd920602017-11-23 12:15:00 -0800142
143}; // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700144
145/*
146 * fd.io coding-style-patch-verification: ON
147 *
148 * Local Variables:
149 * eval: (c-set-style "mozilla")
150 * End:
151 */