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