GBP: Sclass to src-epg conversions
[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    * The key for a GBP endpoint group is its ID
41    */
42   typedef epg_id_t key_t;
43
44   /**
45    * Construct a GBP endpoint_group
46    */
47   gbp_endpoint_group(epg_id_t epg_id,
48                      const interface& itf,
49                      const gbp_route_domain& rd,
50                      const gbp_bridge_domain& bd);
51   gbp_endpoint_group(epg_id_t epg_id,
52                      const gbp_route_domain& rd,
53                      const gbp_bridge_domain& bd);
54   gbp_endpoint_group(epg_id_t epg_id,
55                      uint16_t sclass,
56                      const interface& itf,
57                      const gbp_route_domain& rd,
58                      const gbp_bridge_domain& bd);
59   gbp_endpoint_group(epg_id_t epg_id,
60                      uint16_t sclass,
61                      const gbp_route_domain& rd,
62                      const gbp_bridge_domain& bd);
63
64   /**
65    * Copy Construct
66    */
67   gbp_endpoint_group(const gbp_endpoint_group& r);
68
69   /**
70    * Destructor
71    */
72   ~gbp_endpoint_group();
73
74   /**
75    * Return the object's key
76    */
77   const key_t key() const;
78
79   /**
80    * comparison operator
81    */
82   bool operator==(const gbp_endpoint_group& bdae) const;
83
84   /**
85    * Return the matching 'singular instance'
86    */
87   std::shared_ptr<gbp_endpoint_group> singular() const;
88
89   /**
90    * Find the instnace of the bridge_domain domain in the OM
91    */
92   static std::shared_ptr<gbp_endpoint_group> find(const key_t& k);
93
94   /**
95    * Dump all bridge_domain-doamin into the stream provided
96    */
97   static void dump(std::ostream& os);
98
99   /**
100    * replay the object to create it in hardware
101    */
102   void replay(void);
103
104   /**
105    * Convert to string for debugging
106    */
107   std::string to_string() const;
108
109   /**
110    * Get the ID of the EPG
111    */
112   epg_id_t id() const;
113
114   const std::shared_ptr<gbp_route_domain> get_route_domain() const;
115   const std::shared_ptr<gbp_bridge_domain> get_bridge_domain() const;
116
117 private:
118   /**
119    * Class definition for listeners to OM events
120    */
121   class event_handler : public OM::listener, public inspect::command_handler
122   {
123   public:
124     event_handler();
125     virtual ~event_handler() = default;
126
127     /**
128      * Handle a populate event
129      */
130     void handle_populate(const client_db::key_t& key);
131
132     /**
133      * Handle a replay event
134      */
135     void handle_replay();
136
137     /**
138      * Show the object in the Singular DB
139      */
140     void show(std::ostream& os);
141
142     /**
143      * Get the sortable Id of the listener
144      */
145     dependency_t order() const;
146   };
147
148   /**
149    * event_handler to register with OM
150    */
151   static event_handler m_evh;
152
153   /**
154    * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
155    */
156   void update(const gbp_endpoint_group& obj);
157
158   /**
159    * Find or add the instnace of the bridge_domain domain in the OM
160    */
161   static std::shared_ptr<gbp_endpoint_group> find_or_add(
162     const gbp_endpoint_group& temp);
163
164   /*
165    * It's the VPPHW class that updates the objects in HW
166    */
167   friend class OM;
168
169   /**
170    * It's the singular_db class that calls replay()
171    */
172   friend class singular_db<key_t, gbp_endpoint_group>;
173
174   /**
175    * Sweep/reap the object if still stale
176    */
177   void sweep(void);
178
179   /**
180    * HW configuration for the result of creating the endpoint_group
181    */
182   HW::item<bool> m_hw;
183
184   /**
185    * The EPG ID
186    */
187   epg_id_t m_epg_id;
188
189   /**
190    * The SClass on the wire
191    */
192   uint16_t m_sclass;
193
194   /**
195    * The uplink interface for the endpoint group
196    */
197   std::shared_ptr<interface> m_itf;
198
199   /**
200    * The route-domain the EPG uses
201    */
202   std::shared_ptr<gbp_route_domain> m_rd;
203
204   /**
205    * The bridge-domain the EPG uses
206    */
207   std::shared_ptr<gbp_bridge_domain> m_bd;
208
209   /**
210    * A map of all bridge_domains
211    */
212   static singular_db<key_t, gbp_endpoint_group> m_db;
213 };
214
215 }; // namespace
216
217 /*
218  * fd.io coding-style-patch-verification: ON
219  *
220  * Local Variables:
221  * eval: (c-set-style "mozilla")
222  * End:
223  */
224
225 #endif