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