/** 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 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()); }
/** Policy with actual circular reference as expr */ @Test public void testRoutingPolicyCircularReferenceExpr() { String parentPolicyName = "parent"; CallExpr callExpr = new CallExpr(parentPolicyName); If ifStatement = new If(); ifStatement.setGuard(callExpr); _rpb.setName(parentPolicyName).setStatements(ImmutableList.of(ifStatement)).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)); }
public void computeRoutingPolicySources(Warnings w) { for (String rpName : _routingPolicies.keySet()) { computeRoutingPolicySources(rpName, w); } for (Vrf vrf : _vrfs.values()) { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess != null) { for (BgpPeerConfig neighbor : Iterables.concat( bgpProcess.getActiveNeighbors().values(), bgpProcess.getPassiveNeighbors().values())) { neighbor.setExportPolicySources(getRoutingPolicySources(neighbor.getExportPolicy())); neighbor.setImportPolicySources(getRoutingPolicySources(neighbor.getImportPolicy())); } } OspfProcess ospfProcess = vrf.getOspfProcess(); if (ospfProcess != null) { ospfProcess.setExportPolicySources(getRoutingPolicySources(ospfProcess.getExportPolicy())); } for (GeneratedRoute gr : vrf.getGeneratedRoutes()) { gr.setAttributePolicySources(getRoutingPolicySources(gr.getAttributePolicy())); gr.setGenerationPolicySources(getRoutingPolicySources(gr.getGenerationPolicy())); } } }
/** * 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()); } }