@Test public void testExecute() { Configuration c = new Configuration("h", ConfigurationFormat.CISCO_IOS); CommunitySet cs = CommunitySet.of(StandardCommunity.of(1L)); SetCommunities set = new SetCommunities(new LiteralCommunitySet(cs)); Environment envWriteToOutput = Environment.builder(c).setOutputRoute(routeBuilder()).build(); set.execute(envWriteToOutput); Bgpv4Route routeWriteToOutput = (Bgpv4Route) envWriteToOutput.getOutputRoute().build(); assertThat(routeWriteToOutput.getCommunities().getCommunities(), equalTo(cs.getCommunities())); Environment envWriteToIntermediate = Environment.builder(c) .setIntermediateBgpAttributes(routeBuilder()) .setOutputRoute(routeBuilder()) .setWriteToIntermediateBgpAttributes(true) .build(); set.execute(envWriteToIntermediate); Bgpv4Route routeWriteToIntermediate = (Bgpv4Route) envWriteToIntermediate.getIntermediateBgpAttributes().build(); assertThat( routeWriteToIntermediate.getCommunities().getCommunities(), equalTo(cs.getCommunities())); }
@Override public @Nonnull Result execute(Environment environment) { CommunityContext ctx = CommunityContext.fromEnvironment(environment); CommunitySet communitySet = _communitySetExpr.accept(CommunitySetExprEvaluator.instance(), ctx); BgpRoute.Builder<?, ?> bgpRoute = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); Set<Community> communities = communitySet.getCommunities(); bgpRoute.setCommunities(communities); if (environment.getWriteToIntermediateBgpAttributes()) { environment.getIntermediateBgpAttributes().setCommunities(communities); } return new Result(); }
SetCommunities extends Statement { @Override public @Nonnull Result execute(Environment environment) { CommunityContext ctx = CommunityContext.fromEnvironment(environment); CommunitySet communitySet = _communitySetExpr.accept(CommunitySetExprEvaluator.instance(), ctx); BgpRoute.Builder<?, ?> bgpRoute = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); Set<Community> communities = communitySet.getCommunities(); bgpRoute.setCommunities(communities); if (environment.getWriteToIntermediateBgpAttributes()) { environment.getIntermediateBgpAttributes().setCommunities(communities); } return new Result(); } }
SetCommunities extends Statement { @Override public @Nonnull Result execute(Environment environment) { CommunityContext ctx = CommunityContext.fromEnvironment(environment); CommunitySet communitySet = _communitySetExpr.accept(CommunitySetExprEvaluator.instance(), ctx); BgpRoute.Builder<?, ?> bgpRoute = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); Set<Community> communities = communitySet.getCommunities(); bgpRoute.setCommunities(communities); if (environment.getWriteToIntermediateBgpAttributes()) { environment.getIntermediateBgpAttributes().setCommunities(communities); } return new Result(); } SetCommunities(CommunitySetExpr communitySetExpr); }
SetCommunities extends Statement { @Override public @Nonnull Result execute(Environment environment) { CommunityContext ctx = CommunityContext.fromEnvironment(environment); CommunitySet communitySet = _communitySetExpr.accept(CommunitySetExprEvaluator.instance(), ctx); BgpRoute.Builder<?, ?> bgpRoute = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); Set<Community> communities = communitySet.getCommunities(); bgpRoute.setCommunities(communities); if (environment.getWriteToIntermediateBgpAttributes()) { environment.getIntermediateBgpAttributes().setCommunities(communities); } return new Result(); } SetCommunities(CommunitySetExpr communitySetExpr); @Override T accept(StatementVisitor<T, U> visitor, U arg); @Override @Nonnull Result execute(Environment environment); @JsonProperty(PROP_COMMUNITY_SET_EXPR) @Nonnull CommunitySetExpr getCommunitySetExpr(); @Override boolean equals(Object obj); @Override int hashCode(); }
SetCommunities extends Statement { @Override public @Nonnull Result execute(Environment environment) { CommunityContext ctx = CommunityContext.fromEnvironment(environment); CommunitySet communitySet = _communitySetExpr.accept(CommunitySetExprEvaluator.instance(), ctx); BgpRoute.Builder<?, ?> bgpRoute = (BgpRoute.Builder<?, ?>) environment.getOutputRoute(); Set<Community> communities = communitySet.getCommunities(); bgpRoute.setCommunities(communities); if (environment.getWriteToIntermediateBgpAttributes()) { environment.getIntermediateBgpAttributes().setCommunities(communities); } return new Result(); } SetCommunities(CommunitySetExpr communitySetExpr); @Override T accept(StatementVisitor<T, U> visitor, U arg); @Override @Nonnull Result execute(Environment environment); @JsonProperty(PROP_COMMUNITY_SET_EXPR) @Nonnull CommunitySetExpr getCommunitySetExpr(); @Override boolean equals(Object obj); @Override int hashCode();  }