*/
#include "vom/l3_binding.hpp"
-#include "vom/cmd.hpp"
+#include "vom/l3_binding_cmds.hpp"
+#include "vom/singular_db_funcs.hpp"
namespace VOM {
-singular_db<l3_binding::key_type_t, l3_binding> l3_binding::m_db;
+singular_db<l3_binding::key_t, l3_binding> l3_binding::m_db;
l3_binding::event_handler l3_binding::m_evh;
l3_binding::l3_binding(const interface& itf, const route::prefix_t& pfx)
: m_itf(itf.singular())
, m_pfx(pfx)
- , m_binding(true)
+ , m_binding(true, rc_t::NOOP)
{
}
l3_binding::l3_binding(const l3_binding& o)
: m_itf(o.m_itf)
, m_pfx(o.m_pfx)
- , m_binding(true)
+ , m_binding(o.m_binding)
{
}
sweep();
// not in the DB anymore.
- m_db.release(make_pair(m_itf->key(), m_pfx), this);
+ m_db.release(key(), this);
+}
+
+bool
+l3_binding::operator==(const l3_binding& l) const
+{
+ return ((m_pfx == l.m_pfx) && (*m_itf == *l.m_itf));
+}
+
+const l3_binding::key_t
+l3_binding::key() const
+{
+ return (make_pair(m_itf->key(), m_pfx));
}
void
l3_binding::sweep()
{
if (m_binding) {
- HW::enqueue(new unbind_cmd(m_binding, m_itf->handle(), m_pfx));
+ HW::enqueue(
+ new l3_binding_cmds::unbind_cmd(m_binding, m_itf->handle(), m_pfx));
}
HW::write();
}
l3_binding::replay()
{
if (m_binding) {
- HW::enqueue(new bind_cmd(m_binding, m_itf->handle(), m_pfx));
+ HW::enqueue(
+ new l3_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_pfx));
}
}
return (m_pfx);
}
+const interface&
+l3_binding::itf() const
+{
+ return (*m_itf);
+}
+
+l3_binding::const_iterator_t
+l3_binding::cbegin()
+{
+ return m_db.begin();
+}
+
+l3_binding::const_iterator_t
+l3_binding::cend()
+{
+ return m_db.end();
+}
+
std::string
l3_binding::to_string() const
{
std::ostringstream s;
- s << "L3-config:[" << m_itf->to_string() << " prefix:" << m_pfx.to_string()
+ s << "L3-binding:[" << m_itf->to_string() << " prefix:" << m_pfx.to_string()
<< " " << m_binding.to_string() << "]";
return (s.str());
l3_binding::update(const l3_binding& desired)
{
/*
- * the desired state is always that the interface should be created
- */
+ * no updates for the binding. chaning the interface or the prefix is a change
+ * to the
+ * key, hence a new object
+ */
if (!m_binding) {
- HW::enqueue(new bind_cmd(m_binding, m_itf->handle(), m_pfx));
+ HW::enqueue(
+ new l3_binding_cmds::bind_cmd(m_binding, m_itf->handle(), m_pfx));
}
}
std::shared_ptr<l3_binding>
l3_binding::find_or_add(const l3_binding& temp)
{
- return (m_db.find_or_add(make_pair(temp.m_itf->key(), temp.m_pfx), temp));
+ return (m_db.find_or_add(temp.key(), temp));
+}
+
+std::shared_ptr<l3_binding>
+l3_binding::find(const key_t& k)
+{
+ return (m_db.find(k));
}
std::shared_ptr<l3_binding>
void
l3_binding::dump(std::ostream& os)
{
- m_db.dump(os);
+ db_dump(m_db, os);
}
std::ostream&
-operator<<(std::ostream& os, const l3_binding::key_type_t& key)
+operator<<(std::ostream& os, const l3_binding::key_t& key)
{
os << "[" << key.first << ", " << key.second << "]";
*/
std::deque<std::shared_ptr<l3_binding>> l3s;
- auto it = m_db.cbegin();
+ auto it = m_db.begin();
- while (it != m_db.cend()) {
+ while (it != m_db.end()) {
/*
- * The key in the DB is a pair of the interface's name and prefix.
- * If the keys match, save the L3-config
- */
+ * The key in the DB is a pair of the interface's name and prefix.
+ * If the keys match, save the L3-config
+ */
auto key = it->first;
if (i.key() == key.first) {
l3_binding::event_handler::handle_populate(const client_db::key_t& key)
{
/**
- * This is done while populating the interfaces
- */
+ * This is done while populating the interfaces
+ */
}
dependency_t
void
l3_binding::event_handler::show(std::ostream& os)
{
- m_db.dump(os);
+ db_dump(m_db, os);
}
}