GBP: add allowed ethertypes to contracts
[vpp.git] / extras / vom / vom / ip_unnumbered.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_IP_UNNUMBERED_H__
17 #define __VOM_IP_UNNUMBERED_H__
18
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/interface.hpp"
22 #include "vom/object_base.hpp"
23 #include "vom/om.hpp"
24 #include "vom/singular_db.hpp"
25
26 namespace VOM {
27 /**
28  * A representation of IP unnumbered configuration on an interface
29  */
30 class ip_unnumbered : public object_base
31 {
32 public:
33   /**
34    * Construct a new object matching the desried state
35    *
36    * @param itf - The interface with no IP address
37    * @param l3_itf - The interface that has the IP address we wish to
38    * share.
39    */
40   ip_unnumbered(const interface& itf, const interface& l3_itf);
41
42   /**
43    * Copy Constructor
44    */
45   ip_unnumbered(const ip_unnumbered& o);
46
47   /**
48    * Destructor
49    */
50   ~ip_unnumbered();
51
52   /**
53    * Return the 'singular instance' of the L3-Config that matches this
54    * object
55    */
56   std::shared_ptr<ip_unnumbered> singular() const;
57
58   /**
59    * convert to string format for debug purposes
60    */
61   std::string to_string() const;
62
63   /**
64    * Dump all ip_unnumbereds into the stream provided
65    */
66   static void dump(std::ostream& os);
67
68   /**
69    * The key type for ip_unnumbereds
70    */
71   typedef interface::key_t key_t;
72
73   /**
74    * Find an singular instance in the DB for the interface passed
75    */
76   static std::shared_ptr<ip_unnumbered> find(const interface& i);
77
78 private:
79   /**
80    * Class definition for listeners to OM events
81    */
82   class event_handler : public OM::listener, public inspect::command_handler
83   {
84   public:
85     event_handler();
86     virtual ~event_handler() = default;
87
88     /**
89      * Handle a populate event
90      */
91     void handle_populate(const client_db::key_t& key);
92
93     /**
94      * Handle a replay event
95      */
96     void handle_replay();
97
98     /**
99      * Show the object in the Singular DB
100      */
101     void show(std::ostream& os);
102
103     /**
104      * Get the sortable Id of the listener
105      */
106     dependency_t order() const;
107   };
108
109   /**
110    * event_handler to register with OM
111    */
112   static event_handler m_evh;
113
114   /**
115    * Enquue commonds to the VPP command Q for the update
116    */
117   void update(const ip_unnumbered& obj);
118
119   /**
120    * Find or add the singular instance in the DB
121    */
122   static std::shared_ptr<ip_unnumbered> find_or_add(const ip_unnumbered& temp);
123
124   /*
125    * It's the VPPHW class that updates the objects in HW
126    */
127   friend class OM;
128
129   /**
130    * It's the singular_db class that calls replay
131    */
132   friend class singular_db<key_t, ip_unnumbered>;
133
134   /**
135    * Sweep/reap the object if still stale
136    */
137   void sweep(void);
138
139   /**
140    * replay the object to create it in hardware
141    */
142   void replay(void);
143
144   /**
145    * A reference counting pointer the interface that requires an address.
146    */
147   const std::shared_ptr<interface> m_itf;
148   /**
149    * A reference counting pointer the interface that has an address.
150    */
151   const std::shared_ptr<interface> m_l3_itf;
152
153   /**
154    * HW configuration for the binding. The bool representing the
155    * do/don't bind.
156    */
157   HW::item<bool> m_config;
158
159   /**
160    * A map of all L3 configs keyed against a combination of the interface
161    * and subnet's keys.
162    */
163   static singular_db<key_t, ip_unnumbered> m_db;
164 };
165 };
166
167 /*
168  * fd.io coding-style-patch-verification: ON
169  *
170  * Local Variables:
171  * eval: (c-set-style "mozilla")
172  * End:
173  */
174
175 #endif