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:
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_SUBNET_H__
17 #define __VOM_GBP_SUBNET_H__
21 #include "vom/gbp_endpoint_group.hpp"
22 #include "vom/gbp_recirc.hpp"
23 #include "vom/gbp_route_domain.hpp"
24 #include "vom/singular_db.hpp"
28 * A GBP Enpoint (i.e. a VM)
30 class gbp_subnet : public object_base
34 * The key for a GBP subnet; table and prefix
36 typedef std::pair<gbp_route_domain::key_t, route::prefix_t> key_t;
38 struct type_t : public enum_base<type_t>
41 * Internal subnet is reachable through the source EPG's
44 const static type_t STITCHED_INTERNAL;
47 * External subnet requires NAT translation before egress.
49 const static type_t STITCHED_EXTERNAL;
52 * A transport subnet, sent via the RD's UU-fwd interface
54 const static type_t TRANSPORT;
57 * A transport subnet, sent via the RD's UU-fwd interface
59 const static type_t L3_OUT;
62 type_t(int v, const std::string s);
66 * Construct an internal GBP subnet
68 gbp_subnet(const gbp_route_domain& rd,
69 const route::prefix_t& prefix,
73 * Construct an stitched external GBP subnet
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);
81 * Construct an l3-out GBP subnet
83 gbp_subnet(const gbp_route_domain& rd,
84 const route::prefix_t& prefix,
90 gbp_subnet(const gbp_subnet& r);
98 * Return the object's key
100 const key_t key() const;
103 * comparison operator
105 bool operator==(const gbp_subnet& bdae) const;
108 * Return the matching 'singular instance'
110 std::shared_ptr<gbp_subnet> singular() const;
113 * Find the instnace of the bridge_domain domain in the OM
115 static std::shared_ptr<gbp_subnet> find(const key_t& k);
118 * Dump all bridge_domain-doamin into the stream provided
120 static void dump(std::ostream& os);
123 * replay the object to create it in hardware
128 * Convert to string for debugging
130 std::string to_string() const;
134 * Class definition for listeners to OM events
136 class event_handler : public OM::listener, public inspect::command_handler
140 virtual ~event_handler() = default;
143 * Handle a populate event
145 void handle_populate(const client_db::key_t& key);
148 * Handle a replay event
150 void handle_replay();
153 * Show the object in the Singular DB
155 void show(std::ostream& os);
158 * Get the sortable Id of the listener
160 dependency_t order() const;
164 * event_handler to register with OM
166 static event_handler m_evh;
169 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
171 void update(const gbp_subnet& obj);
174 * Find or add the instnace of the bridge_domain domain in the OM
176 static std::shared_ptr<gbp_subnet> find_or_add(const gbp_subnet& temp);
179 * It's the VPPHW class that updates the objects in HW
184 * It's the singular_db class that calls replay()
186 friend class singular_db<key_t, gbp_subnet>;
189 * Sweep/reap the object if still stale
194 * HW configuration for the result of creating the subnet
199 * the route domain the prefix is in
201 const std::shared_ptr<gbp_route_domain> m_rd;
206 const route::prefix_t m_prefix;
214 * The interface the prefix is reachable through
216 std::shared_ptr<gbp_recirc> m_recirc;
219 * The EPG the subnet is in
221 std::shared_ptr<gbp_endpoint_group> m_epg;
224 * Sclass for l3-out subnets
229 * A map of all bridge_domains
231 static singular_db<key_t, gbp_subnet> m_db;
234 std::ostream& operator<<(std::ostream& os, const gbp_subnet::key_t& key);
239 * fd.io coding-style-patch-verification: ON
242 * eval: (c-set-style "mozilla")