GBP: fixes for l3-out routing
[vpp.git] / extras / vom / vom / gbp_bridge_domain_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/gbp_bridge_domain_cmds.hpp"
17
18 namespace VOM {
19 namespace gbp_bridge_domain_cmds {
20
21 create_cmd::create_cmd(HW::item<uint32_t>& item,
22                        const handle_t bvi,
23                        const handle_t uu_fwd,
24                        const handle_t bm_flood,
25                        const gbp_bridge_domain::flags_t& flags)
26   : rpc_cmd(item)
27   , m_bvi(bvi)
28   , m_uu_fwd(uu_fwd)
29   , m_bm_flood(bm_flood)
30   , m_flags(flags)
31 {
32 }
33
34 bool
35 create_cmd::operator==(const create_cmd& other) const
36 {
37   return ((m_hw_item.data() == other.m_hw_item.data()) &&
38           (m_bvi == other.m_bvi) && (m_uu_fwd == other.m_uu_fwd) &&
39           (m_bm_flood == other.m_bm_flood) && (m_flags == other.m_flags));
40 }
41
42 rc_t
43 create_cmd::issue(connection& con)
44 {
45   msg_t req(con.ctx(), std::ref(*this));
46
47   auto& payload = req.get_request().get_payload();
48
49   payload.bd.bd_id = m_hw_item.data();
50   payload.bd.bvi_sw_if_index = m_bvi.value();
51   payload.bd.uu_fwd_sw_if_index = m_uu_fwd.value();
52   payload.bd.bm_flood_sw_if_index = m_bm_flood.value();
53
54   payload.bd.flags = GBP_BD_API_FLAG_NONE;
55   if (gbp_bridge_domain::flags_t::DO_NOT_LEARN == m_flags)
56     payload.bd.flags = GBP_BD_API_FLAG_DO_NOT_LEARN;
57
58   VAPI_CALL(req.execute());
59
60   return (wait());
61 }
62
63 std::string
64 create_cmd::to_string() const
65 {
66   std::ostringstream s;
67   s << "gbp-bridge-domain: " << m_hw_item.to_string()
68     << " flags:" << m_flags.to_string() << " bvi:" << m_bvi.to_string()
69     << " uu-fwd:" << m_uu_fwd.to_string();
70
71   return (s.str());
72 }
73
74 delete_cmd::delete_cmd(HW::item<uint32_t>& item)
75   : rpc_cmd(item)
76 {
77 }
78
79 bool
80 delete_cmd::operator==(const delete_cmd& other) const
81 {
82   return (m_hw_item.data() == other.m_hw_item.data());
83 }
84
85 rc_t
86 delete_cmd::issue(connection& con)
87 {
88   msg_t req(con.ctx(), std::ref(*this));
89
90   auto& payload = req.get_request().get_payload();
91
92   payload.bd_id = m_hw_item.data();
93
94   VAPI_CALL(req.execute());
95
96   wait();
97   m_hw_item.set(rc_t::NOOP);
98
99   return rc_t::OK;
100 }
101
102 std::string
103 delete_cmd::to_string() const
104 {
105   std::ostringstream s;
106   s << "gbp-bridge-domain: " << m_hw_item.to_string();
107
108   return (s.str());
109 }
110
111 bool
112 dump_cmd::operator==(const dump_cmd& other) const
113 {
114   return (true);
115 }
116
117 rc_t
118 dump_cmd::issue(connection& con)
119 {
120   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
121
122   VAPI_CALL(m_dump->execute());
123
124   wait();
125
126   return rc_t::OK;
127 }
128
129 std::string
130 dump_cmd::to_string() const
131 {
132   return ("gbp-bridge-domain-dump");
133 }
134
135 }; // namespace gbp_bridge_domain_cmds
136 }; // namespace VOM
137
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "mozilla")
143  * End:
144  */