@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { statements.add(new PrependAsPath(new LiteralAsList(_asList))); }
private int prependLength(AsPathListExpr expr) { if (expr instanceof MultipliedAs) { MultipliedAs x = (MultipliedAs) expr; IntExpr e = x.getNumber(); LiteralInt i = (LiteralInt) e; return i.getValue(); } if (expr instanceof LiteralAsList) { LiteralAsList x = (LiteralAsList) expr; return x.getList().size(); } throw new BatfishException("Error[prependLength]: unreachable"); }
private int prependLength(AsPathListExpr expr) { if (expr instanceof MultipliedAs) { MultipliedAs x = (MultipliedAs) expr; IntExpr e = x.getNumber(); LiteralInt i = (LiteralInt) e; return i.getValue(); } if (expr instanceof LiteralAsList) { LiteralAsList x = (LiteralAsList) expr; return x.getList().size(); } throw new BatfishException("Error[prependLength]: unreachable"); }
@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))); } }