@Test public void testComputeBgpNeighborImportRoutingPolicy() { BgpNeighbor neighbor = new BgpIpNeighbor("neighbor"); BgpNeighborIpv4UnicastAddressFamily neighborIpv4UnicastFamily = new BgpNeighborIpv4UnicastAddressFamily(); neighborIpv4UnicastFamily.setRouteMapIn("peerMapIn"); neighbor.setIpv4UnicastAddressFamily(neighborIpv4UnicastFamily); BgpVrf bgpVrf = new BgpVrf("bgpVrf"); Configuration config = new Configuration("host", ConfigurationFormat.CUMULUS_NCLU); RoutingPolicy importPolicy = computeBgpNeighborImportRoutingPolicy(config, neighbor, bgpVrf); RoutingPolicy routemapPolicy = RoutingPolicy.builder() .setOwner(config) .setName("peerMapIn") .addStatement( new If( "match community 10000:1 routes", new MatchCommunitySet(new LiteralCommunity(StandardCommunity.parse("10000:1"))), ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))) .build(); Builder builder = Bgpv4Route.builder() .setOriginatorIp(Ip.parse("10.0.0.1")) .setOriginType(OriginType.EGP) .setProtocol(RoutingProtocol.BGP) .setNetwork(Prefix.parse("10.0.0.0/24")); { Bgpv4Route ipv4Route = builder.setCommunities(ImmutableSet.of(StandardCommunity.parse("10000:1"))).build(); Environment envIpv4 = Environment.builder(config) .setRoutingPolicies(ImmutableMap.of("peerMapIn", routemapPolicy)) .setOriginalRoute(ipv4Route) .setDirection(Direction.IN) .build(); Result result = importPolicy.call(envIpv4); assertTrue(result.getBooleanValue()); } { Bgpv4Route ipv4Route = builder.setCommunities(ImmutableSet.of(StandardCommunity.parse("20000:1"))).build(); Environment envIpv4 = Environment.builder(config) .setRoutingPolicies(ImmutableMap.of("peerMapIn", routemapPolicy)) .setOriginalRoute(ipv4Route) .setDirection(Direction.IN) .build(); Result result = importPolicy.call(envIpv4); assertFalse(result.getBooleanValue()); } }
@Nullable @VisibleForTesting static RoutingPolicy computeBgpNeighborImportRoutingPolicy( Configuration c, BgpNeighbor neighbor, BgpVrf bgpVrf) { BooleanExpr peerImportConditions = getBgpNeighborImportPolicyCallExpr(neighbor); if (peerImportConditions == null) { return null; } String vrfName = bgpVrf.getVrfName(); RoutingPolicy.Builder peerImportPolicy = RoutingPolicy.builder() .setOwner(c) .setName(computeBgpPeerImportPolicyName(vrfName, neighbor.getName())); peerImportPolicy.addStatement( new If( "peer-import policy main conditional: exitAccept if true / exitReject if false", peerImportConditions, ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))); return peerImportPolicy.build(); }
CumulusConversions { @Nullable @VisibleForTesting static RoutingPolicy computeBgpNeighborImportRoutingPolicy( Configuration c, BgpNeighbor neighbor, BgpVrf bgpVrf) { BooleanExpr peerImportConditions = getBgpNeighborImportPolicyCallExpr(neighbor); if (peerImportConditions == null) { return null; } String vrfName = bgpVrf.getVrfName(); RoutingPolicy.Builder peerImportPolicy = RoutingPolicy.builder() .setOwner(c) .setName(computeBgpPeerImportPolicyName(vrfName, neighbor.getName())); peerImportPolicy.addStatement( new If( "peer-import policy main conditional: exitAccept if true / exitReject if false", peerImportConditions, ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))); return peerImportPolicy.build(); } }
CumulusConversions { @Nullable @VisibleForTesting static RoutingPolicy computeBgpNeighborImportRoutingPolicy( Configuration c, BgpNeighbor neighbor, BgpVrf bgpVrf) { BooleanExpr peerImportConditions = getBgpNeighborImportPolicyCallExpr(neighbor); if (peerImportConditions == null) { return null; } String vrfName = bgpVrf.getVrfName(); RoutingPolicy.Builder peerImportPolicy = RoutingPolicy.builder() .setOwner(c) .setName(computeBgpPeerImportPolicyName(vrfName, neighbor.getName())); peerImportPolicy.addStatement( new If( "peer-import policy main conditional: exitAccept if true / exitReject if false", peerImportConditions, ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))); return peerImportPolicy.build(); }  }
CumulusConversions { @Nullable @VisibleForTesting static RoutingPolicy computeBgpNeighborImportRoutingPolicy( Configuration c, BgpNeighbor neighbor, BgpVrf bgpVrf) { BooleanExpr peerImportConditions = getBgpNeighborImportPolicyCallExpr(neighbor); if (peerImportConditions == null) { return null; } String vrfName = bgpVrf.getVrfName(); RoutingPolicy.Builder peerImportPolicy = RoutingPolicy.builder() .setOwner(c) .setName(computeBgpPeerImportPolicyName(vrfName, neighbor.getName())); peerImportPolicy.addStatement( new If( "peer-import policy main conditional: exitAccept if true / exitReject if false", peerImportConditions, ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))); return peerImportPolicy.build(); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); }
CumulusConversions { @Nullable @VisibleForTesting static RoutingPolicy computeBgpNeighborImportRoutingPolicy( Configuration c, BgpNeighbor neighbor, BgpVrf bgpVrf) { BooleanExpr peerImportConditions = getBgpNeighborImportPolicyCallExpr(neighbor); if (peerImportConditions == null) { return null; } String vrfName = bgpVrf.getVrfName(); RoutingPolicy.Builder peerImportPolicy = RoutingPolicy.builder() .setOwner(c) .setName(computeBgpPeerImportPolicyName(vrfName, neighbor.getName())); peerImportPolicy.addStatement( new If( "peer-import policy main conditional: exitAccept if true / exitReject if false", peerImportConditions, ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement()))); return peerImportPolicy.build(); }  static @Nonnull String computeBgpCommonExportPolicyName(String vrfName); @VisibleForTesting static @Nonnull String computeBgpPeerExportPolicyName(
      String vrfName, String peerInterface); static @Nonnull String computeBgpPeerImportPolicyName(String vrf, String peer); static String computeBgpGenerationPolicyName(boolean ipv4, String vrfName, String prefix); static String computeMatchSuppressedSummaryOnlyPolicyName(String vrfName); static String computeOspfExportPolicyName(String vrfName); static final int DEFAULT_STATIC_ROUTE_ADMINISTRATIVE_DISTANCE; static final int DEFAULT_STATIC_ROUTE_METRIC; static final Ip CLAG_LINK_LOCAL_IP; static final long DEFAULT_MAX_MED; static final double SPEED_CONVERSION_FACTOR; static final double DEFAULT_LOOPBACK_BANDWIDTH; static final double DEFAULT_PORT_BANDWIDTH; }