blob: ca4ccf3c38a6683c7c2605533b2b9f2e13d50026 [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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#include "vom/vxlan_tunnel_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017
18DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON;
19
20namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070021namespace vxlan_tunnel_cmds {
22
23create_cmd::create_cmd(HW::item<handle_t>& item,
24 const std::string& name,
25 const vxlan_tunnel::endpoint_t& ep)
Neale Ranns812ed392017-10-16 04:20:13 -070026 : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
27 , m_ep(ep)
28{
29}
30
31bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070032create_cmd::operator==(const create_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070033{
34 return (m_ep == other.m_ep);
35}
36
37rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070038create_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070039{
40 msg_t req(con.ctx(), std::ref(*this));
41
42 auto& payload = req.get_request().get_payload();
43 payload.is_add = 1;
44 payload.is_ipv6 = 0;
45 to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
46 to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
47 payload.mcast_sw_if_index = ~0;
48 payload.encap_vrf_id = 0;
49 payload.decap_next_index = ~0;
50 payload.vni = m_ep.vni;
51
52 VAPI_CALL(req.execute());
53
54 m_hw_item = wait();
55
56 if (m_hw_item) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070057 insert_interface();
Neale Ranns812ed392017-10-16 04:20:13 -070058 }
59
60 return rc_t::OK;
61}
62
63std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070064create_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070065{
66 std::ostringstream s;
67 s << "vxlan-tunnel-create: " << m_hw_item.to_string() << m_ep.to_string();
68
69 return (s.str());
70}
71
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070072delete_cmd::delete_cmd(HW::item<handle_t>& item,
73 const vxlan_tunnel::endpoint_t& ep)
Neale Ranns812ed392017-10-16 04:20:13 -070074 : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
75 , m_ep(ep)
76{
77}
78
79bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070080delete_cmd::operator==(const delete_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070081{
82 return (m_ep == other.m_ep);
83}
84
85rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070086delete_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070087{
88 msg_t req(con.ctx(), std::ref(*this));
89
90 auto payload = req.get_request().get_payload();
91 payload.is_add = 0;
92 payload.is_ipv6 = 0;
93 to_bytes(m_ep.src, &payload.is_ipv6, payload.src_address);
94 to_bytes(m_ep.dst, &payload.is_ipv6, payload.dst_address);
95 payload.mcast_sw_if_index = ~0;
96 payload.encap_vrf_id = 0;
97 payload.decap_next_index = ~0;
98 payload.vni = m_ep.vni;
99
100 VAPI_CALL(req.execute());
101
102 wait();
103 m_hw_item.set(rc_t::NOOP);
104
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700105 remove_interface();
Neale Ranns812ed392017-10-16 04:20:13 -0700106 return (rc_t::OK);
107}
108
109std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700110delete_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700111{
112 std::ostringstream s;
113 s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
114
115 return (s.str());
116}
117
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700118dump_cmd::dump_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -0700119{
120}
121
122bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700123dump_cmd::operator==(const dump_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700124{
125 return (true);
126}
127
128rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700129dump_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700130{
131 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
132
133 auto& payload = m_dump->get_request().get_payload();
134 payload.sw_if_index = ~0;
135
136 VAPI_CALL(m_dump->execute());
137
138 wait();
139
140 return rc_t::OK;
141}
142
143std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700144dump_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700145{
146 return ("Vpp-vxlan_tunnels-Dump");
147}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700148} // namespace vxlan_tunnel_cmds
149} // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700150
151/*
152 * fd.io coding-style-patch-verification: ON
153 *
154 * Local Variables:
155 * eval: (c-set-style "mozilla")
156 * End:
157 */