aboutsummaryrefslogtreecommitdiffstats
path: root/extras/deprecated/vom/vom/gbp_rule.hpp
blob: 1871e7e14a67d0e35e84e60c184f07862287bdfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __VOM_GBP_RULE_H__
#define __VOM_GBP_RULE_H__

#include <set>

#include "vom/types.hpp"
#include <vapi/gbp.api.vapi.h>
namespace VOM {
class gbp_rule
{
public:
  /**
   * Representation of next hop
   */
  struct next_hop_t
  {
    /**
     * Constructor for 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);

    /**
     * default destructor
     */
    ~next_hop_t() = default;

    /**
     * convert to string
     */
    std::string to_string() const;

    /**
     * less-than operator
     */
    bool operator<(const next_hop_t& nh) const;

    /**
     * comparison operator (for testing)
     */
    bool operator==(const next_hop_t& nh) const;

    /**
     * get the IP address
     */
    const boost::asio::ip::address& getIp(void) const;

    /**
     * get the mac address
     */
    const mac_address_t& getMac(void) const;

    /**
     * get the bridge domain Id
     */
    const uint32_t getBdId(void) const;

    /**
     * get the route domain Id
     */
    const uint32_t getRdId(void) const;

  private:
    /**
     * IP address for next hop
     */
    const boost::asio::ip::address m_ip;

    /**
     * mac address for interface lookup
     */
    const mac_address_t m_mac;

    /**
     * bridge domain in which redirected endpoints exist
     */
    const uint32_t m_bd_id;

    /**
     * route domain in which redirected endpoints exist
     */
    const uint32_t m_rd_id;
  };

  /**
   * hash mode enum
   */
  struct hash_mode_t : public enum_base<hash_mode_t>
  {
    /**
     * Flow Hash is calculated based on SRC IP
     * in case of load balancing
     */
    const static hash_mode_t SRC_IP;

    /**
     * Flow hash is calculated based on DST IP
     */
    const static hash_mode_t DST_IP;

    /**
     * Flow hash is calculated based on SRC IP,
     * DST IP and Protocol. SRC IP and DST IP
     * addresses are sorted before hash such that
     * a same hash is generated in both directions.
     */
    const static hash_mode_t SYMMETRIC;

    /**
     * create the hash mode from int value
     */
    static const hash_mode_t& from_int(vapi_enum_gbp_hash_mode i);

  private:
    hash_mode_t(int v, const std::string s);
  };

  /**
   * unordered set of next hops
   */
  typedef std::set<next_hop_t> next_hops_t;

  /**
   * Representation of set of next hops and
   * associated hash mode profile
   */
  struct next_hop_set_t
  {
    /**
     * Constructor for next_hop_set_t
     */
    next_hop_set_t(const hash_mode_t& hm, next_hops_t& nhs);
    next_hop_set_t(const hash_mode_t& hm = hash_mode_t::SYMMETRIC);

    /**
     * Destructor for next_hop_set_t
     */
    ~next_hop_set_t() = default;

    /**
     * convert to string
     */
    std::string to_string() const;

    /**
     * Comparison operator
     */
    bool operator==(const next_hop_set_t& nhs) const;

    /**
     * get the hash mode
     */
    const hash_mode_t& hash_mode(void) const;

    /**
     * get the set of next hops
     */
    const next_hops_t& next_hops(void) const;

  private:
    /**
     * hash mode for this rule
     */
    const hash_mode_t m_hm;

    /**
     * set of next hops
     */
    const next_hops_t m_nhs;
  };

  /**
   * ACL rule action enum
   */
  struct action_t : public enum_base<action_t>
  {
    /**
     * Permit action
     */
    const static action_t PERMIT;

    /**
     * Deny action
     */
    const static action_t DENY;

    /**
     * Redirect action
     */
    const static action_t REDIRECT;

    /**
     * create the action from int value
     */
    static const action_t& from_int(vapi_enum_gbp_rule_action i);

  private:
    action_t(int v, const std::string s);
  };

  /**
   * Construct a new object matching the desried state
   */
  gbp_rule(uint32_t priority, const next_hop_set_t& nhs, const action_t& a);
  gbp_rule(uint32_t priority, const action_t& a);

  /**
   * Copy Constructor
   */
  gbp_rule(const gbp_rule& o) = default;

  /**
   * Destructor
   */
  ~gbp_rule() = default;

  /**
   * convert to string format for debug purposes
   */
  std::string to_string() const;

  /**
  * less-than operator
  */
  bool operator<(const gbp_rule& rule) const;

  /**
   * comparison operator (for testing)
   */
  bool operator==(const gbp_rule& rule) const;

  /**
   * Getters
   */
  const next_hop_set_t& nhs() const;
  const action_t& action() const;

private:
  /**
   * Priority. Used to sort the rules in a list in the order
   * in which they are applied
   */
  uint32_t m_priority;

  /**
   * set of next hops along with hash mode profile
   */
  const next_hop_set_t m_nhs;

  /**
   * Action on match
   */
  const action_t m_action;
};
};

/*
 * fd.io coding-style-patch-verification: OFF
 *
 * Local Variables:
 * eval: (c-set-style "mozilla")
 * End:
 */

#endif