FD.io VPP  v19.08.1-401-g8e4ed521a
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 
65 std::string
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 
117 std::string
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 
156 std::string
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: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "mozilla")
173  * End:
174  */
uint32_t table_id_t
type def the table-id
Definition: prefix.hpp:121
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:141
A cmd class that deletes a route.
Definition: mroute_cmds.hpp:69
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:188
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
vapi_enum_ip_neighbor_flags to_api(const neighbour::flags_t &f)
Definition: api_types.cpp:21
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:76
A representation of the connection to VPP.
Definition: connection.hpp:33
dump_cmd()
Default Constructor.
Definition: dump_cmd.hpp:55
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
A cmd class that Dumps ipv4 fib.
std::string to_string() const
convert to string format for debug purposes
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
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:66
bool operator==(const update_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:40
rc_t wait()
Wait for the issue of the command to complete.
Definition: dump_cmd.hpp:93
typedef mprefix
Definition: ip_types.api:93
bool operator==(const delete_cmd &i) const
Comparison operator - only used for UT.
Definition: mroute_cmds.cpp:90
vapi::Connection & ctx()
Retrun the VAPI context the commands will use.
Definition: connection.cpp:49
path(special_t special, const nh_proto_t &proto=nh_proto_t::IPV4)
constructor for special paths
Definition: route.cpp:58
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A prefix defintion.
Definition: prefix.hpp:252
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:96
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
std::unique_ptr< vapi::Ip_mroute_dump > m_dump
The VAPI event registration.
Definition: dump_cmd.hpp:143
bool operator==(const dump_cmd &i) const
Comparison operator - only used for UT.
bool is_ipv6() const
Definition: prefix.cpp:35
std::string to_string() const
convert to string format for debug purposes
Definition: prefix.cpp:574
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
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
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.
rc_t issue(connection &con)
Issue the command to VPP/HW.
Definition: mroute_cmds.cpp:46