Fix coverity warnings in VOM and VAPI
[vpp.git] / src / vpp-api / vom / sub_interface_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/sub_interface.hpp"
17 #include "vom/cmd.hpp"
18
19 #include <vapi/vpe.api.vapi.hpp>
20
21 namespace VOM {
22 sub_interface::create_cmd::create_cmd(HW::item<handle_t>& item,
23                                       const std::string& name,
24                                       const handle_t& parent,
25                                       uint16_t vlan)
26   : interface::create_cmd<vapi::Create_vlan_subif>(item, name)
27   , m_parent(parent)
28   , m_vlan(vlan)
29 {
30 }
31
32 bool
33 sub_interface::create_cmd::operator==(const create_cmd& other) const
34 {
35   return ((m_name == other.m_name) && (m_parent == other.m_parent) &&
36           (m_vlan == other.m_vlan));
37 }
38
39 rc_t
40 sub_interface::create_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.sw_if_index = m_parent.value();
46   payload.vlan_id = m_vlan;
47
48   VAPI_CALL(req.execute());
49
50   m_hw_item = wait();
51
52   if (m_hw_item.rc() == rc_t::OK) {
53     interface::add(m_name, m_hw_item);
54   }
55
56   return rc_t::OK;
57 }
58
59 std::string
60 sub_interface::create_cmd::to_string() const
61 {
62   std::ostringstream s;
63   s << "sub-itf-create: " << m_hw_item.to_string() << " parent:" << m_parent
64     << " vlan:" << m_vlan;
65   return (s.str());
66 }
67
68 sub_interface::delete_cmd::delete_cmd(HW::item<handle_t>& item)
69   : interface::delete_cmd<vapi::Delete_subif>(item)
70 {
71 }
72
73 bool
74 sub_interface::delete_cmd::operator==(const delete_cmd& other) const
75 {
76   return (m_hw_item == other.m_hw_item);
77 }
78
79 rc_t
80 sub_interface::delete_cmd::issue(connection& con)
81 {
82   msg_t req(con.ctx(), std::ref(*this));
83
84   auto& payload = req.get_request().get_payload();
85   payload.sw_if_index = m_hw_item.data().value();
86
87   VAPI_CALL(req.execute());
88
89   wait();
90   m_hw_item.set(rc_t::NOOP);
91
92   interface::remove(m_hw_item);
93   return (rc_t::OK);
94 }
95
96 std::string
97 sub_interface::delete_cmd::to_string() const
98 {
99   std::ostringstream s;
100
101   s << "sub-itf-delete: " << m_hw_item.to_string();
102
103   return (s.str());
104 }
105 }
106 /*
107  * fd.io coding-style-patch-verification: ON
108  *
109  * Local Variables:
110  * eval: (c-set-style "mozilla")
111  * End:
112  */