summaryrefslogtreecommitdiffstats
path: root/src/plugins/gbp/gbp_endpoint_group.h
blob: f71e5f5d70bf01f25b29128d2089a72278d8d968 (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
/*
 * 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 __GBP_ENDPOINT_GROUP_H__
#define __GBP_ENDPOINT_GROUP_H__

#include <plugins/gbp/gbp_types.h>

#include <vnet/fib/fib_types.h>

/**
 * An Endpoint Group representation
 */
typedef struct gpb_endpoint_group_t_
{
  /**
   * ID
   */
  epg_id_t gepg_id;

  /**
   * Bridge-domain ID the EPG is in
   */
  u32 gepg_bd;

  /**
   * route-domain/IP-table ID the EPG is in
   */
  u32 gepg_rd[FIB_PROTOCOL_IP_MAX];

  /**
   * resulting FIB indices
   */
  u32 gepg_fib_index[FIB_PROTOCOL_IP_MAX];

  /**
   * Is the EPG an external/NAT
   */
  u8 gepg_is_ext;

  /**
   * the uplink interface dedicated to the EPG
   */
  u32 gepg_uplink_sw_if_index;

  /**
   * The DPO used in the L3 path for forwarding internal subnets
   */
  dpo_id_t gepg_dpo[FIB_PROTOCOL_IP_MAX];
} gbp_endpoint_group_t;

/**
 * EPG DB, key'd on EGP-ID
 */
typedef struct gbp_endpoint_group_db_t_
{
  uword *gepg_hash;
} gbp_endpoint_group_db_t;

extern int gbp_endpoint_group_add (epg_id_t epg_id,
				   u32 bd_id,
				   u32 ip4_table_id,
				   u32 ip6_table_id, u32 uplink_sw_if_index);
extern void gbp_endpoint_group_delete (epg_id_t epg_id);

typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
					void *ctx);
extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);

extern gbp_endpoint_group_t *gbp_endpoint_group_find (epg_id_t epg_id);

/**
 * DP functions and databases
 */
extern gbp_endpoint_group_db_t gbp_endpoint_group_db;
extern gbp_endpoint_group_t *gbp_endpoint_group_pool;

always_inline u32
gbp_epg_itf_lookup (epg_id_t epg)
{
  uword *p;

  p = hash_get (gbp_endpoint_group_db.gepg_hash, epg);

  if (NULL != p)
    {
      gbp_endpoint_group_t *gepg;

      gepg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
      return (gepg->gepg_uplink_sw_if_index);
    }
  return (~0);
}

always_inline const dpo_id_t *
gbp_epg_dpo_lookup (epg_id_t epg, fib_protocol_t fproto)
{
  uword *p;

  p = hash_get (gbp_endpoint_group_db.gepg_hash, epg);

  if (NULL != p)
    {
      gbp_endpoint_group_t *gepg;

      gepg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
      return (&gepg->gepg_dpo[fproto]);
    }
  return (NULL);
}

#endif

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