@Override
 @DB
 public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) {
   if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null) {
     NetworkOffering off = _offDao.findById(guestNetwork.getNetworkOfferingId());
     if (!(off.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering))) {
       TransactionLegacy txn = TransactionLegacy.currentTxn();
       txn.start();
       // 1) add router to network
       RouterNetworkVO routerNtwkMap =
           new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
       _routerNetworkDao.persist(routerNtwkMap);
       // 2) create user stats entry for the network
       UserStatisticsVO stats =
           _userStatsDao.findBy(
               router.getAccountId(),
               router.getDataCenterId(),
               guestNetwork.getId(),
               null,
               router.getId(),
               router.getType().toString());
       if (stats == null) {
         stats =
             new UserStatisticsVO(
                 router.getAccountId(),
                 router.getDataCenterId(),
                 null,
                 router.getId(),
                 router.getType().toString(),
                 guestNetwork.getId());
         _userStatsDao.persist(stats);
       }
       txn.commit();
     }
   }
 }
  @Override
  public boolean applyStaticRoutes(
      final List<StaticRouteProfile> staticRoutes, final List<DomainRouterVO> routers)
      throws ResourceUnavailableException {

    s_logger.debug("APPLYING STATIC ROUTES RULES");

    if (staticRoutes == null || staticRoutes.isEmpty()) {
      s_logger.debug("No static routes to apply");
      return true;
    }

    final StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);

    boolean result = true;
    for (final VirtualRouter router : routers) {
      if (router.getState() == State.Running) {

        result = result && routesRules.accept(_advancedVisitor, router);

      } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug(
            "Router "
                + router.getInstanceName()
                + " is in "
                + router.getState()
                + ", so not sending StaticRoute command to the backend");
      } else {
        s_logger.warn(
            "Unable to apply StaticRoute, virtual router is not in the right state "
                + router.getState());

        throw new ResourceUnavailableException(
            "Unable to apply StaticRoute on the backend,"
                + " virtual router is not in the right state",
            DataCenter.class,
            router.getDataCenterId());
      }
    }
    return result;
  }