Fix coverity warnings in VOM and VAPI
[vpp.git] / src / vpp-api / vom / interface_span_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/interface_span.hpp"
17
18 DEFINE_VAPI_MSG_IDS_SPAN_API_JSON;
19
20 namespace VOM {
21 interface_span::config_cmd::config_cmd(HW::item<bool>& item,
22                                        const handle_t& itf_from,
23                                        const handle_t& itf_to,
24                                        const interface_span::state_t& state)
25   : rpc_cmd(item)
26   , m_itf_from(itf_from)
27   , m_itf_to(itf_to)
28   , m_state(state)
29 {
30 }
31
32 bool
33 interface_span::config_cmd::operator==(const config_cmd& o) const
34 {
35   return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to) &&
36           (m_state == o.m_state));
37 }
38
39 rc_t
40 interface_span::config_cmd::issue(connection& con)
41 {
42   msg_t req(con.ctx(), std::ref(*this));
43
44   auto& payload = req.get_request().get_payload();
45   payload.is_l2 = 0;
46   payload.sw_if_index_from = m_itf_from.value();
47   payload.sw_if_index_to = m_itf_to.value();
48   payload.state = m_state.value();
49
50   VAPI_CALL(req.execute());
51
52   m_hw_item.set(wait());
53
54   return rc_t::OK;
55 }
56
57 std::string
58 interface_span::config_cmd::to_string() const
59 {
60   std::ostringstream s;
61   s << "itf-span-config: " << m_hw_item.to_string()
62     << " itf-from:" << m_itf_from.to_string()
63     << " itf-to:" << m_itf_to.to_string() << " state:" << m_state.to_string();
64
65   return (s.str());
66 }
67
68 interface_span::unconfig_cmd::unconfig_cmd(HW::item<bool>& item,
69                                            const handle_t& itf_from,
70                                            const handle_t& itf_to)
71   : rpc_cmd(item)
72   , m_itf_from(itf_from)
73   , m_itf_to(itf_to)
74 {
75 }
76
77 bool
78 interface_span::unconfig_cmd::operator==(const unconfig_cmd& o) const
79 {
80   return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to));
81 }
82
83 rc_t
84 interface_span::unconfig_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_l2 = 0;
90   payload.sw_if_index_from = m_itf_from.value();
91   payload.sw_if_index_to = m_itf_to.value();
92   payload.state = 0;
93
94   VAPI_CALL(req.execute());
95
96   wait();
97   m_hw_item.set(rc_t::NOOP);
98
99   return rc_t::OK;
100 }
101
102 std::string
103 interface_span::unconfig_cmd::to_string() const
104 {
105   std::ostringstream s;
106   s << "itf-span-unconfig: " << m_hw_item.to_string()
107     << " itf-from:" << m_itf_from.to_string()
108     << " itf-to:" << m_itf_to.to_string();
109
110   return (s.str());
111 }
112
113 interface_span::dump_cmd::dump_cmd()
114 {
115 }
116
117 bool
118 interface_span::dump_cmd::operator==(const dump_cmd& other) const
119 {
120   return (true);
121 }
122
123 rc_t
124 interface_span::dump_cmd::issue(connection& con)
125 {
126   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
127
128   auto& payload = m_dump->get_request().get_payload();
129   payload.is_l2 = 0;
130
131   VAPI_CALL(m_dump->execute());
132
133   wait();
134
135   return rc_t::OK;
136 }
137
138 std::string
139 interface_span::dump_cmd::to_string() const
140 {
141   return ("interface-span-dump");
142 }
143 }
144
145 /*
146  * fd.io coding-style-patch-verification: ON
147  *
148  * Local Variables:
149  * eval: (c-set-style "mozilla")
150  * End:
151  */