VCL: remove bogus ASSERT().
[vpp.git] / src / vpp-api / vom / lldp_global.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_LLDP_GLOBAL_H__
17 #define __VOM_LLDP_GLOBAL_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 #include "vom/sub_interface.hpp"
26
27 #include <vapi/lldp.api.vapi.hpp>
28
29 namespace VOM {
30 /**
31  * A representation of LLDP global configuration
32  */
33 class lldp_global : public object_base
34 {
35 public:
36   /**
37    * Construct a new object matching the desried state
38    */
39   lldp_global(const std::string& system_name,
40               uint32_t tx_hold,
41               uint32_t tx_interval);
42
43   /**
44    * Copy Constructor
45    */
46   lldp_global(const lldp_global& o);
47
48   /**
49    * Destructor
50    */
51   ~lldp_global();
52
53   /**
54    * Return the 'singular' of the LLDP global that matches this object
55    */
56   std::shared_ptr<lldp_global> singular() const;
57
58   /**
59    * convert to string format for debug purposes
60    */
61   std::string to_string() const;
62
63   /**
64    * Dump all LLDP globals into the stream provided
65    */
66   static void dump(std::ostream& os);
67
68   /**
69    * A command class that binds the LLDP global to the interface
70    */
71   class config_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Lldp_config>
72   {
73   public:
74     /**
75      * Constructor
76      */
77     config_cmd(HW::item<bool>& item,
78                const std::string& system_name,
79                uint32_t tx_hold,
80                uint32_t tx_interval);
81
82     /**
83      * Issue the command to VPP/HW
84      */
85     rc_t issue(connection& con);
86     /**
87      * convert to string format for debug purposes
88      */
89     std::string to_string() const;
90
91     /**
92      * Comparison operator - only used for UT
93      */
94     bool operator==(const config_cmd& i) const;
95
96   private:
97     /**
98      * The system name
99      */
100     const std::string m_system_name;
101
102     /**
103      * TX timer configs
104      */
105     uint32_t m_tx_hold;
106     uint32_t m_tx_interval;
107   };
108
109 private:
110   /**
111    * Class definition for listeners to OM events
112    */
113   class event_handler : public OM::listener, public inspect::command_handler
114   {
115   public:
116     event_handler();
117     virtual ~event_handler() = default;
118
119     /**
120      * Handle a populate event
121      */
122     void handle_populate(const client_db::key_t& key);
123
124     /**
125      * Handle a replay event
126      */
127     void handle_replay();
128
129     /**
130      * Show the object in the Singular DB
131      */
132     void show(std::ostream& os);
133
134     /**
135      * Get the sortable Id of the listener
136      */
137     dependency_t order() const;
138   };
139
140   /**
141    * event_handler to register with OM
142    */
143   static event_handler m_evh;
144
145   /**
146    * Enquue commonds to the VPP command Q for the update
147    */
148   void update(const lldp_global& obj);
149
150   /**
151    * Find or add LLDP global to the OM
152    */
153   static std::shared_ptr<lldp_global> find_or_add(const lldp_global& temp);
154
155   /*
156    * It's the OM class that calls singular()
157    */
158   friend class OM;
159
160   /**
161    * It's the singular_db class that calls replay()
162    */
163   friend class singular_db<interface::key_type, lldp_global>;
164
165   /**
166    * Sweep/reap the object if still stale
167    */
168   void sweep(void);
169
170   /**
171    * replay the object to create it in hardware
172    */
173   void replay(void);
174
175   /**
176    * The system name
177    */
178   const std::string m_system_name;
179
180   /**
181    * TX timer configs
182    */
183   uint32_t m_tx_hold;
184   uint32_t m_tx_interval;
185
186   /**
187    * HW globaluration for the binding. The bool representing the
188    * do/don't bind.
189    */
190   HW::item<bool> m_binding;
191
192   /**
193    * A map of all Lldp globals keyed against the system name.
194    *  there needs to be some sort of key, that will do.
195    */
196   static singular_db<std::string, lldp_global> m_db;
197 };
198 };
199
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "mozilla")
205  * End:
206  */
207
208 #endif