FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
qos_record.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_record.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/qos_record_cmds.hpp"
19 #include "vom/qos_types_api.hpp"
21 
22 namespace VOM {
23 namespace QoS {
24 
25 singular_db<record::key_t, record> record::m_db;
26 
27 record::event_handler record::m_evh;
28 
29 record::record(const interface& itf, const source_t& src)
30  : m_config(false)
31  , m_itf(itf.singular())
32  , m_src(src)
33 {
34 }
35 
37  : m_config(r.m_config)
38  , m_itf(r.m_itf)
39  , m_src(r.m_src)
40 {
41 }
42 
44 {
45  sweep();
46  m_db.release(key(), this);
47 }
48 
49 const record::key_t
50 record::key() const
51 {
52  return (std::make_pair(m_itf->key(), m_src));
53 }
54 
55 bool
57 {
58  return (key() == r.key());
59 }
60 
61 void
62 record::sweep()
63 {
64  if (m_config) {
65  HW::enqueue(new record_cmds::delete_cmd(m_config, m_itf->handle(), m_src));
66  }
67  HW::write();
68 }
69 
70 void
72 {
73  if (m_config) {
74  HW::enqueue(new record_cmds::create_cmd(m_config, m_itf->handle(), m_src));
75  }
76 }
77 
80 {
81  std::ostringstream s;
82  s << "qos-record:[" << m_itf->to_string() << ", src:" << m_src.to_string();
83 
84  return (s.str());
85 }
86 
87 void
88 record::update(const record& r)
89 {
90  if (rc_t::OK != m_config.rc()) {
91  HW::enqueue(new record_cmds::create_cmd(m_config, m_itf->handle(), m_src));
92  }
93 }
94 
95 std::shared_ptr<record>
96 record::find_or_add(const record& temp)
97 {
98  return (m_db.find_or_add(temp.key(), temp));
99 }
100 
101 std::shared_ptr<record>
103 {
104  return (m_db.find(k));
105 }
106 
107 std::shared_ptr<record>
109 {
110  return find_or_add(*this);
111 }
112 
113 void
114 record::dump(std::ostream& os)
115 {
116  db_dump(m_db, os);
117 }
118 
120 {
121  OM::register_listener(this);
122  inspect::register_handler({ "qos-record" }, "QoS Record", this);
123 }
124 
125 void
126 record::event_handler::handle_replay()
127 {
128  m_db.replay();
129 }
130 
131 void
132 record::event_handler::handle_populate(const client_db::key_t& key)
133 {
134  std::shared_ptr<record_cmds::dump_cmd> cmd =
135  std::make_shared<record_cmds::dump_cmd>();
136 
137  HW::enqueue(cmd);
138  HW::write();
139 
140  for (auto& rr : *cmd) {
141  auto& payload = rr.get_payload();
142 
143  std::shared_ptr<interface> itf =
144  interface::find(payload.record.sw_if_index);
145 
146  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.record.sw_if_index;
147 
148  if (itf) {
149  record qr(*itf, from_api(payload.record.input_source));
150  OM::commit(key, qr);
151 
152  VOM_LOG(log_level_t::DEBUG) << "read: " << qr.to_string();
153  } else {
154  VOM_LOG(log_level_t::ERROR) << "no interface:"
155  << payload.record.sw_if_index;
156  }
157  }
158 }
159 
161 record::event_handler::order() const
162 {
163  return (dependency_t::ENTRY);
164 }
165 
166 void
167 record::event_handler::show(std::ostream& os)
168 {
169  db_dump(m_db, os);
170 }
171 
172 }; // namespace QoS
173 
174 std::ostream&
175 operator<<(std::ostream& os, const QoS::record::key_t& key)
176 {
177  os << key.first << "," << key.second;
178 
179  return os;
180 }
181 
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
qos_record.hpp
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
VOM::QoS::record_cmds::delete_cmd
A cmd class that deletes a GBP endpoint.
Definition: qos_record_cmds.hpp:63
qos_types_api.hpp
VOM::dependency_t::ENTRY
@ ENTRY
Entries in Tables.
VOM::QoS::record::find
static std::shared_ptr< record > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: qos_record.cpp:102
r
vnet_hw_if_output_node_runtime_t * r
Definition: interface_output.c:1071
VOM::QoS::record::record
record(const interface &i, const source_t &source)
Definition: qos_record.cpp:29
VOM::QoS::record::singular
std::shared_ptr< record > singular() const
Return the matching 'singular instance'.
Definition: qos_record.cpp:108
key
typedef key
Definition: ipsec_types.api:88
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
VOM::QoS::record::~record
~record()
Definition: qos_record.cpp:43
VOM::QoS::record::replay
void replay(void)
replay the object to create it in hardware
Definition: qos_record.cpp:71
VOM::interface
A representation of an interface in VPP.
Definition: interface.hpp:41
VOM::QoS::record_cmds::create_cmd
A command class that creates or updates the GBP endpoint.
Definition: qos_record_cmds.hpp:31
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::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::record::key_t
std::pair< interface::key_t, source_t > key_t
Definition: qos_record.hpp:39
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::operator<<
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
Definition: acl_binding.cpp:201
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::record::operator==
bool operator==(const record &bdae) const
comparison operator
Definition: qos_record.cpp:56
VOM::QoS::record
Definition: qos_record.hpp:31
VOM::QoS::record::dump
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_record.cpp:114
VOM::QoS::record::to_string
std::string to_string() const
Convert to string for debugging.
Definition: qos_record.cpp:79
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
qos_record_cmds.hpp
VOM::QoS::source_t
The Source of the QoS classification (i.e.
Definition: qos_types.hpp:33
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::QoS::record::key
const key_t key() const
Return the object's key.
Definition: qos_record.cpp:50
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