Search in sources :

Example 1 with LiteralAsList

use of org.batfish.datamodel.routing_policy.expr.LiteralAsList in project batfish by batfish.

the class PrependAsPathTest method testPrepend.

@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(mkAsPath(3, 4));
    Environment env = newTestEnvironment(builder);
    operation.execute(env);
    assertThat(builder.getAsPath(), equalTo(mkAsPath(1, 2, 3, 4)));
}
Also used : LiteralAsList(org.batfish.datamodel.routing_policy.expr.LiteralAsList) ExplicitAs(org.batfish.datamodel.routing_policy.expr.ExplicitAs) AsExpr(org.batfish.datamodel.routing_policy.expr.AsExpr) Environment(org.batfish.datamodel.routing_policy.Environment) BgpRoute(org.batfish.datamodel.BgpRoute) Test(org.junit.Test)

Example 2 with LiteralAsList

use of org.batfish.datamodel.routing_policy.expr.LiteralAsList in project batfish by batfish.

the class TransferBDD method prependLength.

/*
   * Compute how many times to prepend to a path from the AST
   */
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");
}
Also used : BatfishException(org.batfish.common.BatfishException) LiteralAsList(org.batfish.datamodel.routing_policy.expr.LiteralAsList) IntExpr(org.batfish.datamodel.routing_policy.expr.IntExpr) LiteralInt(org.batfish.datamodel.routing_policy.expr.LiteralInt) MultipliedAs(org.batfish.datamodel.routing_policy.expr.MultipliedAs)

Example 3 with LiteralAsList

use of org.batfish.datamodel.routing_policy.expr.LiteralAsList in project batfish by batfish.

the class PrependAsPathTest method testPrependWithIntermediateAttributes.

@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(mkAsPath(3, 4));
    BgpRoute.Builder intermediateAttributes = new BgpRoute.Builder();
    intermediateAttributes.setAsPath(mkAsPath(5, 6));
    Environment env = newTestEnvironment(outputRoute);
    env.setIntermediateBgpAttributes(intermediateAttributes);
    env.setWriteToIntermediateBgpAttributes(true);
    operation.execute(env);
    assertThat(outputRoute.getAsPath(), equalTo(mkAsPath(1, 2, 3, 4)));
    assertThat(intermediateAttributes.getAsPath(), equalTo(mkAsPath(1, 2, 5, 6)));
}
Also used : LiteralAsList(org.batfish.datamodel.routing_policy.expr.LiteralAsList) ExplicitAs(org.batfish.datamodel.routing_policy.expr.ExplicitAs) AsExpr(org.batfish.datamodel.routing_policy.expr.AsExpr) Environment(org.batfish.datamodel.routing_policy.Environment) BgpRoute(org.batfish.datamodel.BgpRoute) Test(org.junit.Test)

Example 4 with LiteralAsList

use of org.batfish.datamodel.routing_policy.expr.LiteralAsList in project batfish by batfish.

the class TransferSSA method prependLength.

/*
   * Compute how many times to prepend to a path from the AST
   */
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");
}
Also used : BatfishException(org.batfish.common.BatfishException) LiteralAsList(org.batfish.datamodel.routing_policy.expr.LiteralAsList) IntExpr(org.batfish.datamodel.routing_policy.expr.IntExpr) LiteralInt(org.batfish.datamodel.routing_policy.expr.LiteralInt) MultipliedAs(org.batfish.datamodel.routing_policy.expr.MultipliedAs)

Aggregations

LiteralAsList (org.batfish.datamodel.routing_policy.expr.LiteralAsList)4 BatfishException (org.batfish.common.BatfishException)2 BgpRoute (org.batfish.datamodel.BgpRoute)2 Environment (org.batfish.datamodel.routing_policy.Environment)2 AsExpr (org.batfish.datamodel.routing_policy.expr.AsExpr)2 ExplicitAs (org.batfish.datamodel.routing_policy.expr.ExplicitAs)2 IntExpr (org.batfish.datamodel.routing_policy.expr.IntExpr)2 LiteralInt (org.batfish.datamodel.routing_policy.expr.LiteralInt)2 MultipliedAs (org.batfish.datamodel.routing_policy.expr.MultipliedAs)2 Test (org.junit.Test)2