@Test public void testTransformPostExportPrependAs() { AsPath baseAsPath = AsPath.of(ImmutableList.of(AsSet.of(777), AsSet.confed(888))); _baseBgpRouteBuilder.setAsPath(baseAsPath); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.NO_CONFED, 1, DEST_IP, Ip.ZERO); assertThat( _baseBgpRouteBuilder.getAsPath(), equalTo( AsPath.of( ImmutableList.<AsSet>builder() .add(AsSet.of(1)) .addAll(baseAsPath.getAsSets()) .build()))); resetDefaultRouteBuilders(); _baseBgpRouteBuilder.setAsPath(baseAsPath); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.ACROSS_CONFED_BORDER, 2, DEST_IP, Ip.ZERO); assertThat( _baseBgpRouteBuilder.getAsPath(), equalTo( AsPath.of(ImmutableList.<AsSet>builder().add(AsSet.of(2)).add(AsSet.of(777)).build()))); resetDefaultRouteBuilders(); _baseBgpRouteBuilder.setAsPath(baseAsPath); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.WITHIN_CONFED, 4, DEST_IP, Ip.ZERO); assertThat( _baseBgpRouteBuilder.getAsPath(), equalTo( AsPath.of( ImmutableList.<AsSet>builder() .add(AsSet.confed(4)) .addAll(baseAsPath.getAsSets()) .build()))); resetDefaultRouteBuilders(); _baseBgpRouteBuilder.setAsPath(baseAsPath); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.NO_CONFED, 5, DEST_IP, Ip.ZERO); assertThat(_baseBgpRouteBuilder.getAsPath(), equalTo(baseAsPath)); resetDefaultRouteBuilders(); _baseBgpRouteBuilder.setAsPath(baseAsPath); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.WITHIN_CONFED, 6, DEST_IP, Ip.ZERO); assertThat(_baseBgpRouteBuilder.getAsPath(), equalTo(baseAsPath)); }
public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> void transformBgpRoutePostExport( B routeBuilder, boolean isEbgp, ConfedSessionType confedSessionType, long localAs, Ip localIp, Ip originalRouteNhip) { if (isEbgp) { AsSet asSetToPrepend = confedSessionType == ConfedSessionType.WITHIN_CONFED ? AsSet.confed(localAs) : AsSet.of(localAs); AsPath routeAsPath = routeBuilder.getAsPath(); if (confedSessionType.equals(ConfedSessionType.ACROSS_CONFED_BORDER)) { routeAsPath = routeAsPath.removeConfederations(); } routeBuilder.setAsPath( AsPath.of( ImmutableList.<AsSet>builder() .add(asSetToPrepend) .addAll(routeAsPath.getAsSets()) .build())); routeBuilder.setTag(null); } if (routeBuilder.getNextHopIp().equals(UNSET_ROUTE_NEXT_HOP_IP)) { if (isEbgp) { routeBuilder.setNextHopIp(localIp); } else { routeBuilder.setNextHopIp( originalRouteNhip.equals(UNSET_ROUTE_NEXT_HOP_IP) ? localIp : originalRouteNhip); } } if (routeBuilder.getProtocol() == RoutingProtocol.AGGREGATE) { routeBuilder.setProtocol(isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP); } }
BgpProtocolHelper { public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> void transformBgpRoutePostExport( B routeBuilder, boolean isEbgp, ConfedSessionType confedSessionType, long localAs, Ip localIp, Ip originalRouteNhip) { if (isEbgp) { AsSet asSetToPrepend = confedSessionType == ConfedSessionType.WITHIN_CONFED ? AsSet.confed(localAs) : AsSet.of(localAs); AsPath routeAsPath = routeBuilder.getAsPath(); if (confedSessionType.equals(ConfedSessionType.ACROSS_CONFED_BORDER)) { routeAsPath = routeAsPath.removeConfederations(); } routeBuilder.setAsPath( AsPath.of( ImmutableList.<AsSet>builder() .add(asSetToPrepend) .addAll(routeAsPath.getAsSets()) .build())); routeBuilder.setTag(null); } if (routeBuilder.getNextHopIp().equals(UNSET_ROUTE_NEXT_HOP_IP)) { if (isEbgp) { routeBuilder.setNextHopIp(localIp); } else { routeBuilder.setNextHopIp( originalRouteNhip.equals(UNSET_ROUTE_NEXT_HOP_IP) ? localIp : originalRouteNhip); } } if (routeBuilder.getProtocol() == RoutingProtocol.AGGREGATE) { routeBuilder.setProtocol(isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP); } } }
BgpProtocolHelper { public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> void transformBgpRoutePostExport( B routeBuilder, boolean isEbgp, ConfedSessionType confedSessionType, long localAs, Ip localIp, Ip originalRouteNhip) { if (isEbgp) { AsSet asSetToPrepend = confedSessionType == ConfedSessionType.WITHIN_CONFED ? AsSet.confed(localAs) : AsSet.of(localAs); AsPath routeAsPath = routeBuilder.getAsPath(); if (confedSessionType.equals(ConfedSessionType.ACROSS_CONFED_BORDER)) { routeAsPath = routeAsPath.removeConfederations(); } routeBuilder.setAsPath( AsPath.of( ImmutableList.<AsSet>builder() .add(asSetToPrepend) .addAll(routeAsPath.getAsSets()) .build())); routeBuilder.setTag(null); } if (routeBuilder.getNextHopIp().equals(UNSET_ROUTE_NEXT_HOP_IP)) { if (isEbgp) { routeBuilder.setNextHopIp(localIp); } else { routeBuilder.setNextHopIp( originalRouteNhip.equals(UNSET_ROUTE_NEXT_HOP_IP) ? localIp : originalRouteNhip); } } if (routeBuilder.getProtocol() == RoutingProtocol.AGGREGATE) { routeBuilder.setProtocol(isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP); } } private  BgpProtocolHelper(); }
BgpProtocolHelper { public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> void transformBgpRoutePostExport( B routeBuilder, boolean isEbgp, ConfedSessionType confedSessionType, long localAs, Ip localIp, Ip originalRouteNhip) { if (isEbgp) { AsSet asSetToPrepend = confedSessionType == ConfedSessionType.WITHIN_CONFED ? AsSet.confed(localAs) : AsSet.of(localAs); AsPath routeAsPath = routeBuilder.getAsPath(); if (confedSessionType.equals(ConfedSessionType.ACROSS_CONFED_BORDER)) { routeAsPath = routeAsPath.removeConfederations(); } routeBuilder.setAsPath( AsPath.of( ImmutableList.<AsSet>builder() .add(asSetToPrepend) .addAll(routeAsPath.getAsSets()) .build())); routeBuilder.setTag(null); } if (routeBuilder.getNextHopIp().equals(UNSET_ROUTE_NEXT_HOP_IP)) { if (isEbgp) { routeBuilder.setNextHopIp(localIp); } else { routeBuilder.setNextHopIp( originalRouteNhip.equals(UNSET_ROUTE_NEXT_HOP_IP) ? localIp : originalRouteNhip); } } if (routeBuilder.getProtocol() == RoutingProtocol.AGGREGATE) { routeBuilder.setProtocol(isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP); } } 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 { public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> void transformBgpRoutePostExport( B routeBuilder, boolean isEbgp, ConfedSessionType confedSessionType, long localAs, Ip localIp, Ip originalRouteNhip) { if (isEbgp) { AsSet asSetToPrepend = confedSessionType == ConfedSessionType.WITHIN_CONFED ? AsSet.confed(localAs) : AsSet.of(localAs); AsPath routeAsPath = routeBuilder.getAsPath(); if (confedSessionType.equals(ConfedSessionType.ACROSS_CONFED_BORDER)) { routeAsPath = routeAsPath.removeConfederations(); } routeBuilder.setAsPath( AsPath.of( ImmutableList.<AsSet>builder() .add(asSetToPrepend) .addAll(routeAsPath.getAsSets()) .build())); routeBuilder.setTag(null); } if (routeBuilder.getNextHopIp().equals(UNSET_ROUTE_NEXT_HOP_IP)) { if (isEbgp) { routeBuilder.setNextHopIp(localIp); } else { routeBuilder.setNextHopIp( originalRouteNhip.equals(UNSET_ROUTE_NEXT_HOP_IP) ? localIp : originalRouteNhip); } } if (routeBuilder.getProtocol() == RoutingProtocol.AGGREGATE) { routeBuilder.setProtocol(isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP); } } 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);  }