vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / gbp_endpoint.hpp
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_ENDPOINT_H__
17 #define __VOM_GBP_ENDPOINT_H__
18
19 #include <ostream>
20 #include <vector>
21
22 #include "vom/gbp_endpoint_group.hpp"
23 #include "vom/interface.hpp"
24 #include "vom/singular_db.hpp"
25
26 namespace VOM {
27 /**
28  * A GBP Enpoint (i.e. a VM)
29  */
30 class gbp_endpoint : public object_base
31 {
32 public:
33   /**
34    * Endpoint flags
35    */
36   struct flags_t : enum_base<flags_t>
37   {
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;
43
44   private:
45     /**
46      * Private constructor taking the value and the string name
47      */
48     flags_t(int v, const std::string& s);
49   };
50
51   /**
52    * The key for a GBP endpoint; interface and IP
53    */
54   typedef std::pair<interface::key_t, mac_address_t> key_t;
55
56   /**
57    * Construct a GBP endpoint
58    */
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);
64
65   /**
66    * Copy Construct
67    */
68   gbp_endpoint(const gbp_endpoint& r);
69
70   /**
71    * Destructor
72    */
73   ~gbp_endpoint();
74
75   /**
76    * Return the object's key
77    */
78   const key_t key() const;
79
80   /**
81    * comparison operator
82    */
83   bool operator==(const gbp_endpoint& bdae) const;
84
85   /**
86    * Return the matching 'singular instance'
87    */
88   std::shared_ptr<gbp_endpoint> singular() const;
89
90   /**
91    * Find the instnace of the bridge_domain domain in the OM
92    */
93   static std::shared_ptr<gbp_endpoint> find(const key_t& k);
94
95   /**
96    * Dump all bridge_domain-doamin into the stream provided
97    */
98   static void dump(std::ostream& os);
99
100   /**
101    * replay the object to create it in hardware
102    */
103   void replay(void);
104
105   /**
106    * Convert to string for debugging
107    */
108   std::string to_string() const;
109
110 private:
111   /**
112    * Class definition for listeners to OM events
113    */
114   class event_handler : public OM::listener, public inspect::command_handler
115   {
116   public:
117     event_handler();
118     virtual ~event_handler() = default;
119
120     /**
121      * Handle a populate event
122      */
123     void handle_populate(const client_db::key_t& key);
124
125     /**
126      * Handle a replay event
127      */
128     void handle_replay();
129
130     /**
131      * Show the object in the Singular DB
132      */
133     void show(std::ostream& os);
134
135     /**
136      * Get the sortable Id of the listener
137      */
138     dependency_t order() const;
139   };
140
141   /**
142    * event_handler to register with OM
143    */
144   static event_handler m_evh;
145
146   /**
147    * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
148    */
149   void update(const gbp_endpoint& obj);
150
151   /**
152    * Find or add the instnace of the bridge_domain domain in the OM
153    */
154   static std::shared_ptr<gbp_endpoint> find_or_add(const gbp_endpoint& temp);
155
156   /*
157    * It's the VPPHW class that updates the objects in HW
158    */
159   friend class OM;
160
161   /**
162    * It's the singular_db class that calls replay()
163    */
164   friend class singular_db<key_t, gbp_endpoint>;
165
166   /**
167    * Sweep/reap the object if still stale
168    */
169   void sweep(void);
170
171   /**
172    * HW configuration for the result of creating the endpoint
173    */
174   HW::item<handle_t> m_hdl;
175
176   /**
177    * The interface the endpoint is attached to.
178    */
179   std::shared_ptr<interface> m_itf;
180
181   /**
182    * The IP address of the endpoint
183    */
184   std::vector<boost::asio::ip::address> m_ips;
185
186   /**
187    * The MAC address of the endpoint
188    */
189   mac_address_t m_mac;
190
191   /**
192    * The EPG the endpoint is in
193    */
194   std::shared_ptr<gbp_endpoint_group> m_epg;
195
196   /**
197    * Endpoint flags
198    */
199   flags_t m_flags;
200
201   /**
202    * A map of all bridge_domains
203    */
204   static singular_db<key_t, gbp_endpoint> m_db;
205 };
206
207 std::ostream& operator<<(std::ostream& os, const gbp_endpoint::key_t& key);
208 }; // namespace
209
210 /*
211  * fd.io coding-style-patch-verification: ON
212  *
213  * Local Variables:
214  * eval: (c-set-style "mozilla")
215  * End:
216  */
217
218 #endif