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