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__
19 #include "vom/gbp_endpoint_group.hpp"
20 #include "vom/gbp_recirc.hpp"
21 #include "vom/route.hpp"
22 #include "vom/singular_db.hpp"
26 * A GBP Enpoint (i.e. a VM)
28 class gbp_subnet : public object_base
32 * The key for a GBP subnet; table and prefix
34 typedef std::pair<route_domain::key_t, route::prefix_t> key_t;
37 * Construct an internal GBP subnet
39 gbp_subnet(const route_domain& rd, const route::prefix_t& prefix);
42 * Construct an external GBP subnet
44 gbp_subnet(const route_domain& rd,
45 const route::prefix_t& prefix,
46 const gbp_recirc& recirc,
47 const gbp_endpoint_group& epg);
52 gbp_subnet(const gbp_subnet& r);
60 * Return the object's key
62 const key_t key() const;
67 bool operator==(const gbp_subnet& bdae) const;
70 * Return the matching 'singular instance'
72 std::shared_ptr<gbp_subnet> singular() const;
75 * Find the instnace of the bridge_domain domain in the OM
77 static std::shared_ptr<gbp_subnet> find(const key_t& k);
80 * Dump all bridge_domain-doamin into the stream provided
82 static void dump(std::ostream& os);
85 * replay the object to create it in hardware
90 * Convert to string for debugging
92 std::string to_string() const;
95 struct type_t : public enum_base<type_t>
98 * Internal subnet is reachable through the source EPG's
101 const static type_t INTERNAL;
104 * External subnet requires NAT translation before egress.
106 const static type_t EXTERNAL;
109 type_t(int v, const std::string s);
113 * Class definition for listeners to OM events
115 class event_handler : public OM::listener, public inspect::command_handler
119 virtual ~event_handler() = default;
122 * Handle a populate event
124 void handle_populate(const client_db::key_t& key);
127 * Handle a replay event
129 void handle_replay();
132 * Show the object in the Singular DB
134 void show(std::ostream& os);
137 * Get the sortable Id of the listener
139 dependency_t order() const;
143 * event_handler to register with OM
145 static event_handler m_evh;
148 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
150 void update(const gbp_subnet& obj);
153 * Find or add the instnace of the bridge_domain domain in the OM
155 static std::shared_ptr<gbp_subnet> find_or_add(const gbp_subnet& temp);
158 * It's the VPPHW class that updates the objects in HW
163 * It's the singular_db class that calls replay()
165 friend class singular_db<key_t, gbp_subnet>;
168 * Sweep/reap the object if still stale
173 * HW configuration for the result of creating the subnet
178 * the route domain the prefix is in
180 const std::shared_ptr<route_domain> m_rd;
185 const route::prefix_t m_prefix;
193 * The interface the prefix is reachable through
195 std::shared_ptr<gbp_recirc> m_recirc;
198 * The EPG the subnet is in
200 std::shared_ptr<gbp_endpoint_group> m_epg;
203 * A map of all bridge_domains
205 static singular_db<key_t, gbp_subnet> m_db;
211 * fd.io coding-style-patch-verification: ON
214 * eval: (c-set-style "mozilla")