FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_rule.hpp
Go to the documentation of this file.
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 #ifndef __VOM_GBP_RULE_H__
17 #define __VOM_GBP_RULE_H__
18 
19 #include <set>
20 
21 #include "vom/types.hpp"
22 #include <vapi/gbp.api.vapi.h>
23 namespace VOM {
24 class gbp_rule
25 {
26 public:
27  /**
28  * Representation of next hop
29  */
30  struct next_hop_t
31  {
32  /**
33  * Constructor for next_hop_t
34  */
36  const mac_address_t& mac,
37  uint32_t bd_id,
38  uint32_t rd_id);
39 
40  /**
41  * default destructor
42  */
43  ~next_hop_t() = default;
44 
45  /**
46  * convert to string
47  */
48  std::string to_string() const;
49 
50  /**
51  * less-than operator
52  */
53  bool operator<(const next_hop_t& nh) const;
54 
55  /**
56  * comparison operator (for testing)
57  */
58  bool operator==(const next_hop_t& nh) const;
59 
60  /**
61  * get the IP address
62  */
63  const boost::asio::ip::address& getIp(void) const;
64 
65  /**
66  * get the mac address
67  */
68  const mac_address_t& getMac(void) const;
69 
70  /**
71  * get the bridge domain Id
72  */
73  const uint32_t getBdId(void) const;
74 
75  /**
76  * get the route domain Id
77  */
78  const uint32_t getRdId(void) const;
79 
80  private:
81  /**
82  * IP address for next hop
83  */
84  const boost::asio::ip::address m_ip;
85 
86  /**
87  * mac address for interface lookup
88  */
89  const mac_address_t m_mac;
90 
91  /**
92  * bridge domain in which redirected endpoints exist
93  */
94  const uint32_t m_bd_id;
95 
96  /**
97  * route domain in which redirected endpoints exist
98  */
99  const uint32_t m_rd_id;
100  };
101 
102  /**
103  * hash mode enum
104  */
105  struct hash_mode_t : public enum_base<hash_mode_t>
106  {
107  /**
108  * Flow Hash is calculated based on SRC IP
109  * in case of load balancing
110  */
111  const static hash_mode_t SRC_IP;
112 
113  /**
114  * Flow hash is calculated based on DST IP
115  */
116  const static hash_mode_t DST_IP;
117 
118  /**
119  * Flow hash is calculated based on SRC IP,
120  * DST IP and Protocol. SRC IP and DST IP
121  * addresses are sorted before hash such that
122  * a same hash is generated in both directions.
123  */
124  const static hash_mode_t SYMMETRIC;
125 
126  /**
127  * create the hash mode from int value
128  */
129  static const hash_mode_t& from_int(vapi_enum_gbp_hash_mode i);
130 
131  private:
132  hash_mode_t(int v, const std::string s);
133  };
134 
135  /**
136  * unordered set of next hops
137  */
138  typedef std::set<next_hop_t> next_hops_t;
139 
140  /**
141  * Representation of set of next hops and
142  * associated hash mode profile
143  */
145  {
146  /**
147  * Constructor for next_hop_set_t
148  */
151 
152  /**
153  * Destructor for next_hop_set_t
154  */
155  ~next_hop_set_t() = default;
156 
157  /**
158  * convert to string
159  */
160  std::string to_string() const;
161 
162  /**
163  * Comparison operator
164  */
165  bool operator==(const next_hop_set_t& nhs) const;
166 
167  /**
168  * get the hash mode
169  */
170  const hash_mode_t& hash_mode(void) const;
171 
172  /**
173  * get the set of next hops
174  */
175  const next_hops_t& next_hops(void) const;
176 
177  private:
178  /**
179  * hash mode for this rule
180  */
181  const hash_mode_t m_hm;
182 
183  /**
184  * set of next hops
185  */
186  const next_hops_t m_nhs;
187  };
188 
189  /**
190  * ACL rule action enum
191  */
192  struct action_t : public enum_base<action_t>
193  {
194  /**
195  * Permit action
196  */
197  const static action_t PERMIT;
198 
199  /**
200  * Deny action
201  */
202  const static action_t DENY;
203 
204  /**
205  * Redirect action
206  */
207  const static action_t REDIRECT;
208 
209  /**
210  * create the action from int value
211  */
212  static const action_t& from_int(vapi_enum_gbp_rule_action i);
213 
214  private:
215  action_t(int v, const std::string s);
216  };
217 
218  /**
219  * Construct a new object matching the desried state
220  */
221  gbp_rule(uint32_t priority, const next_hop_set_t& nhs, const action_t& a);
222  gbp_rule(uint32_t priority, const action_t& a);
223 
224  /**
225  * Copy Constructor
226  */
227  gbp_rule(const gbp_rule& o) = default;
228 
229  /**
230  * Destructor
231  */
232  ~gbp_rule() = default;
233 
234  /**
235  * convert to string format for debug purposes
236  */
237  std::string to_string() const;
238 
239  /**
240  * less-than operator
241  */
242  bool operator<(const gbp_rule& rule) const;
243 
244  /**
245  * comparison operator (for testing)
246  */
247  bool operator==(const gbp_rule& rule) const;
248 
249  /**
250  * Getters
251  */
252  const next_hop_set_t& nhs() const;
253  const action_t& action() const;
254 
255 private:
256  /**
257  * Priority. Used to sort the rules in a list in the order
258  * in which they are applied
259  */
260  uint32_t m_priority;
261 
262  /**
263  * set of next hops along with hash mode profile
264  */
265  const next_hop_set_t m_nhs;
266 
267  /**
268  * Action on match
269  */
270  const action_t m_action;
271 };
272 };
273 
274 /*
275  * fd.io coding-style-patch-verification: OFF
276  *
277  * Local Variables:
278  * eval: (c-set-style "mozilla")
279  * End:
280  */
281 
282 #endif
VOM::gbp_rule::next_hop_set_t
Representation of set of next hops and associated hash mode profile.
Definition: gbp_rule.hpp:144
VOM::gbp_rule::nhs
const next_hop_set_t & nhs() const
Getters.
Definition: gbp_rule.cpp:216
mac
vl_api_mac_address_t mac
Definition: l2.api:559
VOM::gbp_rule::next_hop_t::getBdId
const uint32_t getBdId(void) const
get the bridge domain Id
Definition: gbp_rule.cpp:70
VOM::gbp_rule
Definition: gbp_rule.hpp:24
VOM::gbp_rule::operator<
bool operator<(const gbp_rule &rule) const
less-than operator
Definition: gbp_rule.cpp:185
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::gbp_rule::action_t::DENY
const static action_t DENY
Deny action.
Definition: gbp_rule.hpp:202
VOM::gbp_rule::next_hops_t
std::set< next_hop_t > next_hops_t
unordered set of next hops
Definition: gbp_rule.hpp:138
VOM::gbp_rule::next_hop_set_t::next_hops
const next_hops_t & next_hops(void) const
get the set of next hops
Definition: gbp_rule.cpp:143
types.hpp
VOM::gbp_rule::hash_mode_t::DST_IP
const static hash_mode_t DST_IP
Flow hash is calculated based on DST IP.
Definition: gbp_rule.hpp:116
VOM::gbp_rule::next_hop_set_t::next_hop_set_t
next_hop_set_t(const hash_mode_t &hm, next_hops_t &nhs)
Constructor for next_hop_set_t.
Definition: gbp_rule.cpp:101
VOM::gbp_rule::next_hop_set_t::hash_mode
const hash_mode_t & hash_mode(void) const
get the hash mode
Definition: gbp_rule.cpp:137
VOM::gbp_rule::action_t::PERMIT
const static action_t PERMIT
Permit action.
Definition: gbp_rule.hpp:197
VOM::gbp_rule::action_t::REDIRECT
const static action_t REDIRECT
Redirect action.
Definition: gbp_rule.hpp:207
VOM::gbp_rule::to_string
std::string to_string() const
convert to string format for debug purposes
Definition: gbp_rule.cpp:198
VOM::gbp_rule::hash_mode_t::SYMMETRIC
const static hash_mode_t SYMMETRIC
Flow hash is calculated based on SRC IP, DST IP and Protocol.
Definition: gbp_rule.hpp:124
VOM::gbp_rule::next_hop_set_t::to_string
std::string to_string() const
convert to string
Definition: gbp_rule.cpp:115
bd_id
u32 bd_id
Definition: gbp.api:188
priority
i32 priority
Definition: ipsec.api:95
VOM::gbp_rule::next_hop_t::~next_hop_t
~next_hop_t()=default
default destructor
VOM::enum_base
A template base class for all enum types.
Definition: enum_base.hpp:30
VOM::gbp_rule::next_hop_t::getMac
const mac_address_t & getMac(void) const
get the mac address
Definition: gbp_rule.cpp:64
VOM::gbp_rule::next_hop_t::operator==
bool operator==(const next_hop_t &nh) const
comparison operator (for testing)
Definition: gbp_rule.cpp:51
VOM::gbp_rule::hash_mode_t
hash mode enum
Definition: gbp_rule.hpp:105
VOM::gbp_rule::next_hop_set_t::operator==
bool operator==(const next_hop_set_t &nhs) const
Comparison operator.
Definition: gbp_rule.cpp:131
address
manual_print typedef address
Definition: ip_types.api:96
VOM::gbp_rule::~gbp_rule
~gbp_rule()=default
Destructor.
VOM::gbp_rule::next_hop_t::to_string
std::string to_string() const
convert to string
Definition: gbp_rule.cpp:33
nh
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
VOM::gbp_rule::action_t
ACL rule action enum.
Definition: gbp_rule.hpp:192
VOM::gbp_rule::action_t::from_int
static const action_t & from_int(vapi_enum_gbp_rule_action i)
create the action from int value
Definition: gbp_rule.cpp:158
rd_id
u32 rd_id
Definition: gbp.api:35
VOM::gbp_rule::next_hop_t::getRdId
const uint32_t getRdId(void) const
get the route domain Id
Definition: gbp_rule.cpp:76
VOM::gbp_rule::next_hop_t::next_hop_t
next_hop_t(const boost::asio::ip::address &ip, const mac_address_t &mac, uint32_t bd_id, uint32_t rd_id)
Constructor for next_hop_t.
Definition: gbp_rule.cpp:21
VOM::mac_address_t
Type def of a Ethernet address.
Definition: types.hpp:295
a
a
Definition: bitmap.h:525
ip
vl_api_address_t ip
Definition: l2.api:558
i
int i
Definition: flowhash_template.h:376
VOM::gbp_rule::hash_mode_t::from_int
static const hash_mode_t & from_int(vapi_enum_gbp_hash_mode i)
create the hash mode from int value
Definition: gbp_rule.cpp:91
VOM::gbp_rule::next_hop_t
Representation of next hop.
Definition: gbp_rule.hpp:30
VOM::gbp_rule::operator==
bool operator==(const gbp_rule &rule) const
comparison operator (for testing)
Definition: gbp_rule.cpp:191
VOM::gbp_rule::action
const action_t & action() const
Definition: gbp_rule.cpp:210
VOM::gbp_rule::next_hop_t::getIp
const boost::asio::ip::address & getIp(void) const
get the IP address
Definition: gbp_rule.cpp:58
VOM::gbp_rule::hash_mode_t::SRC_IP
const static hash_mode_t SRC_IP
Flow Hash is calculated based on SRC IP in case of load balancing.
Definition: gbp_rule.hpp:111
VOM::gbp_rule::next_hop_t::operator<
bool operator<(const next_hop_t &nh) const
less-than operator
Definition: gbp_rule.cpp:45
VOM::gbp_rule::gbp_rule
gbp_rule(uint32_t priority, const next_hop_set_t &nhs, const action_t &a)
Construct a new object matching the desried state.
Definition: gbp_rule.cpp:168
VOM::gbp_rule::next_hop_set_t::~next_hop_set_t
~next_hop_set_t()=default
Destructor for next_hop_set_t.
string
const char *const string
Definition: cJSON.h:172