Fix coverity warnings in VOM and VAPI
[vpp.git] / src / vpp-api / vom / neighbour_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/neighbour.hpp"
17
18 namespace VOM {
19 neighbour::create_cmd::create_cmd(HW::item<bool>& item,
20                                   handle_t itf,
21                                   const mac_address_t& mac,
22                                   const boost::asio::ip::address& ip_addr)
23   : rpc_cmd(item)
24   , m_itf(itf)
25   , m_mac(mac)
26   , m_ip_addr(ip_addr)
27 {
28 }
29
30 bool
31 neighbour::create_cmd::operator==(const create_cmd& other) const
32 {
33   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
34           (m_itf == other.m_itf));
35 }
36
37 rc_t
38 neighbour::create_cmd::issue(connection& con)
39 {
40   msg_t req(con.ctx(), std::ref(*this));
41
42   auto& payload = req.get_request().get_payload();
43   payload.sw_if_index = m_itf.value();
44   payload.is_add = 1;
45   payload.is_static = 1;
46   m_mac.to_bytes(payload.mac_address, 6);
47   to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
48
49   VAPI_CALL(req.execute());
50
51   m_hw_item.set(wait());
52
53   return rc_t::OK;
54 }
55
56 std::string
57 neighbour::create_cmd::to_string() const
58 {
59   std::ostringstream s;
60   s << "nieghbour-create: " << m_hw_item.to_string()
61     << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
62     << " ip:" << m_ip_addr.to_string();
63
64   return (s.str());
65 }
66
67 neighbour::delete_cmd::delete_cmd(HW::item<bool>& item,
68                                   handle_t itf,
69                                   const mac_address_t& mac,
70                                   const boost::asio::ip::address& ip_addr)
71   : rpc_cmd(item)
72   , m_itf(itf)
73   , m_mac(mac)
74   , m_ip_addr(ip_addr)
75 {
76 }
77
78 bool
79 neighbour::delete_cmd::operator==(const delete_cmd& other) const
80 {
81   return ((m_mac == other.m_mac) && (m_ip_addr == other.m_ip_addr) &&
82           (m_itf == other.m_itf));
83 }
84
85 rc_t
86 neighbour::delete_cmd::issue(connection& con)
87 {
88   msg_t req(con.ctx(), std::ref(*this));
89
90   auto& payload = req.get_request().get_payload();
91   payload.sw_if_index = m_itf.value();
92   payload.is_add = 0;
93   payload.is_static = 1;
94   m_mac.to_bytes(payload.mac_address, 6);
95   to_bytes(m_ip_addr, &payload.is_ipv6, payload.dst_address);
96
97   VAPI_CALL(req.execute());
98
99   wait();
100   m_hw_item.set(rc_t::NOOP);
101
102   return rc_t::OK;
103 }
104
105 std::string
106 neighbour::delete_cmd::to_string() const
107 {
108   std::ostringstream s;
109   s << "neighbour-delete: " << m_hw_item.to_string()
110     << " itf:" << m_itf.to_string() << " mac:" << m_mac.to_string()
111     << " ip:" << m_ip_addr.to_string();
112
113   return (s.str());
114 }
115
116 neighbour::dump_cmd::dump_cmd(const handle_t& hdl, const l3_proto_t& proto)
117   : m_itf(hdl)
118   , m_proto(proto)
119 {
120 }
121
122 neighbour::dump_cmd::dump_cmd(const dump_cmd& d)
123   : m_itf(d.m_itf)
124   , m_proto(d.m_proto)
125 {
126 }
127
128 bool
129 neighbour::dump_cmd::operator==(const dump_cmd& other) const
130 {
131   return (true);
132 }
133
134 rc_t
135 neighbour::dump_cmd::issue(connection& con)
136 {
137   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
138
139   auto& payload = m_dump->get_request().get_payload();
140   payload.sw_if_index = m_itf.value();
141   payload.is_ipv6 = m_proto.is_ipv6();
142
143   VAPI_CALL(m_dump->execute());
144
145   wait();
146
147   return rc_t::OK;
148 }
149
150 std::string
151 neighbour::dump_cmd::to_string() const
152 {
153   return ("neighbour-dump");
154 }
155 }
156
157 /*
158  * fd.io coding-style-patch-verification: ON
159  *
160  * Local Variables:
161  * eval: (c-set-style "mozilla")
162  * End:
163  */