@Test public void testConvertToExternalRoute() { StaticRoute.Builder sb = StaticRoute.builder() .setAdministrativeCost(1) .setNetwork(Prefix.parse("2.2.2.2/32")) .setNextHopInterface("Null"); StaticRoute route = sb.build(); RoutingPolicy exportPolicy = RoutingPolicy.builder() .setOwner(_c) .setName("EXPORT_POLICY") .setStatements( ImmutableList.of( new If( new MatchPrefixSet( DestinationNetwork.instance(), new ExplicitPrefixSet( new PrefixSpace( PrefixRange.fromPrefix(Prefix.parse("2.2.2.2/32"))))), ImmutableList.of( new SetOspfMetricType(OspfMetricType.E1), Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement())))) .build(); assertThat( _routingProcess.convertToExternalRoute(route, exportPolicy).get(), equalTo( OspfExternalType1Route.builder() .setNetwork(route.getNetwork()) .setMetric(0) .setLsaMetric(0) .setCostToAdvertiser(0) .setArea(OspfRoute.NO_AREA) .setAdmin(300) .setAdvertiser(_c.getHostname()) .setNonRouting(true) .build())); assertFalse( "Export policy does not permit export", _routingProcess .convertToExternalRoute(sb.setNetwork(Prefix.parse("1.1.1.1/32")).build(), exportPolicy) .isPresent()); }
@Nonnull @VisibleForTesting Optional<OspfExternalRoute> convertToExternalRoute( AbstractRouteDecorator potentialExportRoute, RoutingPolicy exportPolicy) { OspfExternalRoute.Builder outputRouteBuilder = OspfExternalRoute.builder(); boolean accept = exportPolicy.process(potentialExportRoute, outputRouteBuilder, Direction.OUT); if (!accept) { return Optional.empty(); } assert outputRouteBuilder.getOspfMetricType() != null; outputRouteBuilder .setAdmin( _process .getAdminCosts() .get(outputRouteBuilder.getOspfMetricType().toRoutingProtocol())) .setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = _process.getMaxMetricExternalNetworks(); outputRouteBuilder.setCostToAdvertiser(firstNonNull(maxMetricExternalNetworks, 0L)); OspfMetricType metricType = outputRouteBuilder.getOspfMetricType(); if (maxMetricExternalNetworks != null && metricType == OspfMetricType.E1) { outputRouteBuilder.setMetric(maxMetricExternalNetworks); } outputRouteBuilder.setAdvertiser(_c.getHostname()); outputRouteBuilder.setLsaMetric(outputRouteBuilder.getMetric()); outputRouteBuilder.setArea(OspfRoute.NO_AREA); outputRouteBuilder.setNonRouting(true); return Optional.of(outputRouteBuilder.build()); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Optional<OspfExternalRoute> convertToExternalRoute( AbstractRouteDecorator potentialExportRoute, RoutingPolicy exportPolicy) { OspfExternalRoute.Builder outputRouteBuilder = OspfExternalRoute.builder(); boolean accept = exportPolicy.process(potentialExportRoute, outputRouteBuilder, Direction.OUT); if (!accept) { return Optional.empty(); } assert outputRouteBuilder.getOspfMetricType() != null; outputRouteBuilder .setAdmin( _process .getAdminCosts() .get(outputRouteBuilder.getOspfMetricType().toRoutingProtocol())) .setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = _process.getMaxMetricExternalNetworks(); outputRouteBuilder.setCostToAdvertiser(firstNonNull(maxMetricExternalNetworks, 0L)); OspfMetricType metricType = outputRouteBuilder.getOspfMetricType(); if (maxMetricExternalNetworks != null && metricType == OspfMetricType.E1) { outputRouteBuilder.setMetric(maxMetricExternalNetworks); } outputRouteBuilder.setAdvertiser(_c.getHostname()); outputRouteBuilder.setLsaMetric(outputRouteBuilder.getMetric()); outputRouteBuilder.setArea(OspfRoute.NO_AREA); outputRouteBuilder.setNonRouting(true); return Optional.of(outputRouteBuilder.build()); } }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Optional<OspfExternalRoute> convertToExternalRoute( AbstractRouteDecorator potentialExportRoute, RoutingPolicy exportPolicy) { OspfExternalRoute.Builder outputRouteBuilder = OspfExternalRoute.builder(); boolean accept = exportPolicy.process(potentialExportRoute, outputRouteBuilder, Direction.OUT); if (!accept) { return Optional.empty(); } assert outputRouteBuilder.getOspfMetricType() != null; outputRouteBuilder .setAdmin( _process .getAdminCosts() .get(outputRouteBuilder.getOspfMetricType().toRoutingProtocol())) .setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = _process.getMaxMetricExternalNetworks(); outputRouteBuilder.setCostToAdvertiser(firstNonNull(maxMetricExternalNetworks, 0L)); OspfMetricType metricType = outputRouteBuilder.getOspfMetricType(); if (maxMetricExternalNetworks != null && metricType == OspfMetricType.E1) { outputRouteBuilder.setMetric(maxMetricExternalNetworks); } outputRouteBuilder.setAdvertiser(_c.getHostname()); outputRouteBuilder.setLsaMetric(outputRouteBuilder.getMetric()); outputRouteBuilder.setArea(OspfRoute.NO_AREA); outputRouteBuilder.setNonRouting(true); return Optional.of(outputRouteBuilder.build()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Optional<OspfExternalRoute> convertToExternalRoute( AbstractRouteDecorator potentialExportRoute, RoutingPolicy exportPolicy) { OspfExternalRoute.Builder outputRouteBuilder = OspfExternalRoute.builder(); boolean accept = exportPolicy.process(potentialExportRoute, outputRouteBuilder, Direction.OUT); if (!accept) { return Optional.empty(); } assert outputRouteBuilder.getOspfMetricType() != null; outputRouteBuilder .setAdmin( _process .getAdminCosts() .get(outputRouteBuilder.getOspfMetricType().toRoutingProtocol())) .setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = _process.getMaxMetricExternalNetworks(); outputRouteBuilder.setCostToAdvertiser(firstNonNull(maxMetricExternalNetworks, 0L)); OspfMetricType metricType = outputRouteBuilder.getOspfMetricType(); if (maxMetricExternalNetworks != null && metricType == OspfMetricType.E1) { outputRouteBuilder.setMetric(maxMetricExternalNetworks); } outputRouteBuilder.setAdvertiser(_c.getHostname()); outputRouteBuilder.setLsaMetric(outputRouteBuilder.getMetric()); outputRouteBuilder.setArea(OspfRoute.NO_AREA); outputRouteBuilder.setNonRouting(true); return Optional.of(outputRouteBuilder.build()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); @Override void initialize(Node n); @Override void executeIteration(Map<String, Node> allNodes); @Override void updateTopology(OspfTopology topology); @Nonnull @Override RibDelta<OspfRoute> getUpdatesForMainRib(); @Override void redistribute(RibDelta<? extends AnnotatedRoute<AbstractRoute>> mainRibDelta); @Override boolean isDirty(); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @Nonnull @VisibleForTesting Optional<OspfExternalRoute> convertToExternalRoute( AbstractRouteDecorator potentialExportRoute, RoutingPolicy exportPolicy) { OspfExternalRoute.Builder outputRouteBuilder = OspfExternalRoute.builder(); boolean accept = exportPolicy.process(potentialExportRoute, outputRouteBuilder, Direction.OUT); if (!accept) { return Optional.empty(); } assert outputRouteBuilder.getOspfMetricType() != null; outputRouteBuilder .setAdmin( _process .getAdminCosts() .get(outputRouteBuilder.getOspfMetricType().toRoutingProtocol())) .setNetwork(potentialExportRoute.getNetwork()); Long maxMetricExternalNetworks = _process.getMaxMetricExternalNetworks(); outputRouteBuilder.setCostToAdvertiser(firstNonNull(maxMetricExternalNetworks, 0L)); OspfMetricType metricType = outputRouteBuilder.getOspfMetricType(); if (maxMetricExternalNetworks != null && metricType == OspfMetricType.E1) { outputRouteBuilder.setMetric(maxMetricExternalNetworks); } outputRouteBuilder.setAdvertiser(_c.getHostname()); outputRouteBuilder.setLsaMetric(outputRouteBuilder.getMetric()); outputRouteBuilder.setArea(OspfRoute.NO_AREA); outputRouteBuilder.setNonRouting(true); return Optional.of(outputRouteBuilder.build()); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); @Override void initialize(Node n); @Override void executeIteration(Map<String, Node> allNodes); @Override void updateTopology(OspfTopology topology); @Nonnull @Override RibDelta<OspfRoute> getUpdatesForMainRib(); @Override void redistribute(RibDelta<? extends AnnotatedRoute<AbstractRoute>> mainRibDelta); @Override boolean isDirty();  }