FD.io VPP  v20.09-64-g4f7b92f0a
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
56 record::operator==(const record& r) const
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 
78 std::string
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: ON
186  *
187  * Local Variables:
188  * eval: (c-set-style "mozilla")
189  * End:
190  */
std::pair< interface::key_t, source_t > key_t
Definition: qos_record.hpp:39
#define VOM_LOG(lvl)
Definition: logger.hpp:181
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
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
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
A cmd class that deletes a GBP endpoint.
vl_api_address_t src
Definition: gre.api:54
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
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_record.cpp:114
static const log_level_t DEBUG
Definition: logger.hpp:32
void replay(void)
replay the object to create it in hardware
Definition: qos_record.cpp:71
A command class that creates or updates the GBP endpoint.
record(const interface &i, const source_t &source)
Definition: qos_record.cpp:29
std::string to_string() const
Convert to string for debugging.
Definition: qos_record.cpp:79
A representation of an interface in VPP.
Definition: interface.hpp:41
The Source of the QoS classification (i.e.
Definition: qos_types.hpp:33
const std::string & to_string() const
convert to string format for debug purposes
Definition: enum_base.hpp:36
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
static const log_level_t ERROR
Definition: logger.hpp:29
static const map::outputs_t from_api(vapi_type_qos_egress_map_row rows[4])
Definition: qos_map.cpp:140
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
std::shared_ptr< record > singular() const
Return the matching &#39;singular instance&#39;.
Definition: qos_record.cpp:108
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
const key_t key() const
Return the object&#39;s key.
Definition: qos_record.cpp:50
A representation of a method call to VPP.
Definition: cmd.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
Entries in Tables.
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
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127
bool operator==(const record &bdae) const
comparison operator
Definition: qos_record.cpp:56