FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
qos_map.cpp
Go to the documentation of this file.
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 #include "vom/qos_map.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/qos_map_cmds.hpp"
19 #include "vom/qos_types_api.hpp"
21 
22 namespace VOM {
23 namespace QoS {
24 
26 
27 map::event_handler map::m_evh;
28 
29 map::map(uint32_t id, const outputs_t& o)
30  : m_config(false)
31  , m_id(id)
32  , m_outputs(o)
33 {
34 }
35 
36 map::map(const map& r)
37  : m_config(r.m_config)
38  , m_id(r.m_id)
39  , m_outputs(r.m_outputs)
40 {
41 }
42 
44 {
45  sweep();
46  m_db.release(key(), this);
47 }
48 
49 const map::key_t
50 map::key() const
51 {
52  return m_id;
53 }
54 
55 const uint32_t
56 map::id() const
57 {
58  return m_id;
59 }
60 
61 bool
62 map::operator==(const map& m) const
63 {
64  return (key() == m.key() && m_outputs == m.m_outputs);
65 }
66 
67 void
68 map::sweep()
69 {
70  if (m_config) {
71  HW::enqueue(new map_cmds::delete_cmd(m_config, m_id));
72  }
73  HW::write();
74 }
75 
76 void
78 {
79  if (m_config) {
80  HW::enqueue(new map_cmds::create_cmd(m_config, m_id, m_outputs));
81  }
82 }
83 
84 std::string
86 {
87  std::ostringstream s;
88  s << "qos-map:" << (int)m_id;
89 
90  return (s.str());
91 }
92 
93 void
94 map::update(const map& m)
95 {
96  m_outputs = m.m_outputs;
97 
98  if (rc_t::OK != m_config.rc()) {
99  HW::enqueue(new map_cmds::create_cmd(m_config, m_id, m_outputs));
100  }
101 }
102 
103 std::shared_ptr<map>
104 map::find_or_add(const map& temp)
105 {
106  return (m_db.find_or_add(temp.key(), temp));
107 }
108 
109 std::shared_ptr<map>
110 map::find(const key_t& k)
111 {
112  return (m_db.find(k));
113 }
114 
115 std::shared_ptr<map>
117 {
118  return find_or_add(*this);
119 }
120 
121 void
122 map::dump(std::ostream& os)
123 {
124  db_dump(m_db, os);
125 }
126 
128 {
129  OM::register_listener(this);
130  inspect::register_handler({ "qos-map" }, "QoS Map", this);
131 }
132 
133 void
134 map::event_handler::handle_replay()
135 {
136  m_db.replay();
137 }
138 
139 static const map::outputs_t
140 from_api(vapi_type_qos_egress_map_row rows[4])
141 {
142  map::outputs_t o;
143 
144  for (uint32_t ii = 0; ii < 4; ii++) {
145  std::copy(std::begin(rows[ii].outputs), std::end(rows[ii].outputs),
146  o[ii].begin());
147  }
148 
149  return o;
150 }
151 
152 void
153 map::event_handler::handle_populate(const client_db::key_t& key)
154 {
155  std::shared_ptr<map_cmds::dump_cmd> cmd =
156  std::make_shared<map_cmds::dump_cmd>();
157 
158  HW::enqueue(cmd);
159  HW::write();
160 
161  for (auto& rr : *cmd) {
162  auto& payload = rr.get_payload();
163 
164  map qr(payload.map.id, from_api(payload.map.rows));
165  OM::commit(key, qr);
166  }
167 }
168 
170 map::event_handler::order() const
171 {
172  return (dependency_t::TABLE);
173 }
174 
175 void
176 map::event_handler::show(std::ostream& os)
177 {
178  db_dump(m_db, os);
179 }
180 
181 }; // namespace QoS
182 }; // namespace VOM
183 
184 /*
185  * fd.io coding-style-patch-verification: ON
186  *
187  * Local Variables:
188  * eval: (c-set-style "mozilla")
189  * End:
190  */
static std::shared_ptr< map > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: qos_map.cpp:110
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_map.cpp:122
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
const key_t key() const
Return the object&#39;s key.
Definition: qos_map.cpp:50
const key_t id() const
Return the object&#39;s ID.
Definition: qos_map.cpp:56
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
uint32_t key_t
Definition: qos_map.hpp:45
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
vl_api_qos_egress_map_row_t rows[4]
Definition: qos.api:153
bool operator==(const map &bdae) const
comparison operator
Definition: qos_map.cpp:62
A cmd class that deletes a GBP endpoint.
std::shared_ptr< map > singular() const
Return the matching &#39;singular instance&#39;.
Definition: qos_map.cpp:116
A Database to store the unique &#39;singular&#39; instances of a single object type.
Definition: singular_db.hpp:33
std::array< std::array< bits_t, 256 >, 4 > outputs_t
Definition: qos_map.hpp:38
Tables in which entries are added, e.g bridge/route-domains.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
void event_handler(void *tls_async)
Definition: tls_async.c:334
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:109
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
A command class that creates or updates the GBP endpoint.
A QoS map determines how value from one source are translated to values of another source...
Definition: qos_map.hpp:35
static const map::outputs_t from_api(vapi_type_qos_egress_map_row rows[4])
Definition: qos_map.cpp:140
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
f64 end
end of the time range
Definition: mactime.api:44
std::string to_string() const
Convert to string for debugging.
Definition: qos_map.cpp:85
void replay(void)
replay the object to create it in hardware
Definition: qos_map.cpp:77
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
map(uint32_t id, const outputs_t &o)
Definition: qos_map.cpp:29