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_ENDPOINT_H__
17 #define __VOM_GBP_ENDPOINT_H__
22 #include "vom/gbp_endpoint_group.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/singular_db.hpp"
28 * A GBP Enpoint (i.e. a VM)
30 class gbp_endpoint : public object_base
36 struct flags_t : enum_base<flags_t>
38 const static flags_t NONE;
39 const static flags_t BOUNCE;
40 const static flags_t REMOTE;
41 const static flags_t LEARNT;
42 const static flags_t EXTERNAL;
46 * Private constructor taking the value and the string name
48 flags_t(int v, const std::string& s);
52 * The key for a GBP endpoint; interface and IP
54 typedef std::pair<interface::key_t, mac_address_t> key_t;
57 * Construct a GBP endpoint
59 gbp_endpoint(const interface& itf,
60 const std::vector<boost::asio::ip::address>& ip_addr,
61 const mac_address_t& mac,
62 const gbp_endpoint_group& epg,
63 const flags_t& flags = flags_t::NONE);
68 gbp_endpoint(const gbp_endpoint& r);
76 * Return the object's key
78 const key_t key() const;
83 bool operator==(const gbp_endpoint& bdae) const;
86 * Return the matching 'singular instance'
88 std::shared_ptr<gbp_endpoint> singular() const;
91 * Find the instnace of the bridge_domain domain in the OM
93 static std::shared_ptr<gbp_endpoint> find(const key_t& k);
96 * Dump all bridge_domain-doamin into the stream provided
98 static void dump(std::ostream& os);
101 * replay the object to create it in hardware
106 * Convert to string for debugging
108 std::string to_string() const;
112 * Class definition for listeners to OM events
114 class event_handler : public OM::listener, public inspect::command_handler
118 virtual ~event_handler() = default;
121 * Handle a populate event
123 void handle_populate(const client_db::key_t& key);
126 * Handle a replay event
128 void handle_replay();
131 * Show the object in the Singular DB
133 void show(std::ostream& os);
136 * Get the sortable Id of the listener
138 dependency_t order() const;
142 * event_handler to register with OM
144 static event_handler m_evh;
147 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
149 void update(const gbp_endpoint& obj);
152 * Find or add the instnace of the bridge_domain domain in the OM
154 static std::shared_ptr<gbp_endpoint> find_or_add(const gbp_endpoint& temp);
157 * It's the VPPHW class that updates the objects in HW
162 * It's the singular_db class that calls replay()
164 friend class singular_db<key_t, gbp_endpoint>;
167 * Sweep/reap the object if still stale
172 * HW configuration for the result of creating the endpoint
174 HW::item<handle_t> m_hdl;
177 * The interface the endpoint is attached to.
179 std::shared_ptr<interface> m_itf;
182 * The IP address of the endpoint
184 std::vector<boost::asio::ip::address> m_ips;
187 * The MAC address of the endpoint
192 * The EPG the endpoint is in
194 std::shared_ptr<gbp_endpoint_group> m_epg;
202 * A map of all bridge_domains
204 static singular_db<key_t, gbp_endpoint> m_db;
207 std::ostream& operator<<(std::ostream& os, const gbp_endpoint::key_t& key);
211 * fd.io coding-style-patch-verification: ON
214 * eval: (c-set-style "mozilla")