@Test public void testTransformGeneratedRouteWithAttrPolicy() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder() .setHostname("c") .setConfigurationFormat(ConfigurationFormat.ARISTA) .build(); StandardCommunity community = StandardCommunity.of(1L); Bgpv4Route result = convertGeneratedRouteToBgp( GeneratedRoute.builder().setNetwork(Prefix.ZERO).setDiscard(true).build(), nf.routingPolicyBuilder() .setOwner(c) .setStatements( ImmutableList.of( new SetCommunity(new LiteralCommunity(community)), Statements.ReturnTrue.toStaticStatement())) .build(), Ip.MAX, Ip.ZERO, true); assertThat(result.getCommunities().getCommunities(), equalTo(ImmutableSet.of(community))); }
@Nonnull public static Bgpv4Route convertGeneratedRouteToBgp( GeneratedRoute generatedRoute, @Nullable RoutingPolicy attributePolicy, Ip routerId, Ip nextHopIp, boolean nonRouting) { Builder builder = convertGeneratedRouteToBgp(generatedRoute, routerId, nextHopIp, nonRouting); if (attributePolicy == null) { return builder.build(); } builder.setNextHopIp(UNSET_ROUTE_NEXT_HOP_IP); boolean accepted = attributePolicy.process(builder.build(), builder, Direction.OUT); assert accepted; return builder.setNextHopIp(nextHopIp).build(); }
BgpProtocolHelper { @Nonnull public static Bgpv4Route convertGeneratedRouteToBgp( GeneratedRoute generatedRoute, @Nullable RoutingPolicy attributePolicy, Ip routerId, Ip nextHopIp, boolean nonRouting) { Builder builder = convertGeneratedRouteToBgp(generatedRoute, routerId, nextHopIp, nonRouting); if (attributePolicy == null) { return builder.build(); } builder.setNextHopIp(UNSET_ROUTE_NEXT_HOP_IP); boolean accepted = attributePolicy.process(builder.build(), builder, Direction.OUT); assert accepted; return builder.setNextHopIp(nextHopIp).build(); } }
BgpProtocolHelper { @Nonnull public static Bgpv4Route convertGeneratedRouteToBgp( GeneratedRoute generatedRoute, @Nullable RoutingPolicy attributePolicy, Ip routerId, Ip nextHopIp, boolean nonRouting) { Builder builder = convertGeneratedRouteToBgp(generatedRoute, routerId, nextHopIp, nonRouting); if (attributePolicy == null) { return builder.build(); } builder.setNextHopIp(UNSET_ROUTE_NEXT_HOP_IP); boolean accepted = attributePolicy.process(builder.build(), builder, Direction.OUT); assert accepted; return builder.setNextHopIp(nextHopIp).build(); } private  BgpProtocolHelper(); }
BgpProtocolHelper { @Nonnull public static Bgpv4Route convertGeneratedRouteToBgp( GeneratedRoute generatedRoute, @Nullable RoutingPolicy attributePolicy, Ip routerId, Ip nextHopIp, boolean nonRouting) { Builder builder = convertGeneratedRouteToBgp(generatedRoute, routerId, nextHopIp, nonRouting); if (attributePolicy == null) { return builder.build(); } builder.setNextHopIp(UNSET_ROUTE_NEXT_HOP_IP); boolean accepted = attributePolicy.process(builder.build(), builder, Direction.OUT); assert accepted; return builder.setNextHopIp(nextHopIp).build(); } private  BgpProtocolHelper(); @Nullable static B transformBgpRoutePreExport(
          BgpPeerConfig localNeighbor,
          BgpPeerConfig remoteNeighbor,
          BgpSessionProperties sessionProperties,
          BgpProcess localBgpProcess,
          BgpProcess remoteBgpProcess,
          BgpRoute<B, R> route,
          Type afType); @Nullable static B transformBgpRouteOnImport(
          BgpRoute<B, R> route,
          long localAs,
          boolean allowLocalAsIn,
          boolean isEbgp,
          BgpProcess toProcess,
          @Nullable String peerInterface); @Nonnull static Bgpv4Route convertGeneratedRouteToBgp(
      GeneratedRoute generatedRoute,
      @Nullable RoutingPolicy attributePolicy,
      Ip routerId,
      Ip nextHopIp,
      boolean nonRouting); @Nonnull static Bgpv4Route.Builder convertNonBgpRouteToBgpRoute(
      AbstractRouteDecorator routeDecorator,
      Ip routerId,
      Ip nextHopIp,
      int adminDistance,
      RoutingProtocol protocol); static void transformBgpRoutePostExport(
          B routeBuilder,
          boolean isEbgp,
          ConfedSessionType confedSessionType,
          long localAs,
          Ip localIp,
          Ip originalRouteNhip); }
BgpProtocolHelper { @Nonnull public static Bgpv4Route convertGeneratedRouteToBgp( GeneratedRoute generatedRoute, @Nullable RoutingPolicy attributePolicy, Ip routerId, Ip nextHopIp, boolean nonRouting) { Builder builder = convertGeneratedRouteToBgp(generatedRoute, routerId, nextHopIp, nonRouting); if (attributePolicy == null) { return builder.build(); } builder.setNextHopIp(UNSET_ROUTE_NEXT_HOP_IP); boolean accepted = attributePolicy.process(builder.build(), builder, Direction.OUT); assert accepted; return builder.setNextHopIp(nextHopIp).build(); } private  BgpProtocolHelper(); @Nullable static B transformBgpRoutePreExport(
          BgpPeerConfig localNeighbor,
          BgpPeerConfig remoteNeighbor,
          BgpSessionProperties sessionProperties,
          BgpProcess localBgpProcess,
          BgpProcess remoteBgpProcess,
          BgpRoute<B, R> route,
          Type afType); @Nullable static B transformBgpRouteOnImport(
          BgpRoute<B, R> route,
          long localAs,
          boolean allowLocalAsIn,
          boolean isEbgp,
          BgpProcess toProcess,
          @Nullable String peerInterface); @Nonnull static Bgpv4Route convertGeneratedRouteToBgp(
      GeneratedRoute generatedRoute,
      @Nullable RoutingPolicy attributePolicy,
      Ip routerId,
      Ip nextHopIp,
      boolean nonRouting); @Nonnull static Bgpv4Route.Builder convertNonBgpRouteToBgpRoute(
      AbstractRouteDecorator routeDecorator,
      Ip routerId,
      Ip nextHopIp,
      int adminDistance,
      RoutingProtocol protocol); static void transformBgpRoutePostExport(
          B routeBuilder,
          boolean isEbgp,
          ConfedSessionType confedSessionType,
          long localAs,
          Ip localIp,
          Ip originalRouteNhip);  }