blob: 3b8b8d25ec72614969143b7225e0cb06bcb1e6cd [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/interface_span_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070017
18DEFINE_VAPI_MSG_IDS_SPAN_API_JSON;
19
20namespace VOM {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070021namespace interface_span_cmds {
22
23config_cmd::config_cmd(HW::item<bool>& item,
24 const handle_t& itf_from,
25 const handle_t& itf_to,
26 const interface_span::state_t& state)
Neale Ranns812ed392017-10-16 04:20:13 -070027 : rpc_cmd(item)
28 , m_itf_from(itf_from)
29 , m_itf_to(itf_to)
30 , m_state(state)
31{
32}
33
34bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070035config_cmd::operator==(const config_cmd& o) const
Neale Ranns812ed392017-10-16 04:20:13 -070036{
37 return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to) &&
38 (m_state == o.m_state));
39}
40
41rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070042config_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.is_l2 = 0;
48 payload.sw_if_index_from = m_itf_from.value();
49 payload.sw_if_index_to = m_itf_to.value();
50 payload.state = m_state.value();
51
52 VAPI_CALL(req.execute());
53
54 m_hw_item.set(wait());
55
56 return rc_t::OK;
57}
58
59std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070060config_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -070061{
62 std::ostringstream s;
63 s << "itf-span-config: " << m_hw_item.to_string()
64 << " itf-from:" << m_itf_from.to_string()
65 << " itf-to:" << m_itf_to.to_string() << " state:" << m_state.to_string();
66
67 return (s.str());
68}
69
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070070unconfig_cmd::unconfig_cmd(HW::item<bool>& item,
71 const handle_t& itf_from,
72 const handle_t& itf_to)
Neale Ranns812ed392017-10-16 04:20:13 -070073 : rpc_cmd(item)
74 , m_itf_from(itf_from)
75 , m_itf_to(itf_to)
76{
77}
78
79bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070080unconfig_cmd::operator==(const unconfig_cmd& o) const
Neale Ranns812ed392017-10-16 04:20:13 -070081{
82 return ((m_itf_from == o.m_itf_from) && (m_itf_to == o.m_itf_to));
83}
84
85rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070086unconfig_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -070087{
88 msg_t req(con.ctx(), std::ref(*this));
89
90 auto& payload = req.get_request().get_payload();
91 payload.is_l2 = 0;
92 payload.sw_if_index_from = m_itf_from.value();
93 payload.sw_if_index_to = m_itf_to.value();
94 payload.state = 0;
95
96 VAPI_CALL(req.execute());
97
98 wait();
99 m_hw_item.set(rc_t::NOOP);
100
101 return rc_t::OK;
102}
103
104std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700105unconfig_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700106{
107 std::ostringstream s;
108 s << "itf-span-unconfig: " << m_hw_item.to_string()
109 << " itf-from:" << m_itf_from.to_string()
110 << " itf-to:" << m_itf_to.to_string();
111
112 return (s.str());
113}
114
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700115dump_cmd::dump_cmd()
Neale Ranns812ed392017-10-16 04:20:13 -0700116{
117}
118
119bool
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700120dump_cmd::operator==(const dump_cmd& other) const
Neale Ranns812ed392017-10-16 04:20:13 -0700121{
122 return (true);
123}
124
125rc_t
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700126dump_cmd::issue(connection& con)
Neale Ranns812ed392017-10-16 04:20:13 -0700127{
128 m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
129
130 auto& payload = m_dump->get_request().get_payload();
131 payload.is_l2 = 0;
132
133 VAPI_CALL(m_dump->execute());
134
135 wait();
136
137 return rc_t::OK;
138}
139
140std::string
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700141dump_cmd::to_string() const
Neale Ranns812ed392017-10-16 04:20:13 -0700142{
143 return ("interface-span-dump");
144}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700145
146}; // namespace interface_span_cmds
147}; // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700148
149/*
150 * fd.io coding-style-patch-verification: ON
151 *
152 * Local Variables:
153 * eval: (c-set-style "mozilla")
154 * End:
155 */