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