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