+ip_mroute::ip_mroute(const mprefix_t& mprefix)
+ : m_hw(false)
+ , m_rd(route_domain::get_default())
+ , m_mprefix(mprefix)
+ , m_paths()
+{
+}
+
+ip_mroute::ip_mroute(const ip_mroute& r)
+ : m_hw(r.m_hw)
+ , m_rd(r.m_rd)
+ , m_mprefix(r.m_mprefix)
+ , m_paths(r.m_paths)
+{
+}
+
+ip_mroute::ip_mroute(const route_domain& rd, const mprefix_t& mprefix)
+ : m_hw(false)
+ , m_rd(rd.singular())
+ , m_mprefix(mprefix)
+ , m_paths()
+{
+}
+
+void
+ip_mroute::add(const path& path, const itf_flags_t& flag)
+{
+ m_paths.insert(std::make_pair(path, flag));
+}
+
+ip_mroute::~ip_mroute()
+{
+ sweep();
+ m_db.release(key(), this);
+}
+
+const ip_mroute::key_t
+ip_mroute::key() const
+{
+ return (std::make_pair(m_rd->table_id(), m_mprefix));
+}
+
+bool
+ip_mroute::operator==(const ip_mroute& i) const
+{
+ return ((key() == i.key()) && (m_paths == i.m_paths));
+}
+
+void
+ip_mroute::sweep()
+{
+ if (m_hw) {
+ for (auto& p : m_paths)
+ HW::enqueue(new ip_mroute_cmds::delete_cmd(m_hw, m_rd->table_id(),
+ m_mprefix, p.first, p.second));
+ }
+ HW::write();
+}
+
+void
+ip_mroute::replay()
+{
+ if (m_hw) {
+ for (auto& p : m_paths)
+ HW::enqueue(new ip_mroute_cmds::update_cmd(m_hw, m_rd->table_id(),
+ m_mprefix, p.first, p.second));
+ }
+}
+std::string
+ip_mroute::to_string() const
+{
+ std::ostringstream s;
+ s << "route:[" << m_rd->to_string() << ", " << m_mprefix.to_string() << " ["
+ << m_paths << "]"
+ << "]";
+
+ return (s.str());
+}
+
+void
+ip_mroute::update(const ip_mroute& r)
+{
+ if (rc_t::OK != m_hw.rc()) {
+ for (auto& p : m_paths)
+ HW::enqueue(new ip_mroute_cmds::update_cmd(m_hw, m_rd->table_id(),
+ m_mprefix, p.first, p.second));
+ }
+}
+
+std::shared_ptr<ip_mroute>
+ip_mroute::find_or_add(const ip_mroute& temp)
+{
+ return (m_db.find_or_add(temp.key(), temp));
+}
+
+std::shared_ptr<ip_mroute>
+ip_mroute::find(const key_t& k)
+{
+ return (m_db.find(k));
+}
+
+std::shared_ptr<ip_mroute>
+ip_mroute::singular() const
+{
+ return find_or_add(*this);
+}
+
+void
+ip_mroute::dump(std::ostream& os)
+{
+ db_dump(m_db, os);
+}
+
+ip_mroute::event_handler::event_handler()
+{
+ OM::register_listener(this);
+ inspect::register_handler({ "ip-route" }, "ip route configurations", this);
+}
+
+void
+ip_mroute::event_handler::handle_replay()
+{
+ m_db.replay();
+}
+
+void
+ip_mroute::event_handler::handle_populate(const client_db::key_t& key)
+{
+ std::shared_ptr<ip_mroute_cmds::dump_v4_cmd> cmd_v4 =
+ std::make_shared<ip_mroute_cmds::dump_v4_cmd>();
+ std::shared_ptr<ip_mroute_cmds::dump_v6_cmd> cmd_v6 =
+ std::make_shared<ip_mroute_cmds::dump_v6_cmd>();
+
+ HW::enqueue(cmd_v4);
+ HW::enqueue(cmd_v6);
+ HW::write();
+
+ VOM_LOG(log_level_t::INFO) << "ip-mroute-dump: ";
+
+ for (auto& record : *cmd_v4) {
+ auto& payload = record.get_payload();
+
+ ip_address_t gaddr = from_bytes(0, payload.grp_address);
+ ip_address_t saddr = from_bytes(0, payload.src_address);
+ mprefix_t pfx(saddr, gaddr, payload.address_length);
+
+ /**
+ * populating the route domain here
+ */
+ route_domain rd_temp(payload.table_id);
+ std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id);
+ if (!rd) {
+ OM::commit(key, rd_temp);
+ }
+ ip_mroute ip_r(rd_temp, pfx);
+
+ for (unsigned int i = 0; i < payload.count; i++) {
+ vapi_type_mfib_path& p = payload.path[i];
+ ip_r.add(from_vpp(p.path, nh_proto_t::IPV4),
+ itf_flags_t::from_vpp(p.itf_flags));
+ }
+ VOM_LOG(log_level_t::INFO) << "ip-mroute-dump: " << ip_r.to_string();
+
+ /*
+ * Write each of the discovered interfaces into the OM,
+ * but disable the HW Command q whilst we do, so that no
+ * commands are sent to VPP
+ */
+ OM::commit(key, ip_r);
+ }
+
+ for (auto& record : *cmd_v6) {
+ auto& payload = record.get_payload();
+
+ ip_address_t gaddr = from_bytes(1, payload.grp_address);
+ ip_address_t saddr = from_bytes(1, payload.src_address);
+ mprefix_t pfx(saddr, gaddr, payload.address_length);
+
+ route_domain rd_temp(payload.table_id);
+ std::shared_ptr<route_domain> rd = route_domain::find(payload.table_id);
+ if (!rd) {
+ OM::commit(key, rd_temp);
+ }
+ ip_mroute ip_r(rd_temp, pfx);
+
+ for (unsigned int i = 0; i < payload.count; i++) {
+ vapi_type_mfib_path& p = payload.path[i];
+ ip_r.add(from_vpp(p.path, nh_proto_t::IPV6),
+ itf_flags_t::from_vpp(p.itf_flags));
+ }
+ VOM_LOG(log_level_t::INFO) << "ip-mroute-dump: " << ip_r.to_string();
+
+ /*
+ * Write each of the discovered interfaces into the OM,
+ * but disable the HW Command q whilst we do, so that no
+ * commands are sent to VPP
+ */
+ OM::commit(key, ip_r);
+ }
+}
+
+dependency_t
+ip_mroute::event_handler::order() const
+{
+ return (dependency_t::TABLE);
+}
+
+void
+ip_mroute::event_handler::show(std::ostream& os)
+{
+ db_dump(m_db, os);
+}
+