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