0f91e4b3b7a750d5e945223237d67e017b3d67eb
[vpp.git] / extras / vom / vom / l2_binding_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/l2_binding_cmds.hpp"
17
18 namespace VOM {
19 namespace l2_binding_cmds {
20 bind_cmd::bind_cmd(HW::item<bool>& item,
21                    const handle_t& itf,
22                    uint32_t bd,
23                    bool is_bvi)
24   : rpc_cmd(item)
25   , m_itf(itf)
26   , m_bd(bd)
27   , m_is_bvi(is_bvi)
28 {
29 }
30
31 bool
32 bind_cmd::operator==(const bind_cmd& other) const
33 {
34   return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
35           (m_is_bvi == other.m_is_bvi));
36 }
37
38 rc_t
39 bind_cmd::issue(connection& con)
40 {
41   msg_t req(con.ctx(), std::ref(*this));
42
43   auto& payload = req.get_request().get_payload();
44   payload.rx_sw_if_index = m_itf.value();
45   payload.bd_id = m_bd;
46   payload.shg = 0;
47   payload.bvi = m_is_bvi;
48   payload.enable = 1;
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 bind_cmd::to_string() const
59 {
60   std::ostringstream s;
61   s << "L2-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
62     << " bd:" << m_bd;
63
64   return (s.str());
65 }
66
67 unbind_cmd::unbind_cmd(HW::item<bool>& item,
68                        const handle_t& itf,
69                        uint32_t bd,
70                        bool is_bvi)
71   : rpc_cmd(item)
72   , m_itf(itf)
73   , m_bd(bd)
74   , m_is_bvi(is_bvi)
75 {
76 }
77
78 bool
79 unbind_cmd::operator==(const unbind_cmd& other) const
80 {
81   return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
82           (m_is_bvi == other.m_is_bvi));
83 }
84
85 rc_t
86 unbind_cmd::issue(connection& con)
87 {
88   msg_t req(con.ctx(), std::ref(*this));
89
90   auto& payload = req.get_request().get_payload();
91   payload.rx_sw_if_index = m_itf.value();
92   payload.bd_id = m_bd;
93   payload.shg = 0;
94   payload.bvi = m_is_bvi;
95   payload.enable = 0;
96
97   VAPI_CALL(req.execute());
98
99   wait();
100   m_hw_item.set(rc_t::NOOP);
101
102   return (rc_t::OK);
103 }
104
105 std::string
106 unbind_cmd::to_string() const
107 {
108   std::ostringstream s;
109   s << "L2-unbind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
110     << " bd:" << m_bd;
111
112   return (s.str());
113 }
114
115 set_vtr_op_cmd::set_vtr_op_cmd(HW::item<l2_binding::l2_vtr_op_t>& item,
116                                const handle_t& itf,
117                                uint16_t tag)
118   : rpc_cmd(item)
119   , m_itf(itf)
120   , m_tag(tag)
121 {
122 }
123
124 bool
125 set_vtr_op_cmd::operator==(const set_vtr_op_cmd& other) const
126 {
127   return (
128     (m_hw_item.data() == other.m_hw_item.data() && m_itf == other.m_itf) &&
129     (m_tag == other.m_tag));
130 }
131
132 rc_t
133 set_vtr_op_cmd::issue(connection& con)
134 {
135   msg_t req(con.ctx(), std::ref(*this));
136
137   auto& payload = req.get_request().get_payload();
138   payload.sw_if_index = m_itf.value();
139   payload.vtr_op = m_hw_item.data().value();
140   payload.push_dot1q = 1;
141   payload.tag1 = m_tag;
142
143   VAPI_CALL(req.execute());
144
145   wait();
146
147   return (rc_t::OK);
148 }
149
150 std::string
151 set_vtr_op_cmd::to_string() const
152 {
153   std::ostringstream s;
154   s << "L2-set-vtr-op: " << m_hw_item.to_string()
155     << " itf:" << m_itf.to_string() << " tag:" << m_tag;
156
157   return (s.str());
158 }
159
160 }; // namespace l2_binding_cmds
161 }; // namespace VOM
162
163 /*
164  * fd.io coding-style-patch-verification: ON
165  *
166  * Local Variables:
167  * eval: (c-set-style "mozilla")
168  * End:
169  */