FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
gbp_subnet.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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_SUBNET_H__
17 #define __VOM_GBP_SUBNET_H__
18 
19 #include <ostream>
20 
22 #include "vom/gbp_recirc.hpp"
23 #include "vom/gbp_route_domain.hpp"
24 #include "vom/singular_db.hpp"
25 
26 namespace VOM {
27 /**
28  * A GBP Enpoint (i.e. a VM)
29  */
30 class gbp_subnet : public object_base
31 {
32 public:
33  /**
34  * The key for a GBP subnet; table and prefix
35  */
36  typedef std::pair<gbp_route_domain::key_t, route::prefix_t> key_t;
37 
38  struct type_t : public enum_base<type_t>
39  {
40  /**
41  * Internal subnet is reachable through the source EPG's
42  * uplink interface.
43  */
44  const static type_t STITCHED_INTERNAL;
45 
46  /**
47  * External subnet requires NAT translation before egress.
48  */
49  const static type_t STITCHED_EXTERNAL;
50 
51  /**
52  * A transport subnet, sent via the RD's UU-fwd interface
53  */
54  const static type_t TRANSPORT;
55 
56  /**
57  * A transport subnet, sent via the RD's UU-fwd interface
58  */
59  const static type_t L3_OUT;
60 
61  private:
62  type_t(int v, const std::string s);
63  };
64 
65  /**
66  * Construct an internal GBP subnet
67  */
68  gbp_subnet(const gbp_route_domain& rd,
69  const route::prefix_t& prefix,
70  const type_t& type);
71 
72  /**
73  * Construct an stitched external GBP subnet
74  */
75  gbp_subnet(const gbp_route_domain& rd,
76  const route::prefix_t& prefix,
77  const gbp_recirc& recirc,
78  const gbp_endpoint_group& epg);
79 
80  /**
81  * Construct an l3-out GBP subnet
82  */
83  gbp_subnet(const gbp_route_domain& rd,
84  const route::prefix_t& prefix,
86 
87  /**
88  * Copy Construct
89  */
90  gbp_subnet(const gbp_subnet& r);
91 
92  /**
93  * Destructor
94  */
95  ~gbp_subnet();
96 
97  /**
98  * Return the object's key
99  */
100  const key_t key() const;
101 
102  /**
103  * comparison operator
104  */
105  bool operator==(const gbp_subnet& bdae) const;
106 
107  /**
108  * Return the matching 'singular instance'
109  */
110  std::shared_ptr<gbp_subnet> singular() const;
111 
112  /**
113  * Find the instnace of the bridge_domain domain in the OM
114  */
115  static std::shared_ptr<gbp_subnet> find(const key_t& k);
116 
117  /**
118  * Dump all bridge_domain-doamin into the stream provided
119  */
120  static void dump(std::ostream& os);
121 
122  /**
123  * replay the object to create it in hardware
124  */
125  void replay(void);
126 
127  /**
128  * Convert to string for debugging
129  */
130  std::string to_string() const;
131 
132 private:
133  /**
134  * Class definition for listeners to OM events
135  */
137  {
138  public:
139  event_handler();
140  virtual ~event_handler() = default;
141 
142  /**
143  * Handle a populate event
144  */
145  void handle_populate(const client_db::key_t& key);
146 
147  /**
148  * Handle a replay event
149  */
150  void handle_replay();
151 
152  /**
153  * Show the object in the Singular DB
154  */
155  void show(std::ostream& os);
156 
157  /**
158  * Get the sortable Id of the listener
159  */
160  dependency_t order() const;
161  };
162 
163  /**
164  * event_handler to register with OM
165  */
166  static event_handler m_evh;
167 
168  /**
169  * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
170  */
171  void update(const gbp_subnet& obj);
172 
173  /**
174  * Find or add the instnace of the bridge_domain domain in the OM
175  */
176  static std::shared_ptr<gbp_subnet> find_or_add(const gbp_subnet& temp);
177 
178  /*
179  * It's the VPPHW class that updates the objects in HW
180  */
181  friend class OM;
182 
183  /**
184  * It's the singular_db class that calls replay()
185  */
186  friend class singular_db<key_t, gbp_subnet>;
187 
188  /**
189  * Sweep/reap the object if still stale
190  */
191  void sweep(void);
192 
193  /**
194  * HW configuration for the result of creating the subnet
195  */
196  HW::item<bool> m_hw;
197 
198  /**
199  * the route domain the prefix is in
200  */
201  const std::shared_ptr<gbp_route_domain> m_rd;
202 
203  /**
204  * prefix to match
205  */
206  const route::prefix_t m_prefix;
207 
208  /*
209  * Subnet type
210  */
211  type_t m_type;
212 
213  /**
214  * The interface the prefix is reachable through
215  */
216  std::shared_ptr<gbp_recirc> m_recirc;
217 
218  /**
219  * The EPG the subnet is in
220  */
221  std::shared_ptr<gbp_endpoint_group> m_epg;
222 
223  /**
224  * Sclass for l3-out subnets
225  */
226  sclass_t m_sclass;
227 
228  /**
229  * A map of all bridge_domains
230  */
231  static singular_db<key_t, gbp_subnet> m_db;
232 };
233 
234 std::ostream& operator<<(std::ostream& os, const gbp_subnet::key_t& key);
235 
236 }; // namespace
237 
238 /*
239  * fd.io coding-style-patch-verification: ON
240  *
241  * Local Variables:
242  * eval: (c-set-style "mozilla")
243  * End:
244  */
245 
246 #endif
uint16_t sclass_t
A template base class for all enum types.
Definition: enum_base.hpp:30
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
static const type_t TRANSPORT
A transport subnet, sent via the RD&#39;s UU-fwd interface.
Definition: gbp_subnet.hpp:54
bool operator==(const enum_base &e) const
Comparison operator.
Definition: enum_base.hpp:41
std::shared_ptr< gbp_subnet > singular() const
Return the matching &#39;singular instance&#39;.
Definition: gbp_subnet.cpp:183
void replay(void)
replay the object to create it in hardware
Definition: gbp_subnet.cpp:122
static const type_t STITCHED_INTERNAL
Internal subnet is reachable through the source EPG&#39;s uplink interface.
Definition: gbp_subnet.hpp:44
~gbp_subnet()
Destructor.
Definition: gbp_subnet.cpp:92
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: gbp_subnet.cpp:189
u16 sclass
Definition: gbp.api:118
static std::shared_ptr< gbp_subnet > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: gbp_subnet.cpp:177
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
A recirculation interface for GBP use pre/post NAT.
Definition: gbp_recirc.hpp:27
A GBP Enpoint (i.e.
Definition: gbp_subnet.hpp:30
std::pair< gbp_route_domain::key_t, route::prefix_t > key_t
The key for a GBP subnet; table and prefix.
Definition: gbp_subnet.hpp:36
gbp_subnet(const gbp_route_domain &rd, const route::prefix_t &prefix, const type_t &type)
Construct an internal GBP subnet.
Definition: gbp_subnet.cpp:41
static const type_t STITCHED_EXTERNAL
External subnet requires NAT translation before egress.
Definition: gbp_subnet.hpp:49
A entry in the ARP termination table of a Bridge Domain.
Class definition for listeners to OM events.
Definition: om.hpp:284
inspect command handler Handler
Definition: inspect.hpp:54
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
void event_handler(void *tls_async)
Definition: tls_async.c:340
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
The interface to writing objects into VPP OM.
Definition: om.hpp:140
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
A entry in the ARP termination table of a Route Domain.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
typedef prefix
Definition: ip_types.api:35
static const type_t L3_OUT
A transport subnet, sent via the RD&#39;s UU-fwd interface.
Definition: gbp_subnet.hpp:59
A prefix defintion.
Definition: prefix.hpp:92
const key_t key() const
Return the object&#39;s key.
Definition: gbp_subnet.cpp:99