FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
mroute_cmds.cpp
Go to the documentation of this file.
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 <sstream>
17 
18 #include "vom/api_types.hpp"
19 #include "vom/mroute_cmds.hpp"
20 #include "vom/route_api_types.hpp"
21 
22 namespace VOM {
23 namespace route {
24 namespace ip_mroute_cmds {
25 
27  table_id_t id,
28  const mprefix_t& mprefix,
29  const path& path,
30  const itf_flags_t& flags)
31  : rpc_cmd(item)
32  , m_id(id)
33  , m_mprefix(mprefix)
34  , m_path(path)
35  , m_flags(flags)
36 {
37 }
38 
39 bool
41 {
42  return ((m_mprefix == other.m_mprefix) && (m_id == other.m_id));
43 }
44 
45 rc_t
47 {
48  msg_t req(con.ctx(), std::ref(*this));
49 
50  auto& payload = req.get_request().get_payload();
51 
52  payload.table_id = m_id;
53  payload.is_add = 1;
54 
55  m_mprefix.to_vpp(&payload.is_ipv6, payload.grp_address, payload.src_address,
56  &payload.grp_address_length);
57 
58  to_vpp(m_path, payload);
59  payload.itf_flags = m_flags.value();
60 
61  VAPI_CALL(req.execute());
62 
63  return (wait());
64 }
65 
66 std::string
68 {
69  std::ostringstream s;
70  s << "ip-mroute-create: " << m_hw_item.to_string() << " table-id:" << m_id
71  << " mprefix:" << m_mprefix.to_string() << " path:" << m_path.to_string()
72  << " flags:" << m_flags;
73 
74  return (s.str());
75 }
76 
78  table_id_t id,
79  const mprefix_t& mprefix,
80  const path& path,
81  const itf_flags_t& flags)
82  : rpc_cmd(item)
83  , m_id(id)
84  , m_mprefix(mprefix)
85  , m_path(path)
86  , m_flags(flags)
87 {
88 }
89 
90 bool
92 {
93  return ((m_mprefix == other.m_mprefix) && (m_id == other.m_id));
94 }
95 
96 rc_t
98 {
99  msg_t req(con.ctx(), std::ref(*this));
100 
101  auto& payload = req.get_request().get_payload();
102  payload.table_id = m_id;
103  payload.is_add = 0;
104 
105  m_mprefix.to_vpp(&payload.is_ipv6, payload.grp_address, payload.src_address,
106  &payload.grp_address_length);
107 
108  to_vpp(m_path, payload);
109  payload.itf_flags = m_flags.value();
110 
111  VAPI_CALL(req.execute());
112 
113  wait();
115 
116  return rc_t::OK;
117 }
118 
119 std::string
121 {
122  std::ostringstream s;
123  s << "ip-mroute-delete: " << m_hw_item.to_string() << " id:" << m_id
124  << " mprefix:" << m_mprefix.to_string();
125 
126  return (s.str());
127 }
128 
130 {
131 }
132 
133 bool
135 {
136  return (true);
137 }
138 
139 rc_t
141 {
142  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
143 
144  VAPI_CALL(m_dump->execute());
145 
146  wait();
147 
148  return rc_t::OK;
149 }
150 
151 std::string
153 {
154  return ("ip-mroute-v4-dump");
155 }
156 
158 {
159 }
160 
161 bool
163 {
164  return (true);
165 }
166 
167 rc_t
169 {
170  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
171 
172  VAPI_CALL(m_dump->execute());
173 
174  wait();
175 
176  return rc_t::OK;
177 }
178 
179 std::string
181 {
182  return ("ip-mroute-v6-dump");
183 }
184 } // namespace ip_mroute_cmds
185 } // namespace mroute
186 } // namespace vom
187  /*
188  * fd.io coding-style-patch-verification: ON
189  *
190  * Local Variables:
191  * eval: (c-set-style "mozilla")
192  * End:
193  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:82
static const rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
u32 flags
Definition: vhost_user.h:115
A cmd class that deletes a route.
Definition: mroute_cmds.hpp:69
A cmd class that Dumps ipv4 fib.
void to_vpp(const route::path &p, vapi_payload_ip_add_del_route &payload)
rc_t issue(connection &con)
Issue the command to VPP/HW.
A path for IP or MPLS routes.
Definition: route.hpp:32
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
std::string to_string() const
convert to string format for debug purposes
Definition: route.cpp:196
int value() const
Return the value of the enum - same as integer conversion.
Definition: enum_base.hpp:67
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
delete_cmd(HW::item< bool > &item, table_id_t id, const mprefix_t &mprefix, const path &path, const itf_flags_t &flags)
Constructor.
Definition: mroute_cmds.cpp:77
A representation of the connection to VPP.
Definition: connection.hpp:33
std::string to_string() const
convert to string format for debug purposes
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
A command class that creates or updates the route.
Definition: mroute_cmds.hpp:32
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
rc_t issue(connection &con)
Issue the command to VPP/HW.
A cmd class that Dumps ipv6 fib.
std::string to_string() const
convert to string format for debug purposes
void to_vpp(uint8_t *is_ip6, uint8_t *saddr, uint8_t *gaddr, uint16_t *len) const
Definition: prefix.cpp:496
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
std::string to_string() const
convert to string format for debug purposes
Definition: mroute_cmds.cpp:67
bool operator==(const dump_v4_cmd &i) const
Comparison operator - only used for UT.
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:40
typedef mprefix
Definition: ip_types.api:40
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:91
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
std::string to_string() const
convert to string format for debug purposes
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A prefix defintion.
Definition: prefix.hpp:213
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:97
update_cmd(HW::item< bool > &item, table_id_t id, const mprefix_t &mprefix, const path &path, const itf_flags_t &flags)
Constructor.
Definition: mroute_cmds.cpp:26
void set(const rc_t &rc)
Set the HW return code - should only be called from the family of Command objects.
Definition: hw.hpp:125
bool operator==(const dump_v6_cmd &i) const
Comparison operator - only used for UT.
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:542
HW::item< bool > & m_hw_item
A reference to an object&#39;s HW::item that the command will update.
Definition: rpc_cmd.hpp:134
HW::item< bool > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
vapi::Ip_mroute_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:46