def _process_routers(self, routers, removed_routers,<EOL>device_id=None, all_routers=False):
try:<EOL><INDENT>ids_previously_hosted_routers = (<EOL>set(r_id for r_id, rdata in self.router_info.items()<EOL>if rdata.router.get('<STR_LIT>',<EOL>{}).get('<STR_LIT:id>') == device_id))<EOL>if all_routers:<EOL><INDENT>prev_router_ids = ids_previously_hosted_routers<EOL><DEDENT>else:<EOL><INDENT>prev_router_ids = (ids_previously_hosted_routers &<EOL>set([router['<STR_LIT:id>'] for router in routers]))<EOL><DEDENT>cur_router_ids = set()<EOL>deleted_routerids_list = []<EOL>for r in routers:<EOL><INDENT>if not r['<STR_LIT>']:<EOL><INDENT>continue<EOL><DEDENT>cur_router_ids.add(r['<STR_LIT:id>'])<EOL><DEDENT>for router_id in prev_router_ids - cur_router_ids:<EOL><INDENT>deleted_routerids_list.append(router_id)<EOL><DEDENT>if removed_routers:<EOL><INDENT>self._adjust_router_list_for_global_router(removed_routers)<EOL>for router in removed_routers:<EOL><INDENT>deleted_routerids_list.append(router['<STR_LIT:id>'])<EOL><DEDENT><DEDENT>self._adjust_router_list_for_global_router(routers)<EOL>for r in routers:<EOL><INDENT>LOG.debug("<STR_LIT>",<EOL>{'<STR_LIT:id>': r['<STR_LIT:id>'], '<STR_LIT>': r[ROUTER_ROLE_ATTR]})<EOL>if r['<STR_LIT:id>'] in deleted_routerids_list:<EOL><INDENT>continue<EOL><DEDENT>if r['<STR_LIT:status>'] == c_constants.ROUTER_INFO_INCOMPLETE:<EOL><INDENT>LOG.debug("<STR_LIT>",<EOL>{'<STR_LIT:id>': r['<STR_LIT:id>']})<EOL>self._update_updated_routers_cache([r['<STR_LIT:id>']])<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>if not r['<STR_LIT>']:<EOL><INDENT>continue<EOL><DEDENT>cur_router_ids.add(r['<STR_LIT:id>'])<EOL>hd = r['<STR_LIT>']<EOL>if not self._dev_status.is_hosting_device_reachable(hd):<EOL><INDENT>LOG.info("<STR_LIT>"<EOL>"<STR_LIT>", {'<STR_LIT:id>': r['<STR_LIT:id>']})<EOL>continue<EOL><DEDENT>if r['<STR_LIT:id>'] not in self.router_info:<EOL><INDENT>self._router_added(r['<STR_LIT:id>'], r)<EOL><DEDENT>ri = self.router_info[r['<STR_LIT:id>']]<EOL>ri.router = r<EOL>self._process_router(ri)<EOL><DEDENT>except ncc_errors.SessionCloseError as e:<EOL><INDENT>LOG.exception(<EOL>"<STR_LIT>", e)<EOL>if not self._dev_status.is_hosting_device_reachable(<EOL>r['<STR_LIT>']):<EOL><INDENT>LOG.debug("<STR_LIT>" %<EOL>r['<STR_LIT>']['<STR_LIT:id>'])<EOL><DEDENT>else:<EOL><INDENT>self._update_updated_routers_cache([r['<STR_LIT:id>']])<EOL>LOG.debug("<STR_LIT>" % (r['<STR_LIT:id>']))<EOL><DEDENT>continue<EOL><DEDENT>except KeyError as e:<EOL><INDENT>LOG.exception("<STR_LIT>", e)<EOL>self._update_updated_routers_cache([r['<STR_LIT:id>']])<EOL>continue<EOL><DEDENT>except cfg_exceptions.DriverException as e:<EOL><INDENT>LOG.exception("<STR_LIT>"<EOL>"<STR_LIT>", {'<STR_LIT:id>': r['<STR_LIT:id>'],<EOL>'<STR_LIT:e>': e})<EOL>self._update_updated_routers_cache([r['<STR_LIT:id>']])<EOL>continue<EOL><DEDENT>LOG.debug("<STR_LIT>",<EOL>{'<STR_LIT:id>': r['<STR_LIT:id>'], '<STR_LIT>': r[ROUTER_ROLE_ATTR]})<EOL><DEDENT>for router_id in deleted_routerids_list:<EOL><INDENT>LOG.debug("<STR_LIT>", router_id)<EOL>self._router_removed(router_id)<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>LOG.exception("<STR_LIT>",<EOL>device_id)<EOL>self.sync_devices.add(device_id)<EOL><DEDENT>
Process the set of routers.

        Iterating on the set of routers received and comparing it with the
        set of routers already in the routing service helper, new routers
        which are added are identified. Before processing check the
        reachability (via ping) of hosting device where the router is hosted.
        If device is not reachable it is backlogged.

        For routers which are only updated, call `_process_router()` on them.

        When all_routers is set to True (because of a full sync),
        this will result in the detection and deletion of routers which
        have been removed.

        Whether the router can only be assigned to a particular hosting device
        is decided and enforced by the plugin. No checks are done here.

        :param routers: The set of routers to be processed
        :param removed_routers: the set of routers which where removed
        :param device_id: Id of the hosting device
        :param all_routers: Flag for specifying a partial list of routers
        :return: None