/** * Smart constructor for {@link NotMatchExpr} that does constant-time simplifications (i.e. when * expr is {@link #TRUE} or {@link #FALSE}). */ public static AclLineMatchExpr not(AclLineMatchExpr expr) { if (expr == TRUE) { return FALSE; } if (expr == FALSE) { return TRUE; } if (expr instanceof NotMatchExpr) { return ((NotMatchExpr) expr).getOperand(); } return new NotMatchExpr(expr); }
@Override public AclLineMatchExpr visitOriginatingFromDevice(OriginatingFromDevice originatingFromDevice) { return new NotMatchExpr(originatingFromDevice); }
@Override public AclLineMatchExpr visitNotMatchExpr(NotMatchExpr notMatchExpr) { // eliminate double-negation return notMatchExpr.getOperand(); }
@Override public AclLineMatchExpr visitPermittedByAcl(PermittedByAcl permittedByAcl) { return new NotMatchExpr(permittedByAcl); }
@Override public Void visitNotMatchExpr(NotMatchExpr notMatchExpr) { // normalization retains negation on literals but not in general, so we recurse either way this.visit(notMatchExpr.getOperand()); return null; }
@Override public AclLineMatchExpr visitNotMatchExpr(NotMatchExpr notMatchExpr) throws CircularReferenceException, UndefinedReferenceException { return new NotMatchExpr(visit(notMatchExpr.getOperand())); }
@Override public AclLineMatchExpr visitMatchSrcInterface(MatchSrcInterface matchSrcInterface) { return new NotMatchExpr(matchSrcInterface); }
@Override public List<T> visitNotMatchExpr(NotMatchExpr notMatchExpr) { List<T> matchingExprs = new ArrayList<>(); if (_type.isAssignableFrom(NotMatchExpr.class)) { matchingExprs.add(_type.cast(notMatchExpr)); } matchingExprs.addAll(visit(notMatchExpr.getOperand())); return matchingExprs; }
@Override public AclLineMatchExpr visitNotMatchExpr(NotMatchExpr notMatchExpr) { return new NotMatchExpr(notMatchExpr.getOperand().accept(this)); }
@Override public AclLineMatchExpr visitMatchHeaderSpace(MatchHeaderSpace matchHeaderSpace) { return new NotMatchExpr(matchHeaderSpace); }
@Override public Void visitNotMatchExpr(NotMatchExpr notMatchExpr) { visit(notMatchExpr.getOperand()); return null; }
@Override public final AclLineMatchExpr visitNotMatchExpr(NotMatchExpr notMatchExpr) { AclLineMatchExpr subExpr = notMatchExpr.getOperand().accept(this); if (subExpr == TrueExpr.INSTANCE) { return FalseExpr.INSTANCE; } else if (subExpr == FalseExpr.INSTANCE) { return TrueExpr.INSTANCE; } else { return new NotMatchExpr(subExpr); } }
notHeaderSpace -> { MatchHeaderSpace matchHeaderSpace = new MatchHeaderSpace(notHeaderSpace); NotMatchExpr notMatchExpr = new NotMatchExpr(matchHeaderSpace); conjunctsBuilder.add(notMatchExpr); conjunctsProvenance.put(
@Override public Boolean visitNotMatchExpr(NotMatchExpr notMatchExpr) { return notMatchExpr.getOperand().accept(this); }
@Override public AclLineMatchExpr visitNotMatchExpr(NotMatchExpr notMatchExpr) { return new NotMatchExpr(notMatchExpr.getOperand().accept(this)); }
@Test public void testSingleExpr() { // Test that the NotMatchExpr returns the opposite of the underlying ACL line NotMatchExpr exprNotTrue = new NotMatchExpr(TrueExpr.INSTANCE); NotMatchExpr exprNotFalse = new NotMatchExpr(FalseExpr.INSTANCE); // Confirm boolean expr NOT true = false assertThat(exprNotTrue, not(matches(createFlow(), ""))); // Confirm boolean expr NOT false = true assertThat(exprNotFalse, matches(createFlow(), "")); } }
@Override public Boolean visitNotMatchExpr(NotMatchExpr notMatchExpr) { return !notMatchExpr.getOperand().accept(this); }
new IpAccessListLine( LineAction.DENY, new NotMatchExpr(new PermittedByAcl(e.getKey(), true)), e.getKey() + "DENY")); new IpAccessListLine( LineAction.DENY, new NotMatchExpr(new PermittedByAcl(ACL_NAME_GLOBAL_POLICY, true)), "GLOBAL_POLICY_REJECT"));
@Override public Void visitNotMatchExpr(NotMatchExpr notMatchExpr) { AclLineMatchExpr operand = notMatchExpr.getOperand(); if (operand instanceof MatchHeaderSpace) { forbidHeaderSpace((MatchHeaderSpace) operand); return null; } throw new IllegalArgumentException("Can only explain AclLineMatchExpr literals."); }
ImmutableList.of( IpAccessListLine.accepting() .setMatchCondition(new NotMatchExpr(new PermittedByAcl("acl0"))) .build())) .setName("acl3")