L2 BD: introduce a BD interface on which to send UU packets
[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.port_type =
48     (m_is_bvi ? L2_API_PORT_TYPE_BVI : L2_API_PORT_TYPE_NORMAL);
49   payload.enable = 1;
50
51   VAPI_CALL(req.execute());
52
53   return (wait());
54 }
55
56 std::string
57 bind_cmd::to_string() const
58 {
59   std::ostringstream s;
60   s << "L2-bind: " << m_hw_item.to_string() << " itf:" << m_itf.to_string()
61     << " bd:" << m_bd;
62
63   return (s.str());
64 }
65
66 unbind_cmd::unbind_cmd(HW::item<bool>& item,
67                        const handle_t& itf,
68                        uint32_t bd,
69                        bool is_bvi)
70   : rpc_cmd(item)
71   , m_itf(itf)
72   , m_bd(bd)
73   , m_is_bvi(is_bvi)
74 {
75 }
76
77 bool
78 unbind_cmd::operator==(const unbind_cmd& other) const
79 {
80   return ((m_itf == other.m_itf) && (m_bd == other.m_bd) &&
81           (m_is_bvi == other.m_is_bvi));
82 }
83
84 rc_t
85 unbind_cmd::issue(connection& con)
86 {
87   msg_t req(con.ctx(), std::ref(*this));
88
89   auto& payload = req.get_request().get_payload();
90   payload.rx_sw_if_index = m_itf.value();
91   payload.bd_id = m_bd;
92   payload.shg = 0;
93   payload.port_type =
94     (m_is_bvi ? L2_API_PORT_TYPE_BVI : L2_API_PORT_TYPE_NORMAL);
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   return (wait());
146 }
147
148 std::string
149 set_vtr_op_cmd::to_string() const
150 {
151   std::ostringstream s;
152   s << "L2-set-vtr-op: " << m_hw_item.to_string()
153     << " itf:" << m_itf.to_string() << " tag:" << m_tag;
154
155   return (s.str());
156 }
157
158 }; // namespace l2_binding_cmds
159 }; // namespace VOM
160
161 /*
162  * fd.io coding-style-patch-verification: ON
163  *
164  * Local Variables:
165  * eval: (c-set-style "mozilla")
166  * End:
167  */