GBP: per-group EP retention policy
[vpp.git] / extras / vom / vom / gbp_endpoint_group.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_GROUP_H__
17 #define __VOM_GBP_ENDPOINT_GROUP_H__
18
19 #include "vom/interface.hpp"
20 #include "vom/singular_db.hpp"
21 #include "vom/types.hpp"
22
23 #include "vom/gbp_bridge_domain.hpp"
24 #include "vom/gbp_route_domain.hpp"
25
26 namespace VOM {
27
28 /**
29  * EPG IDs are 32 bit integers
30  */
31 typedef uint32_t epg_id_t;
32
33 /**
34  * A entry in the ARP termination table of a Bridge Domain
35  */
36 class gbp_endpoint_group : public object_base
37 {
38 public:
39   /**
40    * Endpoint Retention Policy Settings
41    */
42   struct retention_t
43   {
44     retention_t();
45     retention_t(uint32_t remote_ep_timeout);
46
47     retention_t(const retention_t&) = default;
48     retention_t& operator=(const retention_t&) = default;
49
50     bool operator==(const retention_t& o) const;
51     std::string to_string() const;
52
53     /**
54      * Remote Endpoint timeout/ageing
55      */
56     uint32_t remote_ep_timeout;
57   };
58
59   /**
60    * The key for a GBP endpoint group is its ID
61    */
62   typedef epg_id_t key_t;
63
64   /**
65    * Construct a GBP endpoint_group
66    */
67   gbp_endpoint_group(epg_id_t epg_id,
68                      const interface& itf,
69                      const gbp_route_domain& rd,
70                      const gbp_bridge_domain& bd);
71   gbp_endpoint_group(epg_id_t epg_id,
72                      const gbp_route_domain& rd,
73                      const gbp_bridge_domain& bd);
74   gbp_endpoint_group(epg_id_t epg_id,
75                      uint16_t sclass,
76                      const interface& itf,
77                      const gbp_route_domain& rd,
78                      const gbp_bridge_domain& bd);
79   gbp_endpoint_group(epg_id_t epg_id,
80                      uint16_t sclass,
81                      const gbp_route_domain& rd,
82                      const gbp_bridge_domain& bd);
83
84   /**
85    * Copy Construct
86    */
87   gbp_endpoint_group(const gbp_endpoint_group& r);
88
89   /**
90    * Destructor
91    */
92   ~gbp_endpoint_group();
93
94   /**
95    * Return the object's key
96    */
97   const key_t key() const;
98
99   /**
100    * comparison operator
101    */
102   bool operator==(const gbp_endpoint_group& bdae) const;
103
104   /**
105    * Return the matching 'singular instance'
106    */
107   std::shared_ptr<gbp_endpoint_group> singular() const;
108
109   /**
110    * Find the instnace of the bridge_domain domain in the OM
111    */
112   static std::shared_ptr<gbp_endpoint_group> find(const key_t& k);
113
114   /**
115    * Dump all bridge_domain-doamin into the stream provided
116    */
117   static void dump(std::ostream& os);
118
119   /**
120    * replay the object to create it in hardware
121    */
122   void replay(void);
123
124   /**
125    * Convert to string for debugging
126    */
127   std::string to_string() const;
128
129   /**
130    * Get the ID of the EPG
131    */
132   epg_id_t id() const;
133
134   const std::shared_ptr<gbp_route_domain> get_route_domain() const;
135   const std::shared_ptr<gbp_bridge_domain> get_bridge_domain() const;
136
137   void set(const retention_t& retention);
138
139 private:
140   /**
141    * Class definition for listeners to OM events
142    */
143   class event_handler : public OM::listener, public inspect::command_handler
144   {
145   public:
146     event_handler();
147     virtual ~event_handler() = default;
148
149     /**
150      * Handle a populate event
151      */
152     void handle_populate(const client_db::key_t& key);
153
154     /**
155      * Handle a replay event
156      */
157     void handle_replay();
158
159     /**
160      * Show the object in the Singular DB
161      */
162     void show(std::ostream& os);
163
164     /**
165      * Get the sortable Id of the listener
166      */
167     dependency_t order() const;
168   };
169
170   /**
171    * event_handler to register with OM
172    */
173   static event_handler m_evh;
174
175   /**
176    * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
177    */
178   void update(const gbp_endpoint_group& obj);
179
180   /**
181    * Find or add the instnace of the bridge_domain domain in the OM
182    */
183   static std::shared_ptr<gbp_endpoint_group> find_or_add(
184     const gbp_endpoint_group& temp);
185
186   /*
187    * It's the VPPHW class that updates the objects in HW
188    */
189   friend class OM;
190
191   /**
192    * It's the singular_db class that calls replay()
193    */
194   friend class singular_db<key_t, gbp_endpoint_group>;
195
196   /**
197    * Sweep/reap the object if still stale
198    */
199   void sweep(void);
200
201   /**
202    * HW configuration for the result of creating the endpoint_group
203    */
204   HW::item<bool> m_hw;
205
206   /**
207    * The EPG ID
208    */
209   epg_id_t m_epg_id;
210
211   /**
212    * The SClass on the wire
213    */
214   uint16_t m_sclass;
215
216   /**
217    * The uplink interface for the endpoint group
218    */
219   std::shared_ptr<interface> m_itf;
220
221   /**
222    * The route-domain the EPG uses
223    */
224   std::shared_ptr<gbp_route_domain> m_rd;
225
226   /**
227    * The bridge-domain the EPG uses
228    */
229   std::shared_ptr<gbp_bridge_domain> m_bd;
230
231   /**
232    * The Group's EP retention Policy
233    */
234   retention_t m_retention;
235
236   /**
237    * A map of all bridge_domains
238    */
239   static singular_db<key_t, gbp_endpoint_group> m_db;
240 };
241
242 }; // namespace
243
244 /*
245  * fd.io coding-style-patch-verification: ON
246  *
247  * Local Variables:
248  * eval: (c-set-style "mozilla")
249  * End:
250  */
251
252 #endif