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