FD.io VPP  v21.10.1-2-g0a485f517
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 
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: OFF
186  *
187  * Local Variables:
188  * eval: (c-set-style "mozilla")
189  * End:
190  */
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
VOM::QoS::map::~map
~map()
Definition: qos_map.cpp:43
VOM::OM::commit
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
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::inspect::register_handler
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
VOM::dependency_t
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
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::QoS::map::find
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
qos_types_api.hpp
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
VOM::QoS::map::outputs_t
std::array< std::array< bits_t, 256 >, 4 > outputs_t
Definition: qos_map.hpp:38
key
typedef key
Definition: ipsec_types.api:91
VOM::QoS::map_cmds::create_cmd
A command class that creates or updates the GBP endpoint.
Definition: qos_map_cmds.hpp:31
VOM::QoS::map_cmds::delete_cmd
A cmd class that deletes a GBP endpoint.
Definition: qos_map_cmds.hpp:62
VOM::db_dump
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
Definition: singular_db_funcs.hpp:35
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
map
counters map
Definition: map.api:356
VOM::QoS::map::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_map.cpp:122
VOM::QoS::map::key_t
uint32_t key_t
Definition: qos_map.hpp:45
end
f64 end
end of the time range
Definition: mactime.api:44
VOM::QoS::map::key
const key_t key() const
Return the object's key.
Definition: qos_map.cpp:50
VOM::QoS::map::to_string
std::string to_string() const
Convert to string for debugging.
Definition: qos_map.cpp:85
VOM::client_db::key_t
const typedef 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
rows
vl_api_qos_egress_map_row_t rows[4]
Definition: qos.api:153
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
qos_map.hpp
VOM::QoS::map::operator==
bool operator==(const map &bdae) const
comparison operator
Definition: qos_map.cpp:62
VOM::dependency_t::TABLE
@ TABLE
Tables in which entries are added, e.g bridge/route-domains.
false
#define false
Definition: cJSON.c:70
singular_db_funcs.hpp
id
u8 id[64]
Definition: dhcp.api:160
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::QoS::map::singular
std::shared_ptr< map > singular() const
Return the matching 'singular instance'.
Definition: qos_map.cpp:116
VOM::QoS::map::replay
void replay(void)
replay the object to create it in hardware
Definition: qos_map.cpp:77
VOM::QoS::map
A QoS map determines how value from one source are translated to values of another source.
Definition: qos_map.hpp:35
qos_map_cmds.hpp
VOM::QoS::map::map
map(uint32_t id, const outputs_t &o)
Definition: qos_map.cpp:29
VOM::singular_db
A Database to store the unique 'singular' instances of a single object type.
Definition: singular_db.hpp:33
VOM::QoS::map::id
const key_t id() const
Return the object's ID.
Definition: qos_map.cpp:56
show
void show(char *chroot_path, int verbose)
Definition: svmtool.c:104
event_handler
void event_handler(void *tls_async)
Definition: tls_async.c:334
VOM::cmd
A representation of a method call to VPP.
Definition: cmd.hpp:32
VOM::QoS::from_api
static const map::outputs_t from_api(vapi_type_qos_egress_map_row rows[4])
Definition: qos_map.cpp:140
api_types.hpp
string
const char *const string
Definition: cJSON.h:172