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"
18 #include "vom/singular_db_funcs.hpp"
22 * A DB of all interface_span config
24 singular_db<interface_span::key_t, interface_span> interface_span::m_db;
26 interface_span::event_handler interface_span::m_evh;
28 interface_span::interface_span(const interface& itf_from,
29 const interface& itf_to,
30 interface_span::state_t state)
31 : m_itf_from(itf_from.singular())
32 , m_itf_to(itf_to.singular())
38 interface_span::interface_span(const interface_span& o)
39 : m_itf_from(o.m_itf_from)
40 , m_itf_to(o.m_itf_to)
42 , m_config(o.m_config)
46 interface_span::~interface_span()
50 // not in the DB anymore.
51 m_db.release(make_pair(m_itf_from->key(), m_itf_to->key()), this);
55 interface_span::sweep()
58 HW::enqueue(new interface_span_cmds::unconfig_cmd(
59 m_config, m_itf_from->handle(), m_itf_to->handle()));
65 interface_span::dump(std::ostream& os)
71 interface_span::replay()
74 HW::enqueue(new interface_span_cmds::config_cmd(
75 m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
80 interface_span::to_string() const
83 s << "Itf Span-config:"
84 << " itf-from:" << m_itf_from->to_string()
85 << " itf-to:" << m_itf_to->to_string() << " state:" << m_state.to_string();
91 interface_span::update(const interface_span& desired)
94 HW::enqueue(new interface_span_cmds::config_cmd(
95 m_config, m_itf_from->handle(), m_itf_to->handle(), m_state));
100 operator<<(std::ostream& os, const interface_span::key_t& key)
102 os << "[" << key.first << ", " << key.second << "]";
107 std::shared_ptr<interface_span>
108 interface_span::find_or_add(const interface_span& temp)
110 return (m_db.find_or_add(
111 make_pair(temp.m_itf_from->key(), temp.m_itf_to->key()), temp));
114 std::shared_ptr<interface_span>
115 interface_span::singular() const
117 return find_or_add(*this);
120 interface_span::event_handler::event_handler()
122 OM::register_listener(this);
123 inspect::register_handler({ "itf-span" }, "interface span configurations",
128 interface_span::event_handler::handle_replay()
134 interface_span::event_handler::handle_populate(const client_db::key_t& key)
136 std::shared_ptr<interface_span_cmds::dump_cmd> cmd =
137 std::make_shared<interface_span_cmds::dump_cmd>();
142 for (auto& record : *cmd) {
143 auto& payload = record.get_payload();
145 std::shared_ptr<interface> itf_from =
146 interface::find(payload.sw_if_index_from);
147 std::shared_ptr<interface> itf_to = interface::find(payload.sw_if_index_to);
149 interface_span itf_span(*itf_from, *itf_to,
150 state_t::from_int(payload.state));
152 VOM_LOG(log_level_t::DEBUG) << "span-dump: " << itf_from->to_string()
153 << itf_to->to_string()
154 << state_t::from_int(payload.state).to_string();
157 * Write each of the discovered interfaces into the OM,
158 * but disable the HW Command q whilst we do, so that no
159 * commands are sent to VPP
161 OM::commit(key, itf_span);
166 interface_span::event_handler::order() const
168 return (dependency_t::BINDING);
172 interface_span::event_handler::show(std::ostream& os)
177 const interface_span::state_t interface_span::state_t::DISABLED(0, "disable");
178 const interface_span::state_t interface_span::state_t::RX_ENABLED(1,
180 const interface_span::state_t interface_span::state_t::TX_ENABLED(2,
182 const interface_span::state_t interface_span::state_t::TX_RX_ENABLED(
186 interface_span::state_t::state_t(int v, const std::string& s)
187 : enum_base<interface_span::state_t>(v, s)
191 interface_span::state_t
192 interface_span::state_t::from_int(uint8_t i)
196 return interface_span::state_t::DISABLED;
199 return interface_span::state_t::RX_ENABLED;
202 return interface_span::state_t::TX_ENABLED;
209 return interface_span::state_t::TX_RX_ENABLED;
214 * fd.io coding-style-patch-verification: ON
217 * eval: (c-set-style "mozilla")