@Test public void testFromEnvironment() { Map<String, CommunityMatchExpr> communityMatchExprs = ImmutableMap.of("cme", AllStandardCommunities.instance()); Map<String, CommunitySetExpr> communitySetExprs = ImmutableMap.of("cse", new LiteralCommunitySet(CommunitySet.of(StandardCommunity.of(2L)))); Map<String, CommunitySetMatchExpr> communitySetMatchExprs = ImmutableMap.of("csme", new HasCommunity(AllStandardCommunities.instance())); Map<String, CommunitySet> communitySets = ImmutableMap.of("cs", CommunitySet.of(StandardCommunity.of(1L))); Configuration c = new Configuration("a", ConfigurationFormat.CISCO_IOS); c.setCommunityMatchExprs(communityMatchExprs); c.setCommunitySetExprs(communitySetExprs); c.setCommunitySetMatchExprs(communitySetMatchExprs); c.setCommunitySets(communitySets); CommunitySet outputCommunitySet = CommunitySet.of(StandardCommunity.of(1L)); CommunitySet intermediateCommunitySet = CommunitySet.of(StandardCommunity.of(2L)); CommunitySet inputRouteCommunitySet = CommunitySet.of(StandardCommunity.of(3L)); CommunityContext useOutput = fromEnvironment( Environment.builder(c) .setUseOutputAttributes(true) .setOutputRoute( Bgpv4Route.builder().setCommunities(outputCommunitySet.getCommunities())) .build()); assertThat(useOutput.getCommunityMatchExprs(), equalTo(communityMatchExprs)); assertThat(useOutput.getCommunitySetExprs(), equalTo(communitySetExprs)); assertThat(useOutput.getCommunitySetMatchExprs(), equalTo(communitySetMatchExprs)); assertThat(useOutput.getCommunitySets(), equalTo(communitySets)); assertThat(useOutput.getInputCommunitySet(), equalTo(outputCommunitySet)); CommunityContext useIntermediate = fromEnvironment( Environment.builder(c) .setReadFromIntermediateBgpAttributes(true) .setIntermediateBgpAttributes( Bgpv4Route.builder().setCommunities(intermediateCommunitySet.getCommunities())) .build()); assertThat(useIntermediate.getInputCommunitySet(), equalTo(intermediateCommunitySet)); CommunityContext useInputRoute = fromEnvironment( Environment.builder(c) .setOriginalRoute( Bgpv4Route.builder() .setCommunities(inputRouteCommunitySet.getCommunities()) .setNetwork(Prefix.ZERO) .setOriginatorIp(Ip.ZERO) .setOriginType(OriginType.INCOMPLETE) .setProtocol(RoutingProtocol.BGP) .build()) .build()); assertThat(useInputRoute.getInputCommunitySet(), equalTo(inputRouteCommunitySet)); }
public static @Nonnull CommunityContext fromEnvironment(Environment environment) { CommunitySet inputCommunitySet; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); inputCommunitySet = CommunitySet.of(bgpRouteBuilder.getCommunities()); } else if (environment.getReadFromIntermediateBgpAttributes()) { inputCommunitySet = CommunitySet.of(environment.getIntermediateBgpAttributes().getCommunities()); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); inputCommunitySet = bgpRoute.getCommunities(); } else { inputCommunitySet = CommunitySet.empty(); } return CommunityContext.builder() .setCommunityMatchExprs(environment.getCommunityMatchExprs()) .setCommunitySetExprs(environment.getCommunitySetExprs()) .setCommunitySetMatchExprs(environment.getCommunitySetMatchExprs()) .setCommunitySets(environment.getCommunitySets()) .setInputCommunitySet(inputCommunitySet) .build(); }
CommunityContext { public static @Nonnull CommunityContext fromEnvironment(Environment environment) { CommunitySet inputCommunitySet; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); inputCommunitySet = CommunitySet.of(bgpRouteBuilder.getCommunities()); } else if (environment.getReadFromIntermediateBgpAttributes()) { inputCommunitySet = CommunitySet.of(environment.getIntermediateBgpAttributes().getCommunities()); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); inputCommunitySet = bgpRoute.getCommunities(); } else { inputCommunitySet = CommunitySet.empty(); } return CommunityContext.builder() .setCommunityMatchExprs(environment.getCommunityMatchExprs()) .setCommunitySetExprs(environment.getCommunitySetExprs()) .setCommunitySetMatchExprs(environment.getCommunitySetMatchExprs()) .setCommunitySets(environment.getCommunitySets()) .setInputCommunitySet(inputCommunitySet) .build(); } }
CommunityContext { public static @Nonnull CommunityContext fromEnvironment(Environment environment) { CommunitySet inputCommunitySet; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); inputCommunitySet = CommunitySet.of(bgpRouteBuilder.getCommunities()); } else if (environment.getReadFromIntermediateBgpAttributes()) { inputCommunitySet = CommunitySet.of(environment.getIntermediateBgpAttributes().getCommunities()); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); inputCommunitySet = bgpRoute.getCommunities(); } else { inputCommunitySet = CommunitySet.empty(); } return CommunityContext.builder() .setCommunityMatchExprs(environment.getCommunityMatchExprs()) .setCommunitySetExprs(environment.getCommunitySetExprs()) .setCommunitySetMatchExprs(environment.getCommunitySetMatchExprs()) .setCommunitySets(environment.getCommunitySets()) .setInputCommunitySet(inputCommunitySet) .build(); } private  CommunityContext(
      Map<String, CommunityMatchExpr> communityMatchExprs,
      Map<String, CommunitySetExpr> communitySetExprs,
      Map<String, CommunitySetMatchExpr> communitySetMatchExprs,
      Map<String, CommunitySet> communitySets,
      CommunitySet inputCommunitySet); }
CommunityContext { public static @Nonnull CommunityContext fromEnvironment(Environment environment) { CommunitySet inputCommunitySet; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); inputCommunitySet = CommunitySet.of(bgpRouteBuilder.getCommunities()); } else if (environment.getReadFromIntermediateBgpAttributes()) { inputCommunitySet = CommunitySet.of(environment.getIntermediateBgpAttributes().getCommunities()); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); inputCommunitySet = bgpRoute.getCommunities(); } else { inputCommunitySet = CommunitySet.empty(); } return CommunityContext.builder() .setCommunityMatchExprs(environment.getCommunityMatchExprs()) .setCommunitySetExprs(environment.getCommunitySetExprs()) .setCommunitySetMatchExprs(environment.getCommunitySetMatchExprs()) .setCommunitySets(environment.getCommunitySets()) .setInputCommunitySet(inputCommunitySet) .build(); } private  CommunityContext(
      Map<String, CommunityMatchExpr> communityMatchExprs,
      Map<String, CommunitySetExpr> communitySetExprs,
      Map<String, CommunitySetMatchExpr> communitySetMatchExprs,
      Map<String, CommunitySet> communitySets,
      CommunitySet inputCommunitySet); static @Nonnull Builder builder(); @Nonnull Map<String, CommunityMatchExpr> getCommunityMatchExprs(); @Nonnull Map<String, CommunitySetExpr> getCommunitySetExprs(); @Nonnull Map<String, CommunitySetMatchExpr> getCommunitySetMatchExprs(); @Nonnull Map<String, CommunitySet> getCommunitySets(); @Nonnull CommunitySet getInputCommunitySet(); static @Nonnull CommunityContext fromEnvironment(Environment environment); @Nonnull CommunityMatchExprEvaluator getCommunityMatchExprEvaluator(); @Nonnull CommunitySetMatchExprEvaluator getCommunitySetMatchExprEvaluator(); }
CommunityContext { public static @Nonnull CommunityContext fromEnvironment(Environment environment) { CommunitySet inputCommunitySet; if (environment.getUseOutputAttributes() && environment.getOutputRoute() instanceof BgpRoute.Builder<?, ?>) { BgpRoute.Builder<?, ?> bgpRouteBuilder = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); inputCommunitySet = CommunitySet.of(bgpRouteBuilder.getCommunities()); } else if (environment.getReadFromIntermediateBgpAttributes()) { inputCommunitySet = CommunitySet.of(environment.getIntermediateBgpAttributes().getCommunities()); } else if (environment.getOriginalRoute() instanceof BgpRoute) { BgpRoute<?, ?> bgpRoute = (BgpRoute<?, ?>) environment.getOriginalRoute(); inputCommunitySet = bgpRoute.getCommunities(); } else { inputCommunitySet = CommunitySet.empty(); } return CommunityContext.builder() .setCommunityMatchExprs(environment.getCommunityMatchExprs()) .setCommunitySetExprs(environment.getCommunitySetExprs()) .setCommunitySetMatchExprs(environment.getCommunitySetMatchExprs()) .setCommunitySets(environment.getCommunitySets()) .setInputCommunitySet(inputCommunitySet) .build(); } private  CommunityContext(
      Map<String, CommunityMatchExpr> communityMatchExprs,
      Map<String, CommunitySetExpr> communitySetExprs,
      Map<String, CommunitySetMatchExpr> communitySetMatchExprs,
      Map<String, CommunitySet> communitySets,
      CommunitySet inputCommunitySet); static @Nonnull Builder builder(); @Nonnull Map<String, CommunityMatchExpr> getCommunityMatchExprs(); @Nonnull Map<String, CommunitySetExpr> getCommunitySetExprs(); @Nonnull Map<String, CommunitySetMatchExpr> getCommunitySetMatchExprs(); @Nonnull Map<String, CommunitySet> getCommunitySets(); @Nonnull CommunitySet getInputCommunitySet(); static @Nonnull CommunityContext fromEnvironment(Environment environment); @Nonnull CommunityMatchExprEvaluator getCommunityMatchExprEvaluator(); @Nonnull CommunitySetMatchExprEvaluator getCommunitySetMatchExprEvaluator();  }