FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
qos_mark.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_mark.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/qos_mark_cmds.hpp"
19 #include "vom/qos_types_api.hpp"
21 
22 namespace VOM {
23 namespace QoS {
24 
25 singular_db<mark::key_t, mark> mark::m_db;
26 
27 mark::event_handler mark::m_evh;
28 
29 mark::mark(const interface& itf, const map& m, const source_t& src)
30  : m_config(false)
31  , m_itf(itf.singular())
32  , m_map(m.singular())
33  , m_src(src)
34 {
35 }
36 
37 mark::mark(const mark& m)
38  : m_config(m.m_config)
39  , m_itf(m.m_itf)
40  , m_map(m.m_map)
41  , m_src(m.m_src)
42 {
43 }
44 
46 {
47  sweep();
48  m_db.release(key(), this);
49 }
50 
51 const mark::key_t
52 mark::key() const
53 {
54  return (std::make_pair(m_itf->key(), m_src));
55 }
56 
57 bool
58 mark::operator==(const mark& m) const
59 {
60  return (key() == m.key() && m_map->id() == m.m_map->id());
61 }
62 
63 void
64 mark::sweep()
65 {
66  if (m_config) {
67  HW::enqueue(new mark_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 mark_cmds::create_cmd(m_config, m_itf->handle(), m_map->id(), m_src));
78  }
79 }
80 
81 std::string
83 {
84  std::ostringstream s;
85  s << "qos-mark:[" << m_itf->to_string() << ", map:" << m_map->id()
86  << ", src:" << m_src.to_string();
87 
88  return (s.str());
89 }
90 
91 void
92 mark::update(const mark& r)
93 {
94  if (rc_t::OK != m_config.rc()) {
96  new mark_cmds::create_cmd(m_config, m_itf->handle(), m_map->id(), m_src));
97  }
98 }
99 
100 std::shared_ptr<mark>
101 mark::find_or_add(const mark& temp)
102 {
103  return (m_db.find_or_add(temp.key(), temp));
104 }
105 
106 std::shared_ptr<mark>
107 mark::find(const key_t& k)
108 {
109  return (m_db.find(k));
110 }
111 
112 std::shared_ptr<mark>
114 {
115  return find_or_add(*this);
116 }
117 
118 void
119 mark::dump(std::ostream& os)
120 {
121  db_dump(m_db, os);
122 }
123 
125 {
126  OM::register_listener(this);
127  inspect::register_handler({ "qos-mark" }, "QoS Mark", this);
128 }
129 
130 void
131 mark::event_handler::handle_replay()
132 {
133  m_db.replay();
134 }
135 
136 void
137 mark::event_handler::handle_populate(const client_db::key_t& key)
138 {
139  std::shared_ptr<mark_cmds::dump_cmd> cmd =
140  std::make_shared<mark_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.mark.sw_if_index);
149  std::shared_ptr<map> map = map::find(payload.mark.map_id);
150 
151  VOM_LOG(log_level_t::DEBUG) << "data: " << payload.mark.sw_if_index;
152 
153  if (itf && map) {
154  mark qm(*itf, *map, from_api(payload.mark.output_source));
155  OM::commit(key, qm);
156 
157  VOM_LOG(log_level_t::DEBUG) << "read: " << qm.to_string();
158  } else {
160  << "no interface or map:" << payload.mark.sw_if_index << ", "
161  << payload.mark.map_id;
162  }
163  }
164 }
165 
167 mark::event_handler::order() const
168 {
169  return (dependency_t::ENTRY);
170 }
171 
172 void
173 mark::event_handler::show(std::ostream& os)
174 {
175  db_dump(m_db, os);
176 }
177 
178 }; // namespace QoS
179 }; // namespace VOM
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "mozilla")
186  * End:
187  */
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
#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
A command class that creates or updates the GBP endpoint.
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
vl_api_address_t src
Definition: gre.api:51
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 const log_level_t DEBUG
Definition: logger.hpp:32
bool operator==(const mark &bdae) const
comparison operator
Definition: qos_mark.cpp:58
mark(const interface &i, const map &m, const source_t &source)
Definition: qos_mark.cpp:29
A cmd class that deletes a GBP endpoint.
const key_t key() const
Return the object&#39;s key.
Definition: qos_mark.cpp:52
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
Definition: qos_mark.cpp:119
std::string to_string() const
Convert to string for debugging.
Definition: qos_mark.cpp:82
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:338
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 QoS map determines how value from one source are translated to values of another source...
Definition: qos_map.hpp:35
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::pair< interface::key_t, source_t > key_t
Definition: qos_mark.hpp:40
std::shared_ptr< mark > singular() const
Return the matching &#39;singular instance&#39;.
Definition: qos_mark.cpp:113
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
static std::shared_ptr< mark > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
Definition: qos_mark.cpp:107
The marking of packets with QoS bits as they egress an interface.
Definition: qos_mark.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
Entries in Tables.
void replay(void)
replay the object to create it in hardware
Definition: qos_mark.cpp:73
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127