VOM: vxlan-gbp
[vpp.git] / extras / vom / vom / vxlan_gbp_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_gbp_tunnel_cmds.hpp"
17 #include "vom/api_types.hpp"
18
19 DEFINE_VAPI_MSG_IDS_VXLAN_GBP_API_JSON;
20
21 namespace VOM {
22 namespace vxlan_gbp_tunnel_cmds {
23
24 create_cmd::create_cmd(HW::item<handle_t>& item,
25                        const std::string& name,
26                        const vxlan_tunnel::endpoint_t& ep)
27   : interface::create_cmd<vapi::Vxlan_gbp_tunnel_add_del>(item, name)
28   , m_ep(ep)
29 {
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
45   payload.is_add = 1;
46
47   to_api(m_ep.src, payload.tunnel.src);
48   to_api(m_ep.src, payload.tunnel.dst);
49   payload.tunnel.mcast_sw_if_index = ~0;
50   payload.tunnel.encap_table_id = 0;
51   payload.tunnel.vni = m_ep.vni;
52
53   VAPI_CALL(req.execute());
54
55   wait();
56
57   if (rc_t::OK == m_hw_item.rc()) {
58     insert_interface();
59   }
60
61   return rc_t::OK;
62 }
63
64 std::string
65 create_cmd::to_string() const
66 {
67   std::ostringstream s;
68   s << "vxlan-gbp-tunnel-create: " << m_hw_item.to_string() << m_ep.to_string();
69
70   return (s.str());
71 }
72
73 delete_cmd::delete_cmd(HW::item<handle_t>& item,
74                        const vxlan_tunnel::endpoint_t& ep)
75   : interface::delete_cmd<vapi::Vxlan_gbp_tunnel_add_del>(item)
76   , m_ep(ep)
77 {
78 }
79
80 bool
81 delete_cmd::operator==(const delete_cmd& other) const
82 {
83   return (m_ep == other.m_ep);
84 }
85
86 rc_t
87 delete_cmd::issue(connection& con)
88 {
89   msg_t req(con.ctx(), std::ref(*this));
90
91   auto payload = req.get_request().get_payload();
92
93   payload.is_add = 0;
94
95   to_api(m_ep.src, payload.tunnel.src);
96   to_api(m_ep.src, payload.tunnel.dst);
97   payload.tunnel.mcast_sw_if_index = ~0;
98   payload.tunnel.encap_table_id = 0;
99   payload.tunnel.vni = m_ep.vni;
100
101   VAPI_CALL(req.execute());
102
103   wait();
104   m_hw_item.set(rc_t::NOOP);
105
106   remove_interface();
107   return (rc_t::OK);
108 }
109
110 std::string
111 delete_cmd::to_string() const
112 {
113   std::ostringstream s;
114   s << "vxlan-gbp-tunnel-delete: " << m_hw_item.to_string() << m_ep.to_string();
115
116   return (s.str());
117 }
118
119 dump_cmd::dump_cmd()
120 {
121 }
122
123 bool
124 dump_cmd::operator==(const dump_cmd& other) const
125 {
126   return (true);
127 }
128
129 rc_t
130 dump_cmd::issue(connection& con)
131 {
132   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
133
134   auto& payload = m_dump->get_request().get_payload();
135   payload.sw_if_index = ~0;
136
137   VAPI_CALL(m_dump->execute());
138
139   wait();
140
141   return rc_t::OK;
142 }
143
144 std::string
145 dump_cmd::to_string() const
146 {
147   return ("vxlan-gbp-tunnel-dump");
148 }
149 } // namespace vxlan_tunnel_cmds
150 } // namespace VOM
151
152 /*
153  * fd.io coding-style-patch-verification: ON
154  *
155  * Local Variables:
156  * eval: (c-set-style "mozilla")
157  * End:
158  */