def update_router(self, context, router_id, router):
        original_router = self.get_router(context, router_id)
        result = super(BambukL3RouterPlugin,
                       self).update_router(context, router_id, router)

        #TODO: implement it
        update = {}
        added = []
        removed = []
        if 'admin_state_up' in router['router']:
            enabled = router['router']['admin_state_up']
            if enabled != original_router['admin_state_up']:
                update['enabled'] = enabled
        """ Update static routes """
        if 'routes' in router['router']:
            routes = router['router']['routes']
            added, removed = n_utils.diff_list_of_dict(
                original_router['routes'], routes)

        if update or added or removed:
            try:
                pass
            except Exception as ex:
                LOG.exception(_LE('Unable to update router for %s'), id)
                # roll-back
                super(BambukL3RouterPlugin,
                      self).update_router(context, id, original_router)
                raise ex

        return result
    def _routes_updated(self, ri):
        """Update the state of routes in the router.

        Compares the current routes with the (configured) existing routes
        and detect what was removed or added. Then configure the
        logical router in the hosting device accordingly.
        :param ri: RouterInfo corresponding to the router.
        :return: None
        :raises: networking_cisco.plugins.cisco.cfg_agent.cfg_exceptions.
        DriverException if the configuration operation fails.
        """
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                       new_routes)
        for route in adds:
            LOG.debug("Added route entry is '%s'", route)
            # remove replaced route from deleted route
            for del_route in removes:
                if route['destination'] == del_route['destination']:
                    removes.remove(del_route)
            driver = self.driver_manager.get_driver(ri.id)
            driver.routes_updated(ri, 'replace', route)

        for route in removes:
            LOG.debug("Removed route entry is '%s'", route)
            driver = self.driver_manager.get_driver(ri.id)
            driver.routes_updated(ri, 'delete', route)
        ri.routes = new_routes
Beispiel #3
0
    def _routes_updated(self, ri):
        """Update the state of routes in the router.

        Compares the current routes with the (configured) existing routes
        and detect what was removed or added. Then configure the
        logical router in the hosting device accordingly.
        :param ri: RouterInfo corresponding to the router.
        :return: None
        :raises: neutron.plugins.cisco.cfg_agent.cfg_exceptions.DriverException
        if the configuration operation fails.
        """
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes, new_routes)
        for route in adds:
            LOG.debug("Added route entry is '%s'", route)
            # remove replaced route from deleted route
            for del_route in removes:
                if route['destination'] == del_route['destination']:
                    removes.remove(del_route)
            driver = self._drivermgr.get_driver(ri.id)
            driver.routes_updated(ri, 'replace', route)

        for route in removes:
            LOG.debug("Removed route entry is '%s'", route)
            driver = self._drivermgr.get_driver(ri.id)
            driver.routes_updated(ri, 'delete', route)
        ri.routes = new_routes
    def process_router_portforwardings(self, ri, ex_gw_port):
        if 'portforwardings' not in ri.router:
            # note(jianingy): return when portforwarding extension
            # is not enabled
            LOG.debug("Portforwarding Extension Not Enabled")
            return None
        if ex_gw_port:
            new_portfwds = ri.router['portforwardings']
            for new_portfwd in new_portfwds:
                new_portfwd['outside_addr'] = (
                    ex_gw_port.get('fixed_ips')[0].get('ip_address'))
                LOG.debug("New Portforwarding: %s" % new_portfwd.values())
            old_portfwds = ri.portforwardings
            for old_portfwd in old_portfwds:
                LOG.debug("Old Portforwarding: %s" % old_portfwd.values())
            adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                            new_portfwds)
            for portfwd in adds:
                LOG.debug("Add Portforwarding: %s" % portfwd.values())
                self._update_portforwardings(ri, 'create', portfwd)
            for portfwd in removes:
                LOG.debug("Del Portforwarding: %s" % portfwd.values())
                self._update_portforwardings(ri, 'delete', portfwd)
            ri.portforwardings = new_portfwds
        else:
            old_portfwds = ri.portforwardings
            for old_portfwd in old_portfwds:
                    LOG.debug("Del Portforwarding: %s" % old_portfwd.values())
                    self._update_portforwardings(ri, 'delete', old_portfwd)
            ri.portforwardings = []

        ri.iptables_manager.apply()
    def _update_extra_portfwds(self, context, router, portfwds):
        self._validate_fwds(context, router['id'], portfwds)
        LOG.error(_LE('portfwds var from _update_extra_portfwds function: %s'), portfwds)
        old_fwds = self._get_extra_portfwds_by_router_id(context, router['id'])
        LOG.error(_LE('old_fwds var from _update_extra_portfwds function: %s'), old_fwds)
        added, removed = utils.diff_list_of_dict(old_fwds, portfwds)
        LOG.error(_LE('added var from _update_extra_portfwds function: %s'), added)
        LOG.error(_LE('removed var from _update_extra_portfwds function: %s'), removed)
        LOG.debug(_('Removed port forwarding rules are %s'), removed)
        # note(jianingy): remove first so that we won't encounter duplicated
        #                 entry.
        for portfwd in removed:
            del_context = context.session.query(PortForwarding)
            del_context.filter_by(router_id=router['id'],
                                  outside_port=portfwd['outside_port'],
                                  inside_addr=portfwd['inside_addr'],
                                  inside_port=portfwd['inside_port'],
                                  protocol=portfwd['protocol']).delete()
        LOG.debug(_('Added port forwarding rules are %s'), added)
        for portfwd in added:
            router_fwds = PortForwarding(
                router_id=router['id'],
                outside_port=portfwd['outside_port'],
                inside_addr=portfwd['inside_addr'],
                inside_port=portfwd['inside_port'],
                protocol=portfwd['protocol'])

            context.session.add(router_fwds)
 def update_router(self, context, router_id, old_router, new_router):
     old_routes = old_router['routes'][:]
     new_routes = new_router['routes'][:]
     self._process_gw_port(old_router['gw_port'], old_routes)
     self._process_gw_port(new_router['gw_port'], new_routes)
     added, removed = utils.diff_list_of_dict(old_routes, new_routes)
     if added or removed:
         try:
             # NOTE(amotoki): PFC supports one-by-one route update at now.
             # It means there may be a case where some route is updated but
             # some not. To allow the next call of failures to sync routes
             # with Neutron side, we pass the whole new routes here.
             # PFC should support atomic route update in the future.
             self.ofc.update_ofc_router_route(context, router_id,
                                              new_routes)
             new_status = nconst.ROUTER_STATUS_ACTIVE
             self.plugin._update_resource_status(
                 context, "router", router_id, new_status)
             new_router['status'] = new_status
         except (nexc.OFCException, nexc.OFCMappingNotFound) as exc:
             with excutils.save_and_reraise_exception():
                 LOG.error(_LE("_update_ofc_routes() failed due to %s"),
                           exc)
                 new_status = nconst.ROUTER_STATUS_ERROR
                 self.plugin._update_resource_status(
                     context, "router", router_id, new_status)
     return new_router
Beispiel #7
0
 def test_diff_list_of_dict(self):
     old_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key3": "value3"}]
     new_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key4": "value4"}]
     added, removed = utils.diff_list_of_dict(old_list, new_list)
     self.assertEqual(added, [dict(key4="value4")])
     self.assertEqual(removed, [dict(key3="value3")])
Beispiel #8
0
 def test_diff_list_of_dict(self):
     old_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key3": "value3"}]
     new_list = [{"key1": "value1"},
                 {"key2": "value2"},
                 {"key4": "value4"}]
     added, removed = utils.diff_list_of_dict(old_list, new_list)
     self.assertEqual(added, [dict(key4="value4")])
     self.assertEqual(removed, [dict(key3="value3")])
Beispiel #9
0
    def update_router(self, context, id, router):
        original_router = self.get_router(context, id)
        result = super(OVNL3RouterPlugin,
                       self).update_router(context, id, router)

        update = {}
        added = []
        removed = []
        router_name = utils.ovn_name(id)
        if 'admin_state_up' in router['router']:
            enabled = router['router']['admin_state_up']
            if enabled != original_router['admin_state_up']:
                update['enabled'] = enabled

        if 'name' in router['router']:
            if router['router']['name'] != original_router['name']:
                external_ids = {
                    ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY:
                    router['router']['name']
                }
                update['external_ids'] = external_ids
        """ Update static routes """
        if 'routes' in router['router']:
            routes = router['router']['routes']
            added, removed = n_utils.diff_list_of_dict(
                original_router['routes'], routes)

        if update or added or removed:
            try:
                with self._ovn.transaction(check_error=True) as txn:
                    if update:
                        txn.add(self._ovn.update_lrouter(
                            router_name, **update))

                    for route in added:
                        txn.add(
                            self._ovn.add_static_route(
                                router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))

                    for route in removed:
                        txn.add(
                            self._ovn.delete_static_route(
                                router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))
            except Exception:
                LOG.exception(_LE('Unable to update lrouter for %s'), id)
                super(OVNL3RouterPlugin,
                      self).update_router(context, id, original_router)
                raise n_exc.ServiceUnavailable()

        return result
Beispiel #10
0
 def routes_updated(self, old_routes, new_routes):
     adds, removes = common_utils.diff_list_of_dict(old_routes, new_routes)
     for route in adds:
         LOG.debug("Added route entry is '%s'", route)
         # remove replaced route from deleted route
         for del_route in removes:
             if route['destination'] == del_route['destination']:
                 removes.remove(del_route)
         #replace success even if there is no existing route
         self.update_routing_table('replace', route)
     for route in removes:
         LOG.debug("Removed route entry is '%s'", route)
         self.update_routing_table('delete', route)
Beispiel #11
0
 def routes_updated(self, old_routes, new_routes):
     adds, removes = common_utils.diff_list_of_dict(old_routes, new_routes)
     for route in adds:
         LOG.debug("Added route entry is '%s'", route)
         # remove replaced route from deleted route
         for del_route in removes:
             if route["destination"] == del_route["destination"]:
                 removes.remove(del_route)
         # replace success even if there is no existing route
         self.update_routing_table("replace", route)
     for route in removes:
         LOG.debug("Removed route entry is '%s'", route)
         self.update_routing_table("delete", route)
Beispiel #12
0
    def update_router(self, context, id, router):
        original_router = self.get_router(context, id)
        result = super(OVNL3RouterPlugin, self).update_router(
            context, id, router)

        update = {}
        added = []
        removed = []
        router_name = utils.ovn_name(id)
        if 'admin_state_up' in router['router']:
            enabled = router['router']['admin_state_up']
            if enabled != original_router['admin_state_up']:
                update['enabled'] = enabled

        if 'name' in router['router']:
            if router['router']['name'] != original_router['name']:
                external_ids = {ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY:
                                router['router']['name']}
                update['external_ids'] = external_ids

        """ Update static routes """
        if 'routes' in router['router']:
            routes = router['router']['routes']
            added, removed = n_utils.diff_list_of_dict(
                original_router['routes'], routes)

        if update or added or removed:
            try:
                with self._ovn.transaction(check_error=True) as txn:
                    if update:
                        txn.add(self._ovn.update_lrouter(router_name,
                                **update))

                    for route in added:
                        txn.add(self._ovn.add_static_route(router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))

                    for route in removed:
                        txn.add(self._ovn.delete_static_route(router_name,
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))
            except Exception:
                LOG.exception(_LE('Unable to update lrouter for %s'), id)
                super(OVNL3RouterPlugin, self).update_router(context,
                                                             id,
                                                             original_router)
                raise n_exc.ServiceUnavailable()

        return result
    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router["id"], routes)
        old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(context, router["id"])
        added, removed = utils.diff_list_of_dict(old_routes, routes)
        LOG.debug("Added routes are %s", added)
        for route in added:
            router_routes = RouterRoute(
                router_id=router["id"], destination=route["destination"], nexthop=route["nexthop"]
            )
            context.session.add(router_routes)

        LOG.debug("Removed routes are %s", removed)
        for route in removed:
            context.session.delete(routes_dict[(route["destination"], route["nexthop"])])
Beispiel #14
0
 def process_router_portforwardings(self, ri, ex_gw_port):
     if 'portforwardings' not in ri.router:
         # return when portforwarding extension is not enabled
         return
     new_portfwds = ri.router['portforwardings']
     for new_portfwd in new_portfwds:
         new_portfwd['outside_addr'] = (
             ex_gw_port.get('fixed_ips')[0].get('ip_address'))
     old_portfwds = ri.portforwardings
     adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                                                    new_portfwds)
     for portfwd in adds:
         self._update_portforwardings(ri, 'create', portfwd)
     for portfwd in removes:
         self._update_portforwardings(ri, 'delete', portfwd)
     ri.portforwardings = new_portfwds
Beispiel #15
0
    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router['id'], routes)
        old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(
            context, router['id'])
        added, removed = utils.diff_list_of_dict(old_routes, routes)
        LOG.debug(_('Added routes are %s'), added)
        for route in added:
            router_routes = RouterRoute(router_id=router['id'],
                                        destination=route['destination'],
                                        nexthop=route['nexthop'])
            context.session.add(router_routes)

        LOG.debug(_('Removed routes are %s'), removed)
        for route in removed:
            context.session.delete(routes_dict[(route['destination'],
                                                route['nexthop'])])
Beispiel #16
0
 def process_router_portforwardings(self, ri, ex_gw_port):
     if 'portforwardings' not in ri.router:
         # return when portforwarding extension is not enabled
         return
     new_portfwds = ri.router['portforwardings']
     for new_portfwd in new_portfwds:
         new_portfwd['outside_addr'] = (
             ex_gw_port.get('fixed_ips')[0].get('ip_address'))
     old_portfwds = ri.portforwardings
     adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                                                    new_portfwds)
     for portfwd in adds:
         self._update_portforwardings(ri, 'create', portfwd)
     for portfwd in removes:
         self._update_portforwardings(ri, 'delete', portfwd)
     ri.portforwardings = new_portfwds
Beispiel #17
0
    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router['id'], routes)
        old_routes = self._get_extra_routes_by_router_id(context, router['id'])
        added, removed = utils.diff_list_of_dict(old_routes, routes)
        LOG.debug('Added routes are %s' % added)
        for route in added:
            router_routes = RouterRoute(router_id=router['id'],
                                        destination=route['destination'],
                                        nexthop=route['nexthop'])
            context.session.add(router_routes)

        LOG.debug('Removed routes are %s' % removed)
        for route in removed:
            del_context = context.session.query(RouterRoute)
            del_context.filter_by(router_id=router['id'],
                                  destination=route['destination'],
                                  nexthop=route['nexthop']).delete()
Beispiel #18
0
 def update_router(self, context, router_id, router):
     """Update the router with static route"""
     r = router['router']
     old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(
         context, router_id)
     added, removed = neutron_utils.diff_list_of_dict(
         old_routes, r['routes'])
     try:
         updated_router = super(BrocadeSVIPlugin, self).\
             update_router(context, router_id, router)
         if 'routes' in r:
             self._invoke_nos_driver_api('update_router', router_id, None,
                                         None, None, None, added, removed)
     except Exception as e:
         LOG.error(_LE("Failed to modify route %s"), str(e))
         raise e
     return updated_router
Beispiel #19
0
 def routes_updated(self, ri):
     new_routes = ri.router['routes']
     old_routes = ri.routes
     adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                    new_routes)
     for route in adds:
         LOG.debug(_("Added route entry is '%s'"), route)
         # remove replaced route from deleted route
         for del_route in removes:
             if route['destination'] == del_route['destination']:
                 removes.remove(del_route)
         #replace success even if there is no existing route
         self._update_routing_table(ri, 'replace', route)
     for route in removes:
         LOG.debug(_("Removed route entry is '%s'"), route)
         self._update_routing_table(ri, 'delete', route)
     ri.routes = new_routes
Beispiel #20
0
 def update_ofc_router_route(self, context, router_id, new_routes):
     ofc_router_id = self._get_ofc_id(context, "ofc_router", router_id)
     ofc_routes = self.driver.list_router_routes(ofc_router_id)
     route_dict = {}
     cur_routes = []
     for r in ofc_routes:
         key = ','.join((r['destination'], r['nexthop']))
         route_dict[key] = r['id']
         del r['id']
         cur_routes.append(r)
     added, removed = utils.diff_list_of_dict(cur_routes, new_routes)
     for r in removed:
         key = ','.join((r['destination'], r['nexthop']))
         route_id = route_dict[key]
         self.driver.delete_router_route(route_id)
     for r in added:
         self.driver.add_router_route(ofc_router_id, r['destination'],
                                      r['nexthop'])
Beispiel #21
0
 def update_ofc_router_route(self, context, router_id, new_routes):
     ofc_router_id = self._get_ofc_id(context, "ofc_router", router_id)
     ofc_routes = self.driver.list_router_routes(ofc_router_id)
     route_dict = {}
     cur_routes = []
     for r in ofc_routes:
         key = ','.join((r['destination'], r['nexthop']))
         route_dict[key] = r['id']
         del r['id']
         cur_routes.append(r)
     added, removed = utils.diff_list_of_dict(cur_routes, new_routes)
     for r in removed:
         key = ','.join((r['destination'], r['nexthop']))
         route_id = route_dict[key]
         self.driver.delete_router_route(route_id)
     for r in added:
         self.driver.add_router_route(ofc_router_id, r['destination'],
                                      r['nexthop'])
Beispiel #22
0
 def update_router(self, context, id, router):
     r = router['router']
     with context.session.begin(subtransactions=True):
         if 'routes' in r:
             old_routes = self._get_extra_routes_by_router_id(context,
                                                              id)
             added, removed = utils.diff_list_of_dict(old_routes,
                                                      r['routes'])
             self._validate_nuage_staticroutes(old_routes, added, removed)
             ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
                 context.session, id)
             if not ent_rtr_mapping:
                 msg = (_("Router %s does not hold net-partition "
                          "assoc on VSD. extra-route failed") % id)
                 raise n_exc.BadRequest(resource='router', msg=msg)
             # Let it do internal checks first and verify it.
             router_updated = super(NuagePlugin,
                                    self).update_router(context,
                                                        id,
                                                        router)
             for route in removed:
                 rtr_rt_mapping = nuagedb.get_router_route_mapping(
                     context.session, id, route)
                 if rtr_rt_mapping:
                     self.nuageclient.delete_nuage_staticroute(
                         rtr_rt_mapping['nuage_route_id'])
                     nuagedb.delete_static_route(context.session,
                                                 rtr_rt_mapping)
             for route in added:
                 params = {
                     'parent_id': ent_rtr_mapping['nuage_router_id'],
                     'net': netaddr.IPNetwork(route['destination']),
                     'nexthop': route['nexthop']
                 }
                 nuage_rt_id = self.nuageclient.create_nuage_staticroute(
                     params)
                 nuagedb.add_static_route(context.session,
                                          id, nuage_rt_id,
                                          route['destination'],
                                          route['nexthop'])
         else:
             router_updated = super(NuagePlugin, self).update_router(
                 context, id, router)
     return router_updated
Beispiel #23
0
 def update_router(self, context, id, router):
     r = router['router']
     with context.session.begin(subtransactions=True):
         if 'routes' in r:
             old_routes = self._get_extra_routes_by_router_id(context,
                                                              id)
             added, removed = utils.diff_list_of_dict(old_routes,
                                                      r['routes'])
             self._validate_nuage_staticroutes(old_routes, added, removed)
             ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
                 context.session, id)
             if not ent_rtr_mapping:
                 msg = (_("Router %s does not hold net-partition "
                          "assoc on VSD. extra-route failed") % id)
                 raise n_exc.BadRequest(resource='router', msg=msg)
             # Let it do internal checks first and verify it.
             router_updated = super(NuagePlugin,
                                    self).update_router(context,
                                                        id,
                                                        router)
             for route in removed:
                 rtr_rt_mapping = nuagedb.get_router_route_mapping(
                     context.session, id, route)
                 if rtr_rt_mapping:
                     self.nuageclient.delete_nuage_staticroute(
                         rtr_rt_mapping['nuage_route_id'])
                     nuagedb.delete_static_route(context.session,
                                                 rtr_rt_mapping)
             for route in added:
                 params = {
                     'parent_id': ent_rtr_mapping['nuage_router_id'],
                     'net': netaddr.IPNetwork(route['destination']),
                     'nexthop': route['nexthop']
                 }
                 nuage_rt_id = self.nuageclient.create_nuage_staticroute(
                     params)
                 nuagedb.add_static_route(context.session,
                                          id, nuage_rt_id,
                                          route['destination'],
                                          route['nexthop'])
         else:
             router_updated = super(NuagePlugin, self).update_router(
                 context, id, router)
     return router_updated
Beispiel #24
0
    def _update_extra_routes(self, context, router, routes):
        self._validate_routes(context, router['id'],
                              routes)
        old_routes = self._get_extra_routes_by_router_id(
            context, router['id'])
        added, removed = utils.diff_list_of_dict(old_routes,
                                                 routes)
        LOG.debug(_('Added routes are %s'), added)
        for route in added:
            router_routes = RouterRoute(
                router_id=router['id'],
                destination=route['destination'],
                nexthop=route['nexthop'])
            context.session.add(router_routes)

        LOG.debug(_('Removed routes are %s'), removed)
        for route in removed:
            del_context = context.session.query(RouterRoute)
            del_context.filter_by(router_id=router['id'],
                                  destination=route['destination'],
                                  nexthop=route['nexthop']).delete()
Beispiel #25
0
 def process_router_portforwardings(self, ex_gw_port):
     if 'portforwardings' not in self.router:
         return
     new_portfwds = self.router['portforwardings']
     for new_portfwd in new_portfwds:
         new_portfwd['outside_addr'] = (
             ex_gw_port.get('fixed_ips')[0].get('ip_address'))
     old_portfwds = self.portforwarding
     adds, removes = common_utils.diff_list_of_dict(old_portfwds,
                                                    new_portfwds)
     LOG.debug(_("process_router_portforwardings var adds'%s'"), adds)
     LOG.debug(_("process_router_portforwardings var removes'%s'"), removes)
     LOG.debug(_("process_router_portforwardings var old_portfwds'%s'"),
               old_portfwds)
     LOG.debug(_("process_router_portforwardings var new_portfwds'%s'"),
               new_portfwds)
     for portfwd in adds:
         self._update_portforwardings('create', portfwd)
     for portfwd in removes:
         self._update_portforwardings('delete', portfwd)
     self.portforwarding = new_portfwds
    def routes_updated(self, ri):
        LOG.debug("Enter routes updated function")
        data = {}
        data['id'] = ri.router_id
        data['subnets'] = self._get_engine_subnets(
            ri.router.get(l3_constants.SNAT_ROUTER_INTF_KEY, []))
        ex_gw_port = self._get_ex_gw_port(ri)
        data['ext_net_info'] = {
            'vlan': ex_gw_port['vlan'],
            'ip': ex_gw_port['fixed_ips'][0]['ip_address']
        }
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes, new_routes)

        if removes:
            data['routes'] = self._get_engine_routes(removes, ex_gw_port)
            self.dataengine_rpc.router_route_delete(data)

        if adds:
            data['routes'] = self._get_engine_routes(adds, ex_gw_port)
            self.dataengine_rpc.router_route_add(data)
    def routes_updated(self, ri):
        LOG.debug("Enter routes updated function")
        data = {}
        data['id'] = ri.router_id
        data['subnets'] = self._get_engine_subnets(ri.router.get(l3_constants.SNAT_ROUTER_INTF_KEY, []))
        ex_gw_port = self._get_ex_gw_port(ri)
        data['ext_net_info'] = {
            'vlan': ex_gw_port['vlan'],
            'ip': ex_gw_port['fixed_ips'][0]['ip_address']
        }
        new_routes = ri.router['routes']
        old_routes = ri.routes
        adds, removes = common_utils.diff_list_of_dict(old_routes,
                                                       new_routes)

        if removes:
            data['routes'] = self._get_engine_routes(removes, ex_gw_port)
            self.dataengine_rpc.router_route_delete(data)
        
        if adds:
            data['routes'] = self._get_engine_routes(adds, ex_gw_port)
            self.dataengine_rpc.router_route_add(data)
Beispiel #28
0
    def _update_extra_portfwds(self, context, router, portfwds):
        old_fwds = self._get_extra_portfwds_by_router_id(context, router['id'])
        added, removed = utils.diff_list_of_dict(old_fwds, portfwds)

        LOG.debug(_('Removed port forwarding rules are %s'), removed)
        for portfwd in removed:
            del_context = context.session.query(PortForwardingRule)
            del_context.filter_by(router_id=router['id'],
                                  outside_port=portfwd['outside_port'],
                                  inside_addr=portfwd['inside_addr'],
                                  inside_port=portfwd['inside_port'],
                                  protocol=portfwd['protocol']).delete()

        LOG.debug(_('Added port forwarding rules are %s'), added)
        for portfwd in added:
            router_fwds = PortForwardingRule(
                router_id=router['id'],
                outside_port=portfwd['outside_port'],
                inside_addr=portfwd['inside_addr'],
                inside_port=portfwd['inside_port'],
                protocol=portfwd['protocol'])

            context.session.add(router_fwds)
 def update_router(self, context, router_id, router):
     """Update the router with static route"""
     r = router['router']
     old_routes, routes_dict = self._get_extra_routes_dict_by_router_id(
         context, router_id)
     added, removed = neutron_utils.diff_list_of_dict(old_routes,
                                                      r['routes'])
     try:
         updated_router = super(BrocadeSVIPlugin, self).\
             update_router(context, router_id, router)
         if 'routes' in r:
             self._invoke_nos_driver_api('update_router',
                                         router_id,
                                         None,
                                         None,
                                         None,
                                         None,
                                         added,
                                         removed)
     except Exception as e:
         LOG.error(_LE("Failed to modify route %s"), str(e))
         raise e
     return updated_router
    def _update_extra_portfwds(self, context, router, portfwds):
        old_fwds = self._get_extra_portfwds_by_router_id(
            context, router['id'])
        added, removed = utils.diff_list_of_dict(old_fwds, portfwds)

        LOG.debug(_('Removed port forwarding rules are %s'), removed)
        for portfwd in removed:
            del_context = context.session.query(PortForwardingRule)
            del_context.filter_by(router_id=router['id'],
                                  outside_port=portfwd['outside_port'],
                                  inside_addr=portfwd['inside_addr'],
                                  inside_port=portfwd['inside_port'],
                                  protocol=portfwd['protocol']).delete()

        LOG.debug(_('Added port forwarding rules are %s'), added)
        for portfwd in added:
            router_fwds = PortForwardingRule(
                router_id=router['id'],
                outside_port=portfwd['outside_port'],
                inside_addr=portfwd['inside_addr'],
                inside_port=portfwd['inside_port'],
                protocol=portfwd['protocol'])

            context.session.add(router_fwds)
Beispiel #31
0
    def sync_routers_and_rports(self, ctx):
        """Sync Routers between neutron and NB.

        @param ctx: neutron context
        @type  ctx: object of type neutron.context.Context
        @var   db_routers: List of Routers from neutron DB
        @var   db_router_ports: List of Router ports from neutron DB
        @var   lrouters: NB dictionary of logical routers and
               the corresponding logical router ports.
               vs list-of-acls
        @var   del_lrouters_list: List of Routers that need to be
               deleted from NB
        @var   del_lrouter_ports_list: List of Router ports that need to be
               deleted from NB
        @return: Nothing
        """
        if not config.is_ovn_l3():
            LOG.debug("OVN L3 mode is disabled, skipping "
                      "sync routers and router ports")
            return

        LOG.debug('OVN-NB Sync Routers and Router ports started')
        db_routers = {}
        db_router_ports = {}
        for router in self.l3_plugin.get_routers(ctx):
            db_routers[router['id']] = router

        interfaces = self.l3_plugin._get_sync_interfaces(ctx,
                                                         db_routers.keys())
        for interface in interfaces:
            db_router_ports[interface['id']] = interface
        lrouters = self.ovn_api.get_all_logical_routers_with_rports()
        del_lrouters_list = []
        del_lrouter_ports_list = []
        update_sroutes_list = []
        for lrouter in lrouters:
            if lrouter['name'] in db_routers:
                for lrport in lrouter['ports']:
                    if lrport in db_router_ports:
                        del db_router_ports[lrport]
                    else:
                        del_lrouter_ports_list.append(
                            {'port': lrport, 'lrouter': lrouter['name']})
                if 'routes' in db_routers[lrouter['name']]:
                    db_routes = db_routers[lrouter['name']]['routes']
                else:
                    db_routes = []
                ovn_routes = lrouter['static_routes']
                add_routes, del_routes = n_utils.diff_list_of_dict(
                    ovn_routes, db_routes)
                update_sroutes_list.append({'id': lrouter['name'],
                                            'add': add_routes,
                                            'del': del_routes})
                del db_routers[lrouter['name']]
            else:
                del_lrouters_list.append(lrouter)

        for r_id, router in db_routers.items():
            LOG.warning(_LW("Router found in Neutron but not in "
                            "OVN DB, router id=%s"), router['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router %s in OVN NB DB"),
                                router['id'])
                    self.l3_plugin.create_lrouter_in_ovn(router)
                    if 'routes' in router:
                        update_sroutes_list.append(
                            {'id': router['id'], 'add': router['routes'],
                             'del': []})
                except RuntimeError:
                    LOG.warning(_LW("Create router in OVN NB failed for"
                                    " router %s"), router['id'])

        for rp_id, rrport in db_router_ports.items():
            LOG.warning(_LW("Router Port found in Neutron but not in OVN "
                            "DB, router port_id=%s"), rrport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router port %s in "
                                    "OVN NB DB"), rrport['id'])
                    self.l3_plugin.create_lrouter_port_in_ovn(
                        ctx, rrport['device_id'], rrport)
                except RuntimeError:
                    LOG.warning(_LW("Create router port in OVN "
                                    "NB failed for"
                                    " router port %s"), rrport['id'])

        with self.ovn_api.transaction(check_error=True) as txn:
            for lrouter in del_lrouters_list:
                LOG.warning(_LW("Router found in OVN but not in "
                                "Neutron, router id=%s"), lrouter['name'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the router %s from OVN NB DB"),
                                lrouter['name'])
                    txn.add(self.ovn_api.delete_lrouter(
                            utils.ovn_name(lrouter['name'])))

            for lrport_info in del_lrouter_ports_list:
                LOG.warning(_LW("Router Port found in OVN but not in "
                                "Neutron, port_id=%s"), lrport_info['port'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the port %s from OVN NB DB"),
                                lrport_info['port'])
                    txn.add(self.ovn_api.delete_lrouter_port(
                            utils.ovn_lrouter_port_name(lrport_info['port']),
                            utils.ovn_name(lrport_info['lrouter']),
                            if_exists=False))
            for sroute in update_sroutes_list:
                if sroute['add']:
                    LOG.warning("Router %s static routes %s found in "
                                "Neutron but not in OVN", sroute['id'],
                                sroute['add'])
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(_LW("Add static routes %s to OVN NB DB"),
                                    sroute['add'])
                        for route in sroute['add']:
                            txn.add(self.ovn_api.add_static_route(
                                utils.ovn_name(sroute['id']),
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))
                if sroute['del']:
                    LOG.warning("Router %s static routes %s found in "
                                "OVN but not in Neutron", sroute['id'],
                                sroute['del'])
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(_LW("Delete static routes %s from OVN "
                                        "NB DB"), sroute['del'])
                        for route in sroute['del']:
                            txn.add(self.ovn_api.delete_static_route(
                                utils.ovn_name(sroute['id']),
                                ip_prefix=route['destination'],
                                nexthop=route['nexthop']))
        LOG.debug('OVN-NB Sync routers and router ports finished')
Beispiel #32
0
    def sync_routers_and_rports(self, ctx):
        """Sync Routers between neutron and NB.

        @param ctx: neutron context
        @type  ctx: object of type neutron.context.Context
        @var   db_routers: List of Routers from neutron DB
        @var   db_router_ports: List of Router ports from neutron DB
        @var   lrouters: NB dictionary of logical routers and
               the corresponding logical router ports.
               vs list-of-acls
        @var   del_lrouters_list: List of Routers that need to be
               deleted from NB
        @var   del_lrouter_ports_list: List of Router ports that need to be
               deleted from NB
        @return: Nothing
        """
        if not config.is_ovn_l3():
            LOG.debug("OVN L3 mode is disabled, skipping "
                      "sync routers and router ports")
            return

        LOG.debug('OVN-NB Sync Routers and Router ports started')
        db_routers = {}
        db_router_ports = {}
        for router in self.l3_plugin.get_routers(ctx):
            db_routers[router['id']] = router

        interfaces = self.l3_plugin._get_sync_interfaces(
            ctx, db_routers.keys())
        for interface in interfaces:
            db_router_ports[interface['id']] = interface
        lrouters = self.ovn_api.get_all_logical_routers_with_rports()
        del_lrouters_list = []
        del_lrouter_ports_list = []
        update_sroutes_list = []
        for lrouter in lrouters:
            if lrouter['name'] in db_routers:
                for lrport in lrouter['ports']:
                    if lrport in db_router_ports:
                        del db_router_ports[lrport]
                    else:
                        del_lrouter_ports_list.append({
                            'port':
                            lrport,
                            'lrouter':
                            lrouter['name']
                        })
                if 'routes' in db_routers[lrouter['name']]:
                    db_routes = db_routers[lrouter['name']]['routes']
                else:
                    db_routes = []
                ovn_routes = lrouter['static_routes']
                add_routes, del_routes = n_utils.diff_list_of_dict(
                    ovn_routes, db_routes)
                update_sroutes_list.append({
                    'id': lrouter['name'],
                    'add': add_routes,
                    'del': del_routes
                })
                del db_routers[lrouter['name']]
            else:
                del_lrouters_list.append(lrouter)

        for r_id, router in db_routers.items():
            LOG.warning(
                _LW("Router found in Neutron but not in "
                    "OVN DB, router id=%s"), router['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router %s in OVN NB DB"),
                                router['id'])
                    self.l3_plugin.create_lrouter_in_ovn(router)
                    if 'routes' in router:
                        update_sroutes_list.append({
                            'id': router['id'],
                            'add': router['routes'],
                            'del': []
                        })
                except RuntimeError:
                    LOG.warning(
                        _LW("Create router in OVN NB failed for"
                            " router %s"), router['id'])

        for rp_id, rrport in db_router_ports.items():
            LOG.warning(
                _LW("Router Port found in Neutron but not in OVN "
                    "DB, router port_id=%s"), rrport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(
                        _LW("Creating the router port %s in "
                            "OVN NB DB"), rrport['id'])
                    self.l3_plugin.create_lrouter_port_in_ovn(
                        ctx, rrport['device_id'], rrport)
                except RuntimeError:
                    LOG.warning(
                        _LW("Create router port in OVN "
                            "NB failed for"
                            " router port %s"), rrport['id'])

        with self.ovn_api.transaction(check_error=True) as txn:
            for lrouter in del_lrouters_list:
                LOG.warning(
                    _LW("Router found in OVN but not in "
                        "Neutron, router id=%s"), lrouter['name'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the router %s from OVN NB DB"),
                                lrouter['name'])
                    txn.add(
                        self.ovn_api.delete_lrouter(
                            utils.ovn_name(lrouter['name'])))

            for lrport_info in del_lrouter_ports_list:
                LOG.warning(
                    _LW("Router Port found in OVN but not in "
                        "Neutron, port_id=%s"), lrport_info['port'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the port %s from OVN NB DB"),
                                lrport_info['port'])
                    txn.add(
                        self.ovn_api.delete_lrouter_port(
                            utils.ovn_lrouter_port_name(lrport_info['port']),
                            utils.ovn_name(lrport_info['lrouter']),
                            if_exists=False))
            for sroute in update_sroutes_list:
                if sroute['add']:
                    LOG.warning(
                        _LW("Router %(id)s static routes %(route)s "
                            "found in Neutron but not in OVN"), {
                                'id': sroute['id'],
                                'route': sroute['add']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(_LW("Add static routes %s to OVN NB DB"),
                                    sroute['add'])
                        for route in sroute['add']:
                            txn.add(
                                self.ovn_api.add_static_route(
                                    utils.ovn_name(sroute['id']),
                                    ip_prefix=route['destination'],
                                    nexthop=route['nexthop']))
                if sroute['del']:
                    LOG.warning(
                        _LW("Router %(id)s static routes %(route)s "
                            "found in OVN but not in Neutron"), {
                                'id': sroute['id'],
                                'route': sroute['del']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(
                            _LW("Delete static routes %s from OVN "
                                "NB DB"), sroute['del'])
                        for route in sroute['del']:
                            txn.add(
                                self.ovn_api.delete_static_route(
                                    utils.ovn_name(sroute['id']),
                                    ip_prefix=route['destination'],
                                    nexthop=route['nexthop']))
        LOG.debug('OVN-NB Sync routers and router ports finished')
Beispiel #33
0
    def sync_routers_and_rports(self, ctx):
        """Sync Routers between neutron and NB.

        @param ctx: neutron context
        @type  ctx: object of type neutron.context.Context
        @var   db_routers: List of Routers from neutron DB
        @var   db_router_ports: List of Router ports from neutron DB
        @var   lrouters: NB dictionary of logical routers and
               the corresponding logical router ports.
               vs list-of-acls
        @var   del_lrouters_list: List of Routers that need to be
               deleted from NB
        @var   del_lrouter_ports_list: List of Router ports that need to be
               deleted from NB
        @return: Nothing
        """
        if not config.is_ovn_l3():
            LOG.debug("OVN L3 mode is disabled, skipping "
                      "sync routers and router ports")
            return

        LOG.debug('OVN-NB Sync Routers and Router ports started')
        db_routers = {}
        db_router_ports = {}
        db_gateway_ports = {}
        db_fips = {}
        for router in self.l3_plugin.get_routers(ctx):
            db_routers[router['id']] = router
            db_routers[router['id']]['floating_ips'] = []

        db_routers_keys = db_routers.keys()
        fips = self.l3_plugin.get_floatingips(ctx,
                                              {'router_id': db_routers_keys})
        interfaces = self.l3_plugin._get_sync_interfaces(
            ctx, db_routers_keys, [
                lib_constants.DEVICE_OWNER_ROUTER_INTF,
                lib_constants.DEVICE_OWNER_ROUTER_GW
            ])
        for fip in fips:
            db_routers[fip['router_id']]['floating_ips'].append({
                'floating_ip_address':
                fip['floating_ip_address'],
                'fixed_ip_address':
                fip['fixed_ip_address']
            })
        for interface in interfaces:
            if (interface['device_owner'] ==
                    lib_constants.DEVICE_OWNER_ROUTER_INTF):
                db_router_ports[interface['id']] = interface
                db_router_ports[interface['id']]['networks'] = sorted(
                    self.l3_plugin.get_networks_for_lrouter_port(
                        ctx, interface['fixed_ips']))
            else:
                db_gateway_ports[interface['id']] = interface
                db_gateway_ports[interface['id']]['networks'] = sorted(
                    self.l3_plugin.get_networks_for_lrouter_port(
                        ctx, interface['fixed_ips']))

        LOG.debug("Get neutron routers=%s", db_routers)
        LOG.debug("Get neutron router ports=%s", db_router_ports)
        LOG.debug("Get neutron gateway ports=%s", db_gateway_ports)

        lrouters = self.ovn_api.get_all_logical_routers_with_rports()
        LOG.debug("Get ovn routers=%s", lrouters)
        del_lrouters_list = []
        del_lrouter_ports_list = []
        del_gwrouter_ports_list = []
        update_sroutes_list = []
        update_fips_list = []
        update_lrport_list = []
        for lrouter in lrouters:
            if lrouter['name'] in db_routers:
                for lrport, lrport_nets in lrouter['ports'].items():
                    if lrport in db_router_ports:
                        db_lrport_nets = db_router_ports[lrport]['networks']
                        if db_lrport_nets != sorted(lrport_nets):
                            update_lrport_list.append(
                                (lrouter['name'], db_router_ports[lrport]))
                        del db_router_ports[lrport]
                    else:
                        del_lrouter_ports_list.append({
                            'port':
                            lrport,
                            'lrouter':
                            lrouter['name']
                        })

                for gwport, gwport_nets in lrouter['gateway_ports'].items():
                    if gwport in db_gateway_ports:
                        del db_gateway_ports[gwport]
                    else:
                        del_gwrouter_ports_list.append({
                            'port':
                            gwport,
                            'lrouter':
                            lrouter['name'],
                            'next_hop':
                            lrouter['next_hop']
                        })

                if 'routes' in db_routers[lrouter['name']]:
                    db_routes = db_routers[lrouter['name']]['routes']
                else:
                    db_routes = []
                ovn_routes = lrouter['static_routes']
                add_routes, del_routes = n_utils.diff_list_of_dict(
                    ovn_routes, db_routes)
                update_sroutes_list.append({
                    'id': lrouter['name'],
                    'del': del_routes,
                    'add': add_routes
                })
                ovn_fips = lrouter['floating_ips']
                db_fips = db_routers[lrouter['name']]['floating_ips']
                add_fips, del_fips = n_utils.diff_list_of_dict(
                    ovn_fips, db_fips)
                update_fips_list.append({
                    'id': lrouter['name'],
                    'add': add_fips,
                    'del': del_fips
                })
                del db_routers[lrouter['name']]
            else:
                del_lrouters_list.append(lrouter)

        for r_id, router in db_routers.items():
            LOG.warning(
                _LW("Router found in Neutron but not in "
                    "OVN DB, router id=%s"), router['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(_LW("Creating the router %s in OVN NB DB"),
                                router['id'])
                    self.l3_plugin.create_lrouter_in_ovn(router)
                    if 'routes' in router:
                        update_sroutes_list.append({
                            'id': router['id'],
                            'add': router['routes'],
                            'del': []
                        })
                    if 'floating_ips' in router:
                        update_fips_list.append({
                            'id': router['id'],
                            'add': router['floating_ips'],
                            'del': []
                        })
                except RuntimeError:
                    LOG.warning(
                        _LW("Create router in OVN NB failed for"
                            " router %s"), router['id'])

        for rp_id, rrport in db_router_ports.items():
            LOG.warning(
                _LW("Router Port found in Neutron but not in OVN "
                    "DB, router port_id=%s"), rrport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(
                        _LW("Creating the router port %s in "
                            "OVN NB DB"), rrport['id'])
                    self.l3_plugin.create_lrouter_port_in_ovn(
                        ctx, rrport['device_id'], rrport)
                except RuntimeError:
                    LOG.warning(
                        _LW("Create router port in OVN "
                            "NB failed for"
                            " router port %s"), rrport['id'])

        for router_id, rport in update_lrport_list:
            LOG.warning(
                _LW("Router Port port_id=%s needs to be updated"
                    " for networks changed"), rport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(
                        _LW("Updating networks on router port %s in "
                            "OVN NB DB"), rport['id'])
                    self.l3_plugin.update_lrouter_port_in_ovn(
                        ctx, router_id, rport, rport['networks'])
                except RuntimeError:
                    LOG.warning(
                        _LW("Update router port networks in OVN "
                            "NB failed for"
                            " router port %s"), rport['id'])

        for gwport_info in del_gwrouter_ports_list:
            LOG.warning(
                _LW("Gateway Port found in OVN but not in "
                    "Neutron, port_id=%s"), gwport_info['port'])
            if self.mode == SYNC_MODE_REPAIR:
                LOG.warning(_LW("Deleting the port %s from OVN NB DB"),
                            gwport_info['port'])
                self.l3_plugin.delete_gw_router_port_in_ovn(
                    gwport_info['lrouter'], gwport_info['port'],
                    gwport_info['next_hop'])

        for gwp_id, gwport in db_gateway_ports.items():
            LOG.warning(
                _LW("Gateway Port found in Neutron but not in OVN "
                    "DB, gateway port_id=%s"), gwport['id'])
            if self.mode == SYNC_MODE_REPAIR:
                try:
                    LOG.warning(
                        _LW("Creating the gateway port %s in "
                            "OVN NB DB"), gwport['id'])
                    self.l3_plugin.create_gw_router_port_in_ovn(
                        ctx, gwport['device_id'], gwport)
                except RuntimeError:
                    LOG.warning(
                        _LW("Create gateway port in OVN "
                            "NB failed for"
                            " gateway port %s"), gwport['id'])

        with self.ovn_api.transaction(check_error=True) as txn:
            for lrouter in del_lrouters_list:
                LOG.warning(
                    _LW("Router found in OVN but not in "
                        "Neutron, router id=%s"), lrouter['name'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the router %s from OVN NB DB"),
                                lrouter['name'])
                    txn.add(
                        self.ovn_api.delete_lrouter(
                            utils.ovn_name(lrouter['name'])))
                    txn.add(
                        self.ovn_api.delete_lrouter(
                            utils.ovn_gateway_name(lrouter['name'])))
                    txn.add(
                        self.ovn_api.delete_lswitch(
                            utils.ovn_transit_name(lrouter['name'])))

            for lrport_info in del_lrouter_ports_list:
                LOG.warning(
                    _LW("Router Port found in OVN but not in "
                        "Neutron, port_id=%s"), lrport_info['port'])
                if self.mode == SYNC_MODE_REPAIR:
                    LOG.warning(_LW("Deleting the port %s from OVN NB DB"),
                                lrport_info['port'])
                    txn.add(
                        self.ovn_api.delete_lrouter_port(
                            utils.ovn_lrouter_port_name(lrport_info['port']),
                            utils.ovn_name(lrport_info['lrouter']),
                            if_exists=False))

            for sroute in update_sroutes_list:
                if sroute['add']:
                    LOG.warning(
                        _LW("Router %(id)s static routes %(route)s "
                            "found in Neutron but not in OVN"), {
                                'id': sroute['id'],
                                'route': sroute['add']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(_LW("Add static routes %s to OVN NB DB"),
                                    sroute['add'])
                        for route in sroute['add']:
                            txn.add(
                                self.ovn_api.add_static_route(
                                    utils.ovn_name(sroute['id']),
                                    ip_prefix=route['destination'],
                                    nexthop=route['nexthop']))
                if sroute['del']:
                    LOG.warning(
                        _LW("Router %(id)s static routes %(route)s "
                            "found in OVN but not in Neutron"), {
                                'id': sroute['id'],
                                'route': sroute['del']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(
                            _LW("Delete static routes %s from OVN "
                                "NB DB"), sroute['del'])
                        for route in sroute['del']:
                            txn.add(
                                self.ovn_api.delete_static_route(
                                    utils.ovn_name(sroute['id']),
                                    ip_prefix=route['destination'],
                                    nexthop=route['nexthop']))

            for fip in update_fips_list:
                if fip['del']:
                    LOG.warning(
                        _LW("Router %(id)s floating ips %(fip)s "
                            "found in OVN but not in Neutron"), {
                                'id': fip['id'],
                                'fip': fip['del']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(
                            _LW("Delete floating ips %s from OVN NB DB"),
                            fip['del'])
                        for ifip in fip['del']:
                            txn.add(
                                self.ovn_api.delete_nat(
                                    utils.ovn_gateway_name(fip['id']),
                                    logical_ip=ifip['fixed_ip_address'],
                                    external_ip=ifip['floating_ip_address'],
                                    type='dnat_and_snat'))
                if fip['add']:
                    LOG.warning(
                        _LW("Router %(id)s floating ips %(fip)s "
                            "found in Neutron but not in OVN"), {
                                'id': fip['id'],
                                'fip': fip['add']
                            })
                    if self.mode == SYNC_MODE_REPAIR:
                        LOG.warning(_LW("Add floating ips %s to OVN NB DB"),
                                    fip['add'])
                        for ifip in fip['add']:
                            txn.add(
                                self.ovn_api.add_nat(
                                    utils.ovn_gateway_name(fip['id']),
                                    logical_ip=ifip['fixed_ip_address'],
                                    external_ip=ifip['floating_ip_address'],
                                    type='dnat_and_snat'))

        LOG.debug('OVN-NB Sync routers and router ports finished')