Move VOM to extras/vom
[vpp.git] / extras / vom / vom / vxlan_tunnel_cmds.cpp
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/vxlan_tunnel_cmds.hpp"
17
18 DEFINE_VAPI_MSG_IDS_VXLAN_API_JSON;
19
20 namespace VOM {
21 namespace vxlan_tunnel_cmds {
22
23 create_cmd::create_cmd(HW::item<handle_t>& item,
24                        const std::string& name,
25                        const vxlan_tunnel::endpoint_t& ep)
26   : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
27   , m_ep(ep)
28 {
29 }
30
31 bool
32 create_cmd::operator==(const create_cmd& other) const
33 {
34   return (m_ep == other.m_ep);
35 }
36
37 rc_t
38 create_cmd::issue(connection& con)
39 {
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) {
57     insert_interface();
58   }
59
60   return rc_t::OK;
61 }
62
63 std::string
64 create_cmd::to_string() const
65 {
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
72 delete_cmd::delete_cmd(HW::item<handle_t>& item,
73                        const vxlan_tunnel::endpoint_t& ep)
74   : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
75   , m_ep(ep)
76 {
77 }
78
79 bool
80 delete_cmd::operator==(const delete_cmd& other) const
81 {
82   return (m_ep == other.m_ep);
83 }
84
85 rc_t
86 delete_cmd::issue(connection& con)
87 {
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
105   remove_interface();
106   return (rc_t::OK);
107 }
108
109 std::string
110 delete_cmd::to_string() const
111 {
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
118 dump_cmd::dump_cmd()
119 {
120 }
121
122 bool
123 dump_cmd::operator==(const dump_cmd& other) const
124 {
125   return (true);
126 }
127
128 rc_t
129 dump_cmd::issue(connection& con)
130 {
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
143 std::string
144 dump_cmd::to_string() const
145 {
146   return ("Vpp-vxlan_tunnels-Dump");
147 }
148 } // namespace vxlan_tunnel_cmds
149 } // namespace VOM
150
151 /*
152  * fd.io coding-style-patch-verification: ON
153  *
154  * Local Variables:
155  * eval: (c-set-style "mozilla")
156  * End:
157  */