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