GBP: l3-out subnets
[vpp.git] / extras / vom / vom / gbp_ext_itf_cmds.cpp
1 /*
2  * Copyright (c) 2018 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_ext_itf_cmds.hpp"
17
18 namespace VOM {
19 namespace gbp_ext_itf_cmds {
20
21 create_cmd::create_cmd(HW::item<bool>& item,
22                        const handle_t& itf,
23                        uint32_t bd_id,
24                        uint32_t rd_id)
25   : rpc_cmd(item)
26   , m_itf(itf)
27   , m_bd_id(bd_id)
28   , m_rd_id(rd_id)
29 {
30 }
31
32 bool
33 create_cmd::operator==(const create_cmd& other) const
34 {
35   return ((m_itf == other.m_itf) && (m_bd_id == other.m_bd_id) &&
36           (m_rd_id == other.m_rd_id));
37 }
38
39 rc_t
40 create_cmd::issue(connection& con)
41 {
42   msg_t req(con.ctx(), std::ref(*this));
43
44   auto& payload = req.get_request().get_payload();
45   payload.is_add = 1;
46   payload.ext_itf.sw_if_index = m_itf.value();
47   payload.ext_itf.bd_id = m_bd_id;
48   payload.ext_itf.rd_id = m_rd_id;
49
50   VAPI_CALL(req.execute());
51
52   return (wait());
53 }
54
55 std::string
56 create_cmd::to_string() const
57 {
58   std::ostringstream s;
59   s << "gbp-ext_itf-create: " << m_hw_item.to_string() << " itf:" << m_itf
60     << " bd-id:" << m_bd_id << " rd-id:" << m_rd_id;
61
62   return (s.str());
63 }
64
65 delete_cmd::delete_cmd(HW::item<bool>& item, const handle_t& itf)
66   : rpc_cmd(item)
67   , m_itf(itf)
68 {
69 }
70
71 bool
72 delete_cmd::operator==(const delete_cmd& other) const
73 {
74   return (m_itf == other.m_itf);
75 }
76
77 rc_t
78 delete_cmd::issue(connection& con)
79 {
80   msg_t req(con.ctx(), std::ref(*this));
81
82   auto& payload = req.get_request().get_payload();
83   payload.is_add = 0;
84   payload.ext_itf.sw_if_index = m_itf.value();
85   payload.ext_itf.bd_id = ~0;
86   payload.ext_itf.rd_id = ~0;
87
88   VAPI_CALL(req.execute());
89
90   return (wait());
91 }
92
93 std::string
94 delete_cmd::to_string() const
95 {
96   std::ostringstream s;
97   s << "gbp-ext-itf-delete: " << m_hw_item.to_string() << " itf:" << m_itf;
98
99   return (s.str());
100 }
101
102 bool
103 dump_cmd::operator==(const dump_cmd& other) const
104 {
105   return (true);
106 }
107
108 rc_t
109 dump_cmd::issue(connection& con)
110 {
111   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
112
113   VAPI_CALL(m_dump->execute());
114
115   wait();
116
117   return rc_t::OK;
118 }
119
120 std::string
121 dump_cmd::to_string() const
122 {
123   return ("gbp-ext-itf-dump");
124 }
125
126 }; // namespace gbp_ext_itf_cmds
127 }; // namespace VOM
128
129 /*
130  * fd.io coding-style-patch-verification: ON
131  *
132  * Local Variables:
133  * eval: (c-set-style "mozilla")
134  * End:
135  */