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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
20 #include "vom/singular_db_funcs.hpp"
25 singular_db<mark::key_t, mark> mark::m_db;
27 mark::event_handler mark::m_evh;
29 mark::mark(const interface& itf, const map& m, const source_t& src)
31 , m_itf(itf.singular())
37 mark::mark(const mark& m)
38 : m_config(m.m_config)
48 m_db.release(key(), this);
54 return (std::make_pair(m_itf->key(), m_src));
58 mark::operator==(const mark& m) const
60 return (key() == m.key() && m_map->id() == m.m_map->id());
67 HW::enqueue(new mark_cmds::delete_cmd(m_config, m_itf->handle(), m_src));
77 new mark_cmds::create_cmd(m_config, m_itf->handle(), m_map->id(), m_src));
82 mark::to_string() const
85 s << "qos-mark:[" << m_itf->to_string() << ", map:" << m_map->id()
86 << ", src:" << m_src.to_string();
92 mark::update(const mark& r)
94 if (rc_t::OK != m_config.rc()) {
96 new mark_cmds::create_cmd(m_config, m_itf->handle(), m_map->id(), m_src));
100 std::shared_ptr<mark>
101 mark::find_or_add(const mark& temp)
103 return (m_db.find_or_add(temp.key(), temp));
106 std::shared_ptr<mark>
107 mark::find(const key_t& k)
109 return (m_db.find(k));
112 std::shared_ptr<mark>
113 mark::singular() const
115 return find_or_add(*this);
119 mark::dump(std::ostream& os)
124 mark::event_handler::event_handler()
126 OM::register_listener(this);
127 inspect::register_handler({ "qos-mark" }, "QoS Mark", this);
131 mark::event_handler::handle_replay()
137 mark::event_handler::handle_populate(const client_db::key_t& key)
139 std::shared_ptr<mark_cmds::dump_cmd> cmd =
140 std::make_shared<mark_cmds::dump_cmd>();
145 for (auto& rr : *cmd) {
146 auto& payload = rr.get_payload();
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);
151 VOM_LOG(log_level_t::DEBUG) << "data: " << payload.mark.sw_if_index;
154 mark qm(*itf, *map, from_api(payload.mark.output_source));
157 VOM_LOG(log_level_t::DEBUG) << "read: " << qm.to_string();
159 VOM_LOG(log_level_t::ERROR)
160 << "no interface or map:" << payload.mark.sw_if_index << ", "
161 << payload.mark.map_id;
167 mark::event_handler::order() const
169 return (dependency_t::ENTRY);
173 mark::event_handler::show(std::ostream& os)
182 * fd.io coding-style-patch-verification: ON
185 * eval: (c-set-style "mozilla")