gre: migrate old MULTIARCH macros to VLIB_NODE_FN
[vpp.git] / extras / vom / vom / gbp_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_GBP_GLOBAL_H__
17 #define __VOM_GBP_GLOBAL_H__
18
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/object_base.hpp"
22 #include "vom/om.hpp"
23 #include "vom/singular_db.hpp"
24
25 namespace VOM {
26 /**
27  * A representation of GBP global configuration
28  */
29 class gbp_global : public object_base
30 {
31 public:
32   /**
33    * The key for the global conifugration is the 'system' namse
34    */
35   typedef std::string key_t;
36
37   /**
38    * Construct a new object matching the desried state
39    */
40   gbp_global(const std::string& system_name, uint32_t remote_ep_retention);
41
42   /**
43    * Copy Constructor
44    */
45   gbp_global(const gbp_global& o);
46
47   /**
48    * Destructor
49    */
50   ~gbp_global();
51
52   /**
53    * Get this objects key
54    */
55   const key_t& key() const;
56
57   /**
58    * Comparison operator
59    */
60   bool operator==(const gbp_global& l) const;
61
62   /**
63    * Return the 'singular' of the GBP global that matches this object
64    */
65   std::shared_ptr<gbp_global> singular() const;
66
67   /**
68    * convert to string format for debug purposes
69    */
70   std::string to_string() const;
71
72   /**
73    * Dump all GBP globals into the stream provided
74    */
75   static void dump(std::ostream& os);
76
77   /**
78    * Find GBP global config from its key
79    */
80   static std::shared_ptr<gbp_global> find(const key_t& k);
81
82 private:
83   /**
84    * Class definition for listeners to OM events
85    */
86   class event_handler : public OM::listener, public inspect::command_handler
87   {
88   public:
89     event_handler();
90     virtual ~event_handler() = default;
91
92     /**
93      * Handle a populate event
94      */
95     void handle_populate(const client_db::key_t& key);
96
97     /**
98      * Handle a replay event
99      */
100     void handle_replay();
101
102     /**
103      * Show the object in the Singular DB
104      */
105     void show(std::ostream& os);
106
107     /**
108      * Get the sortable Id of the listener
109      */
110     dependency_t order() const;
111   };
112
113   /**
114    * event_handler to register with OM
115    */
116   static event_handler m_evh;
117
118   /**
119    * Enquue commonds to the VPP command Q for the update
120    */
121   void update(const gbp_global& obj);
122
123   /**
124    * Find or add GBP global to the OM
125    */
126   static std::shared_ptr<gbp_global> find_or_add(const gbp_global& temp);
127
128   /*
129    * It's the OM class that calls singular()
130    */
131   friend class OM;
132
133   /**
134    * It's the singular_db class that calls replay()
135    */
136   friend class singular_db<key_t, gbp_global>;
137
138   /**
139    * Sweep/reap the object if still stale
140    */
141   void sweep(void);
142
143   /**
144    * replay the object to create it in hardware
145    */
146   void replay(void);
147
148   /**
149    * The system name
150    */
151   const std::string m_system_name;
152
153   /**
154    * TX timer configs
155    */
156   uint32_t m_remote_ep_retention;
157
158   /**
159    * HW globaluration for the binding. The bool representing the
160    * do/don't bind.
161    */
162   HW::item<bool> m_binding;
163
164   /**
165    * A map of all Gbp globals keyed against the system name.
166    *  there needs to be some sort of key, that will do.
167    */
168   static singular_db<key_t, gbp_global> m_db;
169 };
170 };
171
172 /*
173  * fd.io coding-style-patch-verification: ON
174  *
175  * Local Variables:
176  * eval: (c-set-style "mozilla")
177  * End:
178  */
179
180 #endif