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