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