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;
59 const static type_t L3_OUT;
62 * An anonymous L3-out subnet
64 const static type_t ANON_L3_OUT;
67 type_t(int v, const std::string s);
71 * Construct an internal GBP subnet
73 gbp_subnet(const gbp_route_domain& rd,
74 const route::prefix_t& prefix,
78 * Construct an stitched external GBP subnet
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);
86 * Construct an l3-out GBP subnet
88 gbp_subnet(const gbp_route_domain& rd,
89 const route::prefix_t& prefix,
91 const type_t& type = type_t::L3_OUT);
96 gbp_subnet(const gbp_subnet& r);
104 * Return the object's key
106 const key_t key() const;
109 * comparison operator
111 bool operator==(const gbp_subnet& bdae) const;
114 * Return the matching 'singular instance'
116 std::shared_ptr<gbp_subnet> singular() const;
119 * Find the instnace of the bridge_domain domain in the OM
121 static std::shared_ptr<gbp_subnet> find(const key_t& k);
124 * Dump all bridge_domain-doamin into the stream provided
126 static void dump(std::ostream& os);
129 * replay the object to create it in hardware
134 * Convert to string for debugging
136 std::string to_string() const;
140 * Class definition for listeners to OM events
142 class event_handler : public OM::listener, public inspect::command_handler
146 virtual ~event_handler() = default;
149 * Handle a populate event
151 void handle_populate(const client_db::key_t& key);
154 * Handle a replay event
156 void handle_replay();
159 * Show the object in the Singular DB
161 void show(std::ostream& os);
164 * Get the sortable Id of the listener
166 dependency_t order() const;
170 * event_handler to register with OM
172 static event_handler m_evh;
175 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
177 void update(const gbp_subnet& obj);
180 * Find or add the instnace of the bridge_domain domain in the OM
182 static std::shared_ptr<gbp_subnet> find_or_add(const gbp_subnet& temp);
185 * It's the VPPHW class that updates the objects in HW
190 * It's the singular_db class that calls replay()
192 friend class singular_db<key_t, gbp_subnet>;
195 * Sweep/reap the object if still stale
200 * HW configuration for the result of creating the subnet
205 * the route domain the prefix is in
207 const std::shared_ptr<gbp_route_domain> m_rd;
212 const route::prefix_t m_prefix;
220 * The interface the prefix is reachable through
222 std::shared_ptr<gbp_recirc> m_recirc;
225 * The EPG the subnet is in
227 std::shared_ptr<gbp_endpoint_group> m_epg;
230 * Sclass for l3-out subnets
235 * A map of all bridge_domains
237 static singular_db<key_t, gbp_subnet> m_db;
240 std::ostream& operator<<(std::ostream& os, const gbp_subnet::key_t& key);
245 * fd.io coding-style-patch-verification: ON
248 * eval: (c-set-style "mozilla")