@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { statements.add(new PrependAsPath(new LiteralAsList(_asList))); }
@JsonCreator private static LiteralAsList jsonCreator(@Nullable @JsonProperty(PROP_LIST) List<AsExpr> list) { return new LiteralAsList(firstNonNull(list, ImmutableList.of())); }
@Override public void applyTo( List<Statement> statements, JuniperConfiguration juniperVendorConfiguration, Configuration c, Warnings w) { List<AsExpr> asList = _asPath.stream().map(ExplicitAs::new).collect(ImmutableList.toImmutableList()); statements.add(new PrependAsPath(new LiteralAsList(asList))); } }
@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))); }
@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))); } }