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