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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_GBP_RULE_H__
17 #define __VOM_GBP_RULE_H__
21 #include "vom/types.hpp"
22 #include <vapi/gbp.api.vapi.h>
28 * Representation of next hop
33 * Constructor for next_hop_t
35 next_hop_t(const boost::asio::ip::address& ip,
36 const mac_address_t& mac,
43 ~next_hop_t() = default;
48 std::string to_string() const;
53 bool operator<(const next_hop_t& nh) const;
56 * comparison operator (for testing)
58 bool operator==(const next_hop_t& nh) const;
63 const boost::asio::ip::address& getIp(void) const;
68 const mac_address_t& getMac(void) const;
71 * get the bridge domain Id
73 const uint32_t getBdId(void) const;
76 * get the route domain Id
78 const uint32_t getRdId(void) const;
82 * IP address for next hop
84 const boost::asio::ip::address m_ip;
87 * mac address for interface lookup
89 const mac_address_t m_mac;
92 * bridge domain in which redirected endpoints exist
94 const uint32_t m_bd_id;
97 * route domain in which redirected endpoints exist
99 const uint32_t m_rd_id;
105 struct hash_mode_t : public enum_base<hash_mode_t>
108 * Flow Hash is calculated based on SRC IP
109 * in case of load balancing
111 const static hash_mode_t SRC_IP;
114 * Flow hash is calculated based on DST IP
116 const static hash_mode_t DST_IP;
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.
124 const static hash_mode_t SYMMETRIC;
127 * create the hash mode from int value
129 static const hash_mode_t& from_int(vapi_enum_gbp_hash_mode i);
132 hash_mode_t(int v, const std::string s);
136 * unordered set of next hops
138 typedef std::set<next_hop_t> next_hops_t;
141 * Representation of set of next hops and
142 * associated hash mode profile
144 struct next_hop_set_t
147 * Constructor for next_hop_set_t
149 next_hop_set_t(const hash_mode_t& hm, next_hops_t& nhs);
150 next_hop_set_t(const hash_mode_t& hm = hash_mode_t::SYMMETRIC);
153 * Destructor for next_hop_set_t
155 ~next_hop_set_t() = default;
160 std::string to_string() const;
163 * Comparison operator
165 bool operator==(const next_hop_set_t& nhs) const;
170 const hash_mode_t& hash_mode(void) const;
173 * get the set of next hops
175 const next_hops_t& next_hops(void) const;
179 * hash mode for this rule
181 const hash_mode_t m_hm;
186 const next_hops_t m_nhs;
190 * ACL rule action enum
192 struct action_t : public enum_base<action_t>
197 const static action_t PERMIT;
202 const static action_t DENY;
207 const static action_t REDIRECT;
210 * create the action from int value
212 static const action_t& from_int(vapi_enum_gbp_rule_action i);
215 action_t(int v, const std::string s);
219 * Construct a new object matching the desried state
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);
227 gbp_rule(const gbp_rule& o) = default;
232 ~gbp_rule() = default;
235 * convert to string format for debug purposes
237 std::string to_string() const;
242 bool operator<(const gbp_rule& rule) const;
245 * comparison operator (for testing)
247 bool operator==(const gbp_rule& rule) const;
252 const next_hop_set_t& nhs() const;
253 const action_t& action() const;
257 * Priority. Used to sort the rules in a list in the order
258 * in which they are applied
263 * set of next hops along with hash mode profile
265 const next_hop_set_t m_nhs;
270 const action_t m_action;
275 * fd.io coding-style-patch-verification: ON
278 * eval: (c-set-style "mozilla")