FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_rule.cpp
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 #include <sstream>
17 
18 #include "vom/gbp_rule.hpp"
19 
20 namespace VOM {
22  const mac_address_t& mac,
23  uint32_t bd_id,
24  uint32_t rd_id)
25  : m_ip(ip)
26  , m_mac(mac)
27  , m_bd_id(bd_id)
28  , m_rd_id(rd_id)
29 {
30 }
31 
34 {
35  std::ostringstream s;
36 
37  s << "["
38  << "ip:" << m_ip << " mac:" << m_mac.to_string() << " bd:" << m_bd_id
39  << " rd:" << m_rd_id << "]";
40 
41  return (s.str());
42 }
43 
44 bool
46 {
47  return (nh.m_ip < m_ip);
48 }
49 
50 bool
52 {
53  return ((m_ip == nh.m_ip) && (m_mac == nh.m_mac) && (m_bd_id == nh.m_bd_id) &&
54  (m_rd_id == nh.m_rd_id));
55 }
56 
59 {
60  return m_ip;
61 }
62 
63 const mac_address_t&
65 {
66  return m_mac;
67 }
68 
69 const uint32_t
71 {
72  return m_bd_id;
73 }
74 
75 const uint32_t
77 {
78  return m_rd_id;
79 }
80 
84 
85 gbp_rule::hash_mode_t::hash_mode_t(int v, const std::string s)
86  : enum_base(v, s)
87 {
88 }
89 
91 gbp_rule::hash_mode_t::from_int(vapi_enum_gbp_hash_mode i)
92 {
95  else if (i == GBP_API_HASH_MODE_SRC_IP)
97 
99 }
100 
103  : m_hm(hm)
104  , m_nhs(nhs)
105 {
106 }
107 
109  : m_hm(hm)
110  , m_nhs()
111 {
112 }
113 
116 {
117  std::ostringstream s;
118 
119  s << "hash-mode:" << m_hm.to_string() << " next-hops:[";
120  auto it = m_nhs.cbegin();
121  while (it != m_nhs.cend()) {
122  s << " " << it->to_string();
123  ++it;
124  }
125  s << " ] next-hop-size:" << m_nhs.size();
126 
127  return (s.str());
128 }
129 
130 bool
132 {
133  return ((m_hm == nhs.m_hm) && (m_nhs == nhs.m_nhs));
134 }
135 
138 {
139  return m_hm;
140 }
141 
144 {
145  return m_nhs;
146 }
147 
151 
152 gbp_rule::action_t::action_t(int v, const std::string s)
153  : enum_base(v, s)
154 {
155 }
156 
157 const gbp_rule::action_t&
158 gbp_rule::action_t::from_int(vapi_enum_gbp_rule_action i)
159 {
160  if (i == GBP_API_RULE_REDIRECT)
162  else if (i == GBP_API_RULE_PERMIT)
164 
166 }
167 
170  const gbp_rule::action_t& a)
171  : m_priority(priority)
172  , m_nhs(nhs)
173  , m_action(a)
174 {
175 }
176 
178  : m_priority(priority)
179  , m_nhs()
180  , m_action(a)
181 {
182 }
183 
184 bool
185 gbp_rule::operator<(const gbp_rule& other) const
186 {
187  return (other.m_priority < m_priority);
188 }
189 
190 bool
191 gbp_rule::operator==(const gbp_rule& rule) const
192 {
193  return ((m_action == rule.m_action) && (m_nhs == rule.m_nhs) &&
194  (m_priority == rule.m_priority));
195 }
196 
199 {
200  std::ostringstream s;
201 
202  s << "gbp-rule:["
203  << "priority:" << m_priority << " action:" << m_action.to_string()
204  << " next-hop-set:[" << m_nhs.to_string() << "]]";
205 
206  return (s.str());
207 }
208 
209 const gbp_rule::action_t&
211 {
212  return m_action;
213 }
214 
217 {
218  return m_nhs;
219 }
220 }; // namespace VOM
221 
222 /*
223  * fd.io coding-style-patch-verification: OFF
224  *
225  * Local Variables:
226  * eval: (c-set-style "mozilla")
227  * End:
228  */
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
GBP_API_RULE_REDIRECT
@ GBP_API_RULE_REDIRECT
Definition: gbp.api:320
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
GBP_API_HASH_MODE_SRC_IP
@ GBP_API_HASH_MODE_SRC_IP
Definition: gbp.api:304
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
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
GBP_API_HASH_MODE_SYMMETRIC
@ GBP_API_HASH_MODE_SYMMETRIC
Definition: gbp.api:306
bd_id
u32 bd_id
Definition: gbp.api:188
priority
i32 priority
Definition: ipsec.api:95
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::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
it
save_rewrite_length must be aligned so that reass doesn t overwrite it
Definition: buffer.h:425
gbp_rule.hpp
GBP_API_RULE_PERMIT
@ GBP_API_RULE_PERMIT
Definition: gbp.api:318
VOM::gbp_rule::action_t
ACL rule action enum.
Definition: gbp_rule.hpp:192
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
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
string
const char *const string
Definition: cJSON.h:172