@JsonCreator private static ExplicitAs jsonCreator(@Nullable @JsonProperty(PROP_AS) Long as) { checkArgument(as != null, "%s must be provided", PROP_AS); return new ExplicitAs(as); }
@Test public void testPrepend() { List<AsExpr> prepend = Lists.newArrayList(new ExplicitAs(1), new ExplicitAs(2)); PrependAsPath operation = new PrependAsPath(new LiteralAsList(prepend)); BgpRoute.Builder builder = new BgpRoute.Builder(); builder.setAsPath(ofSingletonAsSets(3L, 4L)); Environment env = newTestEnvironment(builder); operation.execute(env); assertThat(builder.getAsPath(), equalTo(ofSingletonAsSets(1L, 2L, 3L, 4L))); }
private AsExpr toAsExpr(As_exprContext ctx) { if (ctx.DEC() != null) { int as = toInteger(ctx.DEC()); return new ExplicitAs(as); } else if (ctx.AUTO() != null) { return new AutoAs(); } else if (ctx.RP_VARIABLE() != null) { return new VarAs(ctx.RP_VARIABLE().getText()); } else { throw convError(AsExpr.class, ctx); } }
@Test public void testPrependWithIntermediateAttributes() { List<AsExpr> prepend = Lists.newArrayList(new ExplicitAs(1), new ExplicitAs(2)); PrependAsPath operation = new PrependAsPath(new LiteralAsList(prepend)); BgpRoute.Builder outputRoute = new BgpRoute.Builder(); outputRoute.setAsPath(ofSingletonAsSets(3L, 4L)); BgpRoute.Builder intermediateAttributes = new BgpRoute.Builder(); intermediateAttributes.setAsPath(ofSingletonAsSets(5L, 6L)); Environment env = newTestEnvironment(outputRoute); env.setIntermediateBgpAttributes(intermediateAttributes); env.setWriteToIntermediateBgpAttributes(true); operation.execute(env); assertThat(outputRoute.getAsPath(), equalTo(ofSingletonAsSets(1L, 2L, 3L, 4L))); assertThat(intermediateAttributes.getAsPath(), equalTo(ofSingletonAsSets(1L, 2L, 5L, 6L))); } }