@Test public void testApplyDistributeList() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder() .setHostname("conf") .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); Interface i1 = nf.interfaceBuilder() .setOwner(c) .setVrf(vrf) .setAddress(ACTIVE_ADDR_1) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setInboundDistributeListPolicy("policy") .build()) .build(); RouteFilterList prefixList = new RouteFilterList( "prefix_list", ImmutableList.of( new RouteFilterLine( LineAction.PERMIT, PrefixRange.fromPrefix(ACTIVE_ADDR_2.getPrefix())), new RouteFilterLine( LineAction.DENY, PrefixRange.fromPrefix(ACTIVE_ADDR_1.getPrefix())))); c.getRouteFilterLists().put(prefixList.getName(), prefixList); nf.routingPolicyBuilder() .setName("policy") .setOwner(c) .setStatements( ImmutableList.of( new If( new MatchPrefixSet( DestinationNetwork.instance(), new NamedPrefixSet("prefix_list")), ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement())))) .build(); OspfIntraAreaRoute.Builder allowedRouteBuilder = OspfIntraAreaRoute.builder().setNetwork(ACTIVE_ADDR_2.getPrefix()).setArea(1L); OspfIntraAreaRoute.Builder deniedRouteBuilder = OspfIntraAreaRoute.builder().setNetwork(ACTIVE_ADDR_1.getPrefix()).setArea(1L); applyDistributeList(c, vrf.getName(), i1.getName(), allowedRouteBuilder); assertFalse(allowedRouteBuilder.getNonRouting()); applyDistributeList(c, vrf.getName(), i1.getName(), deniedRouteBuilder); assertTrue(deniedRouteBuilder.getNonRouting()); }
@VisibleForTesting static void applyDistributeList( Configuration c, String vrfName, String ifaceName, AbstractRouteBuilder<?, ?> routeBuilder) { Interface iface = c.getAllInterfaces().get(ifaceName); assert iface != null; if (iface.getOspfInboundDistributeListPolicy() == null) { return; } RoutingPolicy routingPolicy = c.getRoutingPolicies().get(iface.getOspfInboundDistributeListPolicy()); assert routingPolicy != null; routeBuilder.setNonRouting( !routingPolicy.process(routeBuilder.build(), routeBuilder, Direction.IN)); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @VisibleForTesting static void applyDistributeList( Configuration c, String vrfName, String ifaceName, AbstractRouteBuilder<?, ?> routeBuilder) { Interface iface = c.getAllInterfaces().get(ifaceName); assert iface != null; if (iface.getOspfInboundDistributeListPolicy() == null) { return; } RoutingPolicy routingPolicy = c.getRoutingPolicies().get(iface.getOspfInboundDistributeListPolicy()); assert routingPolicy != null; routeBuilder.setNonRouting( !routingPolicy.process(routeBuilder.build(), routeBuilder, Direction.IN)); } }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @VisibleForTesting static void applyDistributeList( Configuration c, String vrfName, String ifaceName, AbstractRouteBuilder<?, ?> routeBuilder) { Interface iface = c.getAllInterfaces().get(ifaceName); assert iface != null; if (iface.getOspfInboundDistributeListPolicy() == null) { return; } RoutingPolicy routingPolicy = c.getRoutingPolicies().get(iface.getOspfInboundDistributeListPolicy()); assert routingPolicy != null; routeBuilder.setNonRouting( !routingPolicy.process(routeBuilder.build(), routeBuilder, Direction.IN)); } OspfRoutingProcess(
      OspfProcess process, String vrfName, Configuration configuration, OspfTopology topology); }
OspfRoutingProcess implements RoutingProcess<OspfTopology, OspfRoute> { @VisibleForTesting static void applyDistributeList( Configuration c, String vrfName, String ifaceName, AbstractRouteBuilder<?, ?> routeBuilder) { Interface iface = c.getAllInterfaces().get(ifaceName); assert iface != null; if (iface.getOspfInboundDistributeListPolicy() == null) { return; } RoutingPolicy routingPolicy = c.getRoutingPolicies().get(iface.getOspfInboundDistributeListPolicy()); assert routingPolicy != null; routeBuilder.setNonRouting( !routingPolicy.process(routeBuilder.build(), routeBuilder, Direction.IN)); } 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> { @VisibleForTesting static void applyDistributeList( Configuration c, String vrfName, String ifaceName, AbstractRouteBuilder<?, ?> routeBuilder) { Interface iface = c.getAllInterfaces().get(ifaceName); assert iface != null; if (iface.getOspfInboundDistributeListPolicy() == null) { return; } RoutingPolicy routingPolicy = c.getRoutingPolicies().get(iface.getOspfInboundDistributeListPolicy()); assert routingPolicy != null; routeBuilder.setNonRouting( !routingPolicy.process(routeBuilder.build(), routeBuilder, Direction.IN)); } 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();  }