@Test public void testTransformOnImportWithPeerInterface() { assertThat( "NextHopInterface should be set to peerInterface", transformBgpRouteOnImport( _baseBgpRouteBuilder .setAsPath(AsPath.ofSingletonAsSets(1L)) .setNextHopInterface("foobar") .build(), 2L, false, true, _process, "baz") .getNextHopInterface(), equalTo("baz")); }
@Nullable public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> B transformBgpRouteOnImport( BgpRoute<B, R> route, long localAs, boolean allowLocalAsIn, boolean isEbgp, BgpProcess toProcess, @Nullable String peerInterface) { if (!allowLocalAsIn && route.getAsPath().containsAs(localAs)) { return null; } RoutingProtocol targetProtocol = isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP; B builder = route.toBuilder(); if (peerInterface != null) { builder.setNextHopInterface(peerInterface); } else { builder.setNextHopInterface(Route.UNSET_NEXT_HOP_INTERFACE); } builder.setAdmin(toProcess.getAdminCost(targetProtocol)); builder.setProtocol(targetProtocol); builder.setSrcProtocol(targetProtocol); return builder; }
BgpProtocolHelper { @Nullable public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> B transformBgpRouteOnImport( BgpRoute<B, R> route, long localAs, boolean allowLocalAsIn, boolean isEbgp, BgpProcess toProcess, @Nullable String peerInterface) { if (!allowLocalAsIn && route.getAsPath().containsAs(localAs)) { return null; } RoutingProtocol targetProtocol = isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP; B builder = route.toBuilder(); if (peerInterface != null) { builder.setNextHopInterface(peerInterface); } else { builder.setNextHopInterface(Route.UNSET_NEXT_HOP_INTERFACE); } builder.setAdmin(toProcess.getAdminCost(targetProtocol)); builder.setProtocol(targetProtocol); builder.setSrcProtocol(targetProtocol); return builder; } }
BgpProtocolHelper { @Nullable public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> B transformBgpRouteOnImport( BgpRoute<B, R> route, long localAs, boolean allowLocalAsIn, boolean isEbgp, BgpProcess toProcess, @Nullable String peerInterface) { if (!allowLocalAsIn && route.getAsPath().containsAs(localAs)) { return null; } RoutingProtocol targetProtocol = isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP; B builder = route.toBuilder(); if (peerInterface != null) { builder.setNextHopInterface(peerInterface); } else { builder.setNextHopInterface(Route.UNSET_NEXT_HOP_INTERFACE); } builder.setAdmin(toProcess.getAdminCost(targetProtocol)); builder.setProtocol(targetProtocol); builder.setSrcProtocol(targetProtocol); return builder; } private  BgpProtocolHelper(); }
BgpProtocolHelper { @Nullable public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> B transformBgpRouteOnImport( BgpRoute<B, R> route, long localAs, boolean allowLocalAsIn, boolean isEbgp, BgpProcess toProcess, @Nullable String peerInterface) { if (!allowLocalAsIn && route.getAsPath().containsAs(localAs)) { return null; } RoutingProtocol targetProtocol = isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP; B builder = route.toBuilder(); if (peerInterface != null) { builder.setNextHopInterface(peerInterface); } else { builder.setNextHopInterface(Route.UNSET_NEXT_HOP_INTERFACE); } builder.setAdmin(toProcess.getAdminCost(targetProtocol)); builder.setProtocol(targetProtocol); builder.setSrcProtocol(targetProtocol); return builder; } 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 { @Nullable public static <R extends BgpRoute<B, R>, B extends BgpRoute.Builder<B, R>> B transformBgpRouteOnImport( BgpRoute<B, R> route, long localAs, boolean allowLocalAsIn, boolean isEbgp, BgpProcess toProcess, @Nullable String peerInterface) { if (!allowLocalAsIn && route.getAsPath().containsAs(localAs)) { return null; } RoutingProtocol targetProtocol = isEbgp ? RoutingProtocol.BGP : RoutingProtocol.IBGP; B builder = route.toBuilder(); if (peerInterface != null) { builder.setNextHopInterface(peerInterface); } else { builder.setNextHopInterface(Route.UNSET_NEXT_HOP_INTERFACE); } builder.setAdmin(toProcess.getAdminCost(targetProtocol)); builder.setProtocol(targetProtocol); builder.setSrcProtocol(targetProtocol); return builder; } 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);  }