vxlan: vxlan/vxlan.api API cleanup
[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                        handle_t mcast_itf)
27   : interface::create_cmd<vapi::Vxlan_add_del_tunnel>(item, name)
28   , m_ep(ep)
29   , m_mcast_itf(mcast_itf)
30 {}
31
32 bool
33 create_cmd::operator==(const create_cmd& other) const
34 {
35   return (m_ep == other.m_ep);
36 }
37
38 rc_t
39 create_cmd::issue(connection& con)
40 {
41   msg_t req(con.ctx(), std::ref(*this));
42
43   auto& payload = req.get_request().get_payload();
44   payload.is_add = 1;
45   to_bytes(m_ep.src,
46            (uint8_t*)&payload.src_address.af,
47            (uint8_t*)&payload.src_address.un);
48   to_bytes(m_ep.dst,
49            (uint8_t*)&payload.dst_address.af,
50            (uint8_t*)&payload.dst_address.un);
51   payload.mcast_sw_if_index = m_mcast_itf.value();
52   payload.encap_vrf_id = 0;
53   payload.decap_next_index = ~0;
54   payload.vni = m_ep.vni;
55
56   VAPI_CALL(req.execute());
57
58   wait();
59
60   if (rc_t::OK == m_hw_item.rc()) {
61     insert_interface();
62   }
63
64   return rc_t::OK;
65 }
66
67 std::string
68 create_cmd::to_string() const
69 {
70   std::ostringstream s;
71   s << "vxlan-tunnel-create: " << m_hw_item.to_string() << " "
72     << m_ep.to_string();
73
74   return (s.str());
75 }
76
77 delete_cmd::delete_cmd(HW::item<handle_t>& item,
78                        const vxlan_tunnel::endpoint_t& ep)
79   : interface::delete_cmd<vapi::Vxlan_add_del_tunnel>(item)
80   , m_ep(ep)
81 {}
82
83 bool
84 delete_cmd::operator==(const delete_cmd& other) const
85 {
86   return (m_ep == other.m_ep);
87 }
88
89 rc_t
90 delete_cmd::issue(connection& con)
91 {
92   msg_t req(con.ctx(), std::ref(*this));
93
94   auto payload = req.get_request().get_payload();
95   payload.is_add = 0;
96   to_bytes(m_ep.src,
97            (uint8_t*)&payload.src_address.af,
98            (uint8_t*)&payload.src_address.un);
99   to_bytes(m_ep.dst,
100            (uint8_t*)&payload.dst_address.af,
101            (uint8_t*)&payload.dst_address.un);
102   payload.mcast_sw_if_index = ~0;
103   payload.encap_vrf_id = 0;
104   payload.decap_next_index = ~0;
105   payload.vni = m_ep.vni;
106
107   VAPI_CALL(req.execute());
108
109   wait();
110   m_hw_item.set(rc_t::NOOP);
111
112   remove_interface();
113   return (rc_t::OK);
114 }
115
116 std::string
117 delete_cmd::to_string() const
118 {
119   std::ostringstream s;
120   s << "vxlan-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
121
122   return (s.str());
123 }
124
125 dump_cmd::dump_cmd() {}
126
127 bool
128 dump_cmd::operator==(const dump_cmd& other) const
129 {
130   return (true);
131 }
132
133 rc_t
134 dump_cmd::issue(connection& con)
135 {
136   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
137
138   auto& payload = m_dump->get_request().get_payload();
139   payload.sw_if_index = ~0;
140
141   VAPI_CALL(m_dump->execute());
142
143   wait();
144
145   return rc_t::OK;
146 }
147
148 std::string
149 dump_cmd::to_string() const
150 {
151   return ("Vpp-vxlan_tunnels-Dump");
152 }
153 } // namespace vxlan_tunnel_cmds
154 } // namespace VOM
155
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "mozilla")
161  * End:
162  */