@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { statements.add(new CallStatement(_applyName)); }
@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { if (parentSources.contains(_calledPolicyName)) { w.redFlag( "Circular reference to routing policy: '" + _calledPolicyName + "' detected at statement: '" + toString() + "'"); return Collections.emptySet(); } RoutingPolicy calledPolicy = routingPolicies.get(_calledPolicyName); if (calledPolicy == null) { return Collections.emptySet(); } return calledPolicy.computeSources(parentSources, routingPolicies, w); }
/** Policy with actual circular reference as statement */ @Test public void testRoutingPolicyCircularReference() { String parentPolicyName = "parent"; _rpb.setName(parentPolicyName) .setStatements(ImmutableList.of(new CallStatement(parentPolicyName))) .build(); _c.computeRoutingPolicySources(_w); /* * A circular reference warning should be emitted containing the name of the circularly * referenced policy. */ assertThat(_w.getRedFlagWarnings(), not(empty())); assertThat( _w.getRedFlagWarnings().iterator().next().getText(), containsString(parentPolicyName)); }
/** * Policy with two different call statements for same policy - should not contain circular * reference */ @Test public void testRoutingPolicyTwoDifferentCallStatementsSamePolicy() { RoutingPolicy calledPolicy = _rpb.build(); Statement callStatement1 = new CallStatement(calledPolicy.getName()); Statement callStatement2 = new CallStatement(calledPolicy.getName()); _rpb.setStatements(ImmutableList.of(callStatement1, callStatement2)).build(); _c.computeRoutingPolicySources(_w); // No circular reference warnings should be emitted assertThat(_w.getRedFlagWarnings(), empty()); } }
} else { onMatchStatements.add(Statements.SetDefaultActionAccept.toStaticStatement()); onMatchStatements.add(new CallStatement(continueTargetPolicy.getName())); ifStatement.getFalseStatements().add(new CallStatement(followingClause.getName())); } else { ifStatement followingClauseNumber = clauseNumber; statements.add(new CallStatement(followingClause.getName())); return output;
/** Policy with two copies of same call statement - should not contain circular reference */ @Test public void testRoutingPolicyTwoCopiesCallStatement() { RoutingPolicy calledPolicy = _rpb.build(); Statement callStatement = new CallStatement(calledPolicy.getName()); _rpb.setStatements(ImmutableList.of(callStatement, callStatement)).build(); _c.computeRoutingPolicySources(_w); // No circular reference warnings should be emitted assertThat(_w.getRedFlagWarnings(), empty()); }
if (defined) { setPolicyStatementReferent(policyName); generationPolicy.getStatements().add(new CallStatement(policyName)); } else { generationPolicy
String parentPolicyName = "parent"; CallStatement callStatement = new CallStatement(parentPolicyName);
.getStatements() .add( new CallStatement( c.getRoutingPolicies() .computeIfAbsent(ospfExportSubPolicyName, n -> new RoutingPolicy(n, c))