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