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