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