blob: 47af69268d1b297dcf6a286289a4a1e93f2164ff [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070016#include "vom/sub_interface_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017#include "vom/cmd.hpp"
18
19#include <vapi/vpe.api.vapi.hpp>
20
21namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070022namespace sub_interface_cmds {
23
24create_cmd::create_cmd(HW::item<handle_t>& item,
25 const std::string& name,
26 const handle_t& parent,
27 uint16_t vlan)
Neale Ranns812ed392017-10-16 04:20:13 -070028 : interface::create_cmd<vapi::Create_vlan_subif>(item, name)
29 , m_parent(parent)
30 , m_vlan(vlan)
31{
32}
33
34bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070035create_cmd::operator==(const create_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070036{
37 return ((m_name == other.m_name) && (m_parent == other.m_parent) &&
38 (m_vlan == other.m_vlan));
39}
40
41rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070042create_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070043{
44 msg_t req(con.ctx(), std::ref(*this));
45
46 auto& payload = req.get_request().get_payload();
47 payload.sw_if_index = m_parent.value();
48 payload.vlan_id = m_vlan;
49
50 VAPI_CALL(req.execute());
51
52 m_hw_item = wait();
53
54 if (m_hw_item.rc() == rc_t::OK) {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070055 insert_interface();
Neale Ranns812ed392017-10-16 04:20:13 -070056 }
57
58 return rc_t::OK;
59}
60
61std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070062create_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070063{
64 std::ostringstream s;
65 s << "sub-itf-create: " << m_hw_item.to_string() << " parent:" << m_parent
66 << " vlan:" << m_vlan;
67 return (s.str());
68}
69
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070070delete_cmd::delete_cmd(HW::item<handle_t>& item)
Neale Ranns812ed392017-10-16 04:20:13 -070071 : interface::delete_cmd<vapi::Delete_subif>(item)
72{
73}
74
75bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070076delete_cmd::operator==(const delete_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -070077{
78 return (m_hw_item == other.m_hw_item);
79}
80
81rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070082delete_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070083{
84 msg_t req(con.ctx(), std::ref(*this));
85
86 auto& payload = req.get_request().get_payload();
87 payload.sw_if_index = m_hw_item.data().value();
88
89 VAPI_CALL(req.execute());
90
91 wait();
92 m_hw_item.set(rc_t::NOOP);
93
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070094 remove_interface();
Neale Ranns812ed392017-10-16 04:20:13 -070095 return (rc_t::OK);
96}
97
98std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070099delete_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700100{
101 std::ostringstream s;
102
103 s << "sub-itf-delete: " << m_hw_item.to_string();
104
105 return (s.str());
106}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700107} // namespace sub_interface_cmds
108} // namespace VOM
109 /*
110 * fd.io coding-style-patch-verification: ON
111 *
112 * Local Variables:
113 * eval: (c-set-style "mozilla")
114 * End:
115 */