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