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