@Test public void testTransformPostExportNextHopIp() { Ip nextHopIp = Ip.parse("1.2.3.4"); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.NO_CONFED, 1, nextHopIp, DEST_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.ACROSS_CONFED_BORDER, 1, nextHopIp, DEST_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.WITHIN_CONFED, 1, nextHopIp, DEST_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.NO_CONFED, 1, nextHopIp, DEST_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(DEST_IP)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.WITHIN_CONFED, 1, nextHopIp, DEST_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(DEST_IP)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, true, ConfedSessionType.WITHIN_CONFED, 1, nextHopIp, UNSET_ROUTE_NEXT_HOP_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.NO_CONFED, 1, nextHopIp, UNSET_ROUTE_NEXT_HOP_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); _baseBgpRouteBuilder.setNextHopIp(null); transformBgpRoutePostExport( _baseBgpRouteBuilder, false, ConfedSessionType.WITHIN_CONFED, 1, nextHopIp, UNSET_ROUTE_NEXT_HOP_IP); assertThat(_baseBgpRouteBuilder.getNextHopIp(), equalTo(nextHopIp)); }
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);  }