FD.io VPP  v21.06-3-gbb25fbf28
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(), 1, std::ref(*this));
49 
50  auto& payload = req.get_request().get_payload();
51 
52  payload.is_add = 1;
53 
54  payload.route.table_id = m_id;
55  payload.route.prefix = to_api(m_mprefix);
56 
57  to_api(m_path, payload.route.paths[0].path);
58  payload.route.paths[0].itf_flags = to_api(m_flags);
59 
60  VAPI_CALL(req.execute());
61 
62  return (wait());
63 }
64 
67 {
68  std::ostringstream s;
69  s << "ip-mroute-create: " << m_hw_item.to_string() << " table-id:" << m_id
70  << " mprefix:" << m_mprefix.to_string() << " path:" << m_path.to_string()
71  << " flags:" << m_flags;
72 
73  return (s.str());
74 }
75 
77  table_id_t id,
78  const mprefix_t& mprefix,
79  const path& path,
80  const itf_flags_t& flags)
81  : rpc_cmd(item)
82  , m_id(id)
83  , m_mprefix(mprefix)
84  , m_path(path)
85  , m_flags(flags)
86 {
87 }
88 
89 bool
91 {
92  return ((m_mprefix == other.m_mprefix) && (m_id == other.m_id));
93 }
94 
95 rc_t
97 {
98  msg_t req(con.ctx(), 1, std::ref(*this));
99 
100  auto& payload = req.get_request().get_payload();
101  payload.is_add = 1;
102 
103  payload.route.table_id = m_id;
104  payload.route.prefix = to_api(m_mprefix);
105 
106  to_api(m_path, payload.route.paths[0].path);
107  payload.route.paths[0].itf_flags = to_api(m_flags);
108 
109  VAPI_CALL(req.execute());
110 
111  wait();
113 
114  return rc_t::OK;
115 }
116 
119 {
120  std::ostringstream s;
121  s << "ip-mroute-delete: " << m_hw_item.to_string() << " id:" << m_id
122  << " mprefix:" << m_mprefix.to_string();
123 
124  return (s.str());
125 }
126 
128  : m_id(id)
129  , m_proto(proto)
130 {
131 }
132 
133 bool
134 dump_cmd::operator==(const dump_cmd& other) const
135 {
136  return (true);
137 }
138 
139 rc_t
141 {
142  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
143 
144  auto& payload = m_dump->get_request().get_payload();
145 
146  payload.table.table_id = m_id;
147  payload.table.is_ip6 = m_proto.is_ipv6();
148 
149  VAPI_CALL(m_dump->execute());
150 
151  wait();
152 
153  return rc_t::OK;
154 }
155 
158 {
159  std::ostringstream s;
160  s << "ip-mroute-dump: id:" << m_id << " proto:" << m_proto.to_string();
161 
162  return (s.str());
163 }
164 
165 } // namespace ip_mroute_cmds
166 } // namespace mroute
167 } // namespace vom
168  /*
169  * fd.io coding-style-patch-verification: OFF
170  *
171  * Local Variables:
172  * eval: (c-set-style "mozilla")
173  * End:
174  */
VOM::HW::item< bool >
VOM::dump_cmd< vapi::Ip_mroute_dump >::msg_t
vapi::Ip_mroute_dump msg_t
Definition: dump_cmd.hpp:46
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_mroute_add_del >::wait
rc_t wait()
Wait on the commands promise.
Definition: rpc_cmd.hpp:82
VOM::HW::item::set
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
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::route::ip_mroute_cmds::dump_cmd
A cmd class that Dumps ipv4 fib.
Definition: mroute_cmds.hpp:106
VOM::route::ip_mroute_cmds::delete_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:96
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
con
Connection con
Definition: vapi_cpp_test.cpp:56
VOM::route::path::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: route.cpp:188
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_mroute_add_del >::m_hw_item
HW::item< bool > & m_hw_item
A reference to an object's HW::item that the command will update.
Definition: rpc_cmd.hpp:134
VOM::dump_cmd< vapi::Ip_mroute_dump >::m_dump
std::unique_ptr< vapi::Ip_mroute_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
VOM::route::mprefix_t
A prefix defintion.
Definition: prefix.hpp:252
mprefix
typedef mprefix
Definition: ip_types.api:118
route_api_types.hpp
VOM::route::ip_mroute_cmds::update_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: mroute_cmds.cpp:66
VAPI_CALL
#define VAPI_CALL(_stmt)
Convenince wrapper macro for error handling in VAPI sends.
Definition: types.hpp:29
VOM::connection
A representation of the connection to VPP.
Definition: connection.hpp:33
VOM::route::ip_mroute_cmds::delete_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: mroute_cmds.cpp:118
VOM::dump_cmd< vapi::Ip_mroute_dump >::wait
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
VOM::rc_t::NOOP
const static rc_t NOOP
The HW write/update action was/has not been attempted.
Definition: types.hpp:104
VOM::route::ip_mroute_cmds::dump_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:140
VOM::route::ip_mroute_cmds::delete_cmd
A cmd class that deletes a route.
Definition: mroute_cmds.hpp:69
VOM::HW::item::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: hw.hpp:161
VOM::l3_proto_t::is_ipv6
bool is_ipv6() const
Definition: prefix.cpp:35
VOM::to_api
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
id
u8 id[64]
Definition: dhcp.api:160
VOM::rpc_cmd< HW::item< bool >, vapi::Ip_mroute_add_del >::msg_t
vapi::Ip_mroute_add_del msg_t
convenient typedef
Definition: rpc_cmd.hpp:46
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::route::ip_mroute_cmds::dump_cmd::operator==
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:134
VOM::l3_proto_t
An L3 protocol can be used to construct a prefix that is used to match packets are part of a route.
Definition: prefix.hpp:52
VOM::route::ip_mroute_cmds::dump_cmd::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: mroute_cmds.cpp:157
VOM::route::itf_flags_t
Definition: route.hpp:207
item
cJSON * item
Definition: cJSON.h:222
VOM::dump_cmd< vapi::Ip_mroute_dump >::dump_cmd
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
VOM::route::path::path
path(special_t special, const nh_proto_t &proto=nh_proto_t::IPV4)
constructor for special paths
Definition: route.cpp:58
VOM::route::ip_mroute_cmds::update_cmd::issue
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:46
VOM::route::path
A path for IP or MPLS routes.
Definition: route.hpp:32
VOM::route::ip_mroute_cmds::delete_cmd::operator==
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:90
VOM::route::table_id_t
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
mroute_cmds.hpp
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::route::ip_mroute_cmds::update_cmd::update_cmd
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
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
VOM::route::ip_mroute_cmds::update_cmd::operator==
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:40
VOM::route::ip_mroute_cmds::delete_cmd::delete_cmd
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:76
api_types.hpp
VOM::route::ip_mroute_cmds::update_cmd
A command class that creates or updates the route.
Definition: mroute_cmds.hpp:32
VOM::route::mprefix_t::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:574
string
const char *const string
Definition: cJSON.h:172
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105