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/l3_binding.hpp"
17 #include "vom/l3_binding_cmds.hpp"
18 #include "vom/singular_db_funcs.hpp"
21 singular_db<l3_binding::key_t, l3_binding> l3_binding::m_db;
23 l3_binding::event_handler l3_binding::m_evh;
26 * Construct a new object matching the desried state
28 l3_binding::l3_binding(const interface& itf, const route::prefix_t& pfx)
29 : m_itf(itf.singular())
31 , m_binding(true, rc_t::NOOP)
35 l3_binding::l3_binding(const l3_binding& o)
38 , m_binding(o.m_binding)
42 l3_binding::~l3_binding()
46 // not in the DB anymore.
47 m_db.release(key(), this);
51 l3_binding::operator==(const l3_binding& l) const
53 return ((m_pfx == l.m_pfx) && (*m_itf == *l.m_itf));
56 const l3_binding::key_t
57 l3_binding::key() const
59 return (make_pair(m_itf->key(), m_pfx));
67 new l3_binding_cmds::unbind_cmd(m_binding, m_itf->handle(), m_pfx));
77 new l3_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_pfx));
81 const route::prefix_t&
82 l3_binding::prefix() const
88 l3_binding::itf() const
93 l3_binding::const_iterator_t
99 l3_binding::const_iterator_t
106 l3_binding::to_string() const
108 std::ostringstream s;
109 s << "L3-binding:[" << m_itf->to_string() << " prefix:" << m_pfx.to_string()
110 << " " << m_binding.to_string() << "]";
116 l3_binding::update(const l3_binding& desired)
119 * no updates for the binding. chaning the interface or the prefix is a change
121 * key, hence a new object
125 new l3_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_pfx));
129 std::shared_ptr<l3_binding>
130 l3_binding::find_or_add(const l3_binding& temp)
132 return (m_db.find_or_add(temp.key(), temp));
135 std::shared_ptr<l3_binding>
136 l3_binding::find(const key_t& k)
138 return (m_db.find(k));
141 std::shared_ptr<l3_binding>
142 l3_binding::singular() const
144 return find_or_add(*this);
148 l3_binding::dump(std::ostream& os)
154 operator<<(std::ostream& os, const l3_binding::key_t& key)
156 os << "[" << key.first << ", " << key.second << "]";
161 l3_binding::event_handler::event_handler()
163 OM::register_listener(this);
164 inspect::register_handler({ "l3" }, "L3 bindings", this);
168 l3_binding::event_handler::handle_replay()
174 l3_binding::event_handler::handle_populate(const client_db::key_t& key)
177 * This is done while populating the interfaces
182 l3_binding::event_handler::order() const
184 return (dependency_t::BINDING);
188 l3_binding::event_handler::show(std::ostream& os)
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "mozilla")