FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
qos_store.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_store.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/qos_store_cmds.hpp"
19 #include "vom/qos_types_api.hpp"
21 
22 namespace VOM {
23 namespace QoS {
24 
25 singular_db<store::key_t, store> store::m_db;
26 
27 store::event_handler store::m_evh;
28 
30  : m_config(false)
31  , m_itf(itf.singular())
32  , m_src(src)
33  , m_value(value)
34 {
35 }
36 
38  : m_config(s.m_config)
39  , m_itf(s.m_itf)
40  , m_src(s.m_src)
41  , m_value(s.m_value)
42 {
43 }
44 
46 {
47  sweep();
48  m_db.release(key(), this);
49 }
50 
51 const store::key_t
52 store::key() const
53 {
54  return (std::make_pair(m_itf->key(), m_src));
55 }
56 
57 bool
58 store::operator==(const store& r) const
59 {
60  return (key() == r.key());
61 }
62 
63 void
64 store::sweep()
65 {
66  if (m_config) {
67  HW::enqueue(new store_cmds::delete_cmd(m_config, m_itf->handle(), m_src));
68  }
69  HW::write();
70 }
71 
72 void
74 {
75  if (m_config) {
77  new store_cmds::create_cmd(m_config, m_itf->handle(), m_src, m_value));
78  }
79 }
80 
83 {
84  std::ostringstream s;
85  s << "qos-store:[" << m_itf->to_string() << ", src:" << m_src.to_string()
86  << ", value:" << static_cast<int>(m_value);
87 
88  return (s.str());
89 }
90 
91 void
92 store::update(const store& r)
93 {
94  if (rc_t::OK != m_config.rc()) {
96  new store_cmds::create_cmd(m_config, m_itf->handle(), m_src, m_value));
97  }
98 }
99 
100 std::shared_ptr<store>
101 store::find_or_add(const store& temp)
102 {
103  return (m_db.find_or_add(temp.key(), temp));
104 }
105 
106 std::shared_ptr<store>
108 {
109  return (m_db.find(k));
110 }
111 
112 std::shared_ptr<store>
114 {
115  return find_or_add(*this);
116 }
117 
118 void
119 store::dump(std::ostream& os)
120 {
121  db_dump(m_db, os);
122 }
123 
125 {
126  OM::register_listener(this);
127  inspect::register_handler({ "qos-store" }, "QoS Store", this);
128 }
129 
130 void
131 store::event_handler::handle_replay()
132 {
133  m_db.replay();
134 }
135 
136 void
137 store::event_handler::handle_populate(const client_db::key_t& key)
138 {
139  std::shared_ptr<store_cmds::dump_cmd> cmd =
140  std::make_shared<store_cmds::dump_cmd>();
141 
142  HW::enqueue(cmd);
143  HW::write();
144 
145  for (auto& rr : *cmd) {
146  auto& payload = rr.get_payload();
147 
148  std::shared_ptr<interface> itf = interface::find(payload.store.sw_if_index);
149 
150  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.store.sw_if_index;
151 
152  if (itf) {
153  store qr(*itf, from_api(payload.store.input_source), payload.store.value);
154  OM::commit(key, qr);
155 
156  VOM_LOG(log_level_t::DEBUG) << "read: " << qr.to_string();
157  } else {
158  VOM_LOG(log_level_t::ERROR) << "no interface:"
159  << payload.store.sw_if_index;
160  }
161  }
162 }
163 
165 store::event_handler::order() const
166 {
167  return (dependency_t::ENTRY);
168 }
169 
170 void
171 store::event_handler::show(std::ostream& os)
172 {
173  db_dump(m_db, os);
174 }
175 
176 }; // namespace QoS
177 
178 }; // namespace VOM
179 
180 /*
181  * fd.io coding-style-patch-verification: OFF
182  *
183  * Local Variables:
184  * eval: (c-set-style "mozilla")
185  * End:
186  */
VOM::HW::write
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:255
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_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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
qos_types_api.hpp
VOM::dependency_t::ENTRY
@ ENTRY
Entries in Tables.
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1089
key
typedef key
Definition: ipsec_types.api:91
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
qos_store_cmds.hpp
VOM::QoS::store::key
const key_t key() const
Return the object's key.
Definition: qos_store.cpp:52
VOM::OM::register_listener
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
qos_store.hpp
VOM::QoS::store::to_string
std::string to_string() const
Convert to string for debugging.
Definition: qos_store.cpp:82
VOM::QoS::store::~store
~store()
Definition: qos_store.cpp:45
VOM::QoS::store_cmds::create_cmd
A command class that creates or updates the GBP endpoint.
Definition: qos_store_cmds.hpp:31
VOM::QoS::store::operator==
bool operator==(const store &bdae) const
comparison operator
Definition: qos_store.cpp:58
VOM::QoS::bits_t
uint8_t bits_t
Definition: qos_types.hpp:27
VOM::QoS::store::replay
void replay(void)
replay the object to create it in hardware
Definition: qos_store.cpp:73
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
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
VOM::QoS::store_cmds::delete_cmd
A cmd class that deletes a GBP endpoint.
Definition: qos_store_cmds.hpp:67
VOM::HW::enqueue
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:212
src
vl_api_address_t src
Definition: gre.api:54
VOM::QoS::store
Definition: qos_store.hpp:31
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::QoS::store::find
static std::shared_ptr< store > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: qos_store.cpp:107
false
#define false
Definition: cJSON.c:70
singular_db_funcs.hpp
VOM::enum_base::to_string
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
VOM::HW::item::rc
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:119
VOM::QoS::store::store
store(const interface &i, const source_t &source, bits_t value)
Definition: qos_store.cpp:29
value
u8 value
Definition: qos.api:54
VOM::QoS::store::key_t
std::pair< interface::key_t, source_t > key_t
Definition: qos_store.hpp:39
VOM::QoS::store::singular
std::shared_ptr< store > singular() const
Return the matching 'singular instance'.
Definition: qos_store.cpp:113
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::QoS::source_t
The Source of the QoS classification (i.e.
Definition: qos_types.hpp:33
VOM::QoS::store::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_store.cpp:119
VOM::QoS::from_api
static const map::outputs_t from_api(vapi_type_qos_egress_map_row rows[4])
Definition: qos_map.cpp:140
VOM::log_level_t::ERROR
const static log_level_t ERROR
Definition: logger.hpp:29
api_types.hpp
VOM::interface::find
static std::shared_ptr< interface > find(const handle_t &h)
The the singular instance of the interface in the DB by handle.
Definition: interface.cpp:538
string
const char *const string
Definition: cJSON.h:172