2 * Copyright (c) 2017 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/interface_span.hpp"
17 #include "vom/interface_span_cmds.hpp"
21 * A DB of all interface_span config
23 singular_db<interface_span::key_t, interface_span> interface_span::m_db;
25 interface_span::event_handler interface_span::m_evh;
27 interface_span::interface_span(const interface& itf_from,
28 const interface& itf_to,
29 interface_span::state_t state)
30 : m_itf_from(itf_from.singular())
31 , m_itf_to(itf_to.singular())
37 interface_span::interface_span(const interface_span& o)
38 : m_itf_from(o.m_itf_from)
39 , m_itf_to(o.m_itf_to)
41 , m_config(o.m_config)
45 interface_span::~interface_span()
49 // not in the DB anymore.
50 m_db.release(make_pair(m_itf_from->key(), m_itf_to->key()), this);
54 interface_span::sweep()
57 HW::enqueue(new interface_span_cmds::unconfig_cmd(
58 m_config, m_itf_from->handle(), m_itf_to->handle()));
64 interface_span::dump(std::ostream& os)
70 interface_span::replay()
73 HW::enqueue(new interface_span_cmds::config_cmd(
74 m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
79 interface_span::to_string() const
82 s << "Itf Span-config:"
83 << " itf-from:" << m_itf_from->to_string()
84 << " itf-to:" << m_itf_to->to_string() << " state:" << m_state.to_string();
90 interface_span::update(const interface_span& desired)
93 HW::enqueue(new interface_span_cmds::config_cmd(
94 m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
99 operator<<(std::ostream& os, const interface_span::key_t& key)
101 os << "[" << key.first << ", " << key.second << "]";
106 std::shared_ptr<interface_span>
107 interface_span::find_or_add(const interface_span& temp)
109 return (m_db.find_or_add(
110 make_pair(temp.m_itf_from->key(), temp.m_itf_to->key()), temp));
113 std::shared_ptr<interface_span>
114 interface_span::singular() const
116 return find_or_add(*this);
119 interface_span::event_handler::event_handler()
121 OM::register_listener(this);
122 inspect::register_handler({ "itf-span" }, "interface span configurations",
127 interface_span::event_handler::handle_replay()
133 interface_span::event_handler::handle_populate(const client_db::key_t& key)
135 std::shared_ptr<interface_span_cmds::dump_cmd> cmd =
136 std::make_shared<interface_span_cmds::dump_cmd>();
141 for (auto& record : *cmd) {
142 auto& payload = record.get_payload();
144 std::shared_ptr<interface> itf_from =
145 interface::find(payload.sw_if_index_from);
146 std::shared_ptr<interface> itf_to = interface::find(payload.sw_if_index_to);
148 interface_span itf_span(*itf_from, *itf_to,
149 state_t::from_int(payload.state));
151 VOM_LOG(log_level_t::DEBUG) << "span-dump: " << itf_from->to_string()
152 << itf_to->to_string()
153 << state_t::from_int(payload.state).to_string();
156 * Write each of the discovered interfaces into the OM,
157 * but disable the HW Command q whilst we do, so that no
158 * commands are sent to VPP
160 OM::commit(key, itf_span);
165 interface_span::event_handler::order() const
167 return (dependency_t::BINDING);
171 interface_span::event_handler::show(std::ostream& os)
176 const interface_span::state_t interface_span::state_t::DISABLED(0, "disable");
177 const interface_span::state_t interface_span::state_t::RX_ENABLED(1,
179 const interface_span::state_t interface_span::state_t::TX_ENABLED(2,
181 const interface_span::state_t interface_span::state_t::TX_RX_ENABLED(
185 interface_span::state_t::state_t(int v, const std::string& s)
186 : enum_base<interface_span::state_t>(v, s)
190 interface_span::state_t
191 interface_span::state_t::from_int(uint8_t i)
195 return interface_span::state_t::DISABLED;
198 return interface_span::state_t::RX_ENABLED;
201 return interface_span::state_t::TX_ENABLED;
208 return interface_span::state_t::TX_RX_ENABLED;
213 * fd.io coding-style-patch-verification: ON
216 * eval: (c-set-style "mozilla")