Search in sources :

Example 21 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class RdsInstanceTest method testRdsSubnetEdge.

@Test
public void testRdsSubnetEdge() throws IOException {
    Map<String, Configuration> configurations = loadAwsConfigurations();
    Topology topology = CommonUtil.synthesizeTopology(configurations);
    // check that RDS instance is a neighbor of both  subnets in which its interfaces are
    assertThat(topology.getEdges(), hasItem(new Edge(new NodeInterfacePair("subnet-073b8061", "subnet-073b8061"), new NodeInterfacePair("test-rds", "test-rds-subnet-073b8061"))));
    assertThat(topology.getEdges(), hasItem(new Edge(new NodeInterfacePair("subnet-1f315846", "subnet-1f315846"), new NodeInterfacePair("test-rds", "test-rds-subnet-1f315846"))));
}
Also used : Configuration(org.batfish.datamodel.Configuration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) Test(org.junit.Test)

Example 22 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class SynthesizerInputImplTest method testComputeEnabledEdges.

@Test
public void testComputeEnabledEdges() {
    Configuration srcNode = _cb.build();
    Configuration nextHop = _cb.build();
    Vrf srcVrf = _vb.setOwner(srcNode).build();
    Vrf nextHopVrf = _vb.setOwner(nextHop).build();
    Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).build();
    Interface nextHopInterface = _ib.setOwner(nextHop).setVrf(nextHopVrf).build();
    Interface disabledNextHopInterface = _ib.setActive(false).build();
    Edge expectedEnabledEdge = new Edge(srcInterface, nextHopInterface);
    Edge expectedDisabledEdge = new Edge(srcInterface, disabledNextHopInterface);
    SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).build();
    SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(expectedEnabledEdge, expectedDisabledEdge))).build();
    assertThat(inputWithDataPlane, hasEnabledEdges(hasItem(expectedEnabledEdge)));
    assertThat(inputWithDataPlane, hasEnabledEdges(not(hasItem(expectedDisabledEdge))));
    assertThat(inputWithDataPlane, hasEnabledEdges(not(hasItem(expectedDisabledEdge))));
    assertThat(inputWithoutDataPlane, hasEnabledEdges(nullValue()));
}
Also used : Configuration(org.batfish.datamodel.Configuration) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 23 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class SynthesizerInputImplTest method testComputeArpTrueEdge.

@Test
public void testComputeArpTrueEdge() {
    Configuration srcNode = _cb.build();
    Vrf srcVrf = _vb.setOwner(srcNode).build();
    Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).build();
    String nextHop1 = "nextHop1";
    String nextHopInterface1 = "nextHopInterface1";
    String nextHop2 = "nextHop2";
    String nextHopInterface2 = "nextHopInterface2";
    IpSpace ipSpace1 = Ip.ZERO;
    IpSpace ipSpace2 = Ip.MAX;
    IpSpaceMatchExpr m1 = new IpSpaceMatchExpr(ipSpace1, false, true);
    IpSpaceMatchExpr m2 = new IpSpaceMatchExpr(ipSpace2, false, true);
    Edge edge1 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop1, nextHopInterface1);
    Edge edge2 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop2, nextHopInterface2);
    SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode)).build();
    SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().setArpTrueEdge(ImmutableMap.of(edge1, ipSpace1, edge2, ipSpace2)).build()).setTopology(new Topology(ImmutableSortedSet.of(edge1, edge2))).build();
    assertThat(inputWithoutDataPlane, hasArpTrueEdge(nullValue()));
    assertThat(inputWithDataPlane, hasArpTrueEdge(equalTo(ImmutableMap.of(srcNode.getHostname(), ImmutableMap.of(srcVrf.getName(), ImmutableMap.of(srcInterface.getName(), ImmutableMap.of(nextHop1, ImmutableMap.of(nextHopInterface1, m1), nextHop2, ImmutableMap.of(nextHopInterface2, m2))))))));
}
Also used : Configuration(org.batfish.datamodel.Configuration) IpSpace(org.batfish.datamodel.IpSpace) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) Vrf(org.batfish.datamodel.Vrf) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 24 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class SynthesizerInputImplTest method testComputeSourceNats.

@Test
public void testComputeSourceNats() {
    Configuration srcNode = _cb.build();
    Configuration nextHop = _cb.build();
    Vrf srcVrf = _vb.setOwner(srcNode).build();
    Vrf nextHopVrf = _vb.setOwner(nextHop).build();
    Ip ip11 = new Ip("1.0.0.0");
    Ip ip12 = new Ip("1.0.0.10");
    Ip ip21 = new Ip("2.0.0.0");
    Ip ip22 = new Ip("2.0.0.10");
    IpAccessList sourceNat1Acl = _aclb.setLines(ImmutableList.of()).setOwner(srcNode).build();
    IpAccessList sourceNat2Acl = _aclb.build();
    SourceNat sourceNat1 = _snb.setPoolIpFirst(ip11).setPoolIpLast(ip12).setAcl(sourceNat1Acl).build();
    SourceNat sourceNat2 = _snb.setPoolIpFirst(ip21).setPoolIpLast(ip22).setAcl(sourceNat2Acl).build();
    Interface srcInterfaceZeroSourceNats = _ib.setOwner(srcNode).setVrf(srcVrf).setSourceNats(ImmutableList.of()).build();
    Interface srcInterfaceOneSourceNat = _ib.setSourceNats(ImmutableList.of(sourceNat1)).build();
    Interface srcInterfaceTwoSourceNats = _ib.setSourceNats(ImmutableList.of(sourceNat1, sourceNat2)).build();
    Interface nextHopInterface = _ib.setOwner(nextHop).setVrf(nextHopVrf).setSourceNats(ImmutableList.of()).build();
    Edge forwardEdge1 = new Edge(srcInterfaceZeroSourceNats, nextHopInterface);
    Edge forwardEdge2 = new Edge(srcInterfaceOneSourceNat, nextHopInterface);
    Edge forwardEdge3 = new Edge(srcInterfaceTwoSourceNats, nextHopInterface);
    Edge backEdge1 = new Edge(nextHopInterface, srcInterfaceZeroSourceNats);
    Edge backEdge2 = new Edge(nextHopInterface, srcInterfaceOneSourceNat);
    Edge backEdge3 = new Edge(nextHopInterface, srcInterfaceTwoSourceNats);
    SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode, nextHop.getName(), nextHop)).build();
    SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().build()).setTopology(new Topology(ImmutableSortedSet.of(forwardEdge1, forwardEdge2, forwardEdge3, backEdge1, backEdge2, backEdge3))).build();
    assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceZeroSourceNats.getName()), equalTo(ImmutableList.of())))));
    assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceOneSourceNat.getName()), equalTo(ImmutableList.of(immutableEntry(new AclPermit(srcNode.getName(), sourceNat1Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip11.asLong(), ip12.asLong()))))))))));
    assertThat(inputWithDataPlane, hasSourceNats(hasEntry(equalTo(srcNode.getName()), hasEntry(equalTo(srcInterfaceTwoSourceNats.getName()), equalTo(ImmutableList.of(immutableEntry(new AclPermit(srcNode.getName(), sourceNat1Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip11.asLong(), ip12.asLong())))), immutableEntry(new AclPermit(srcNode.getName(), sourceNat2Acl.getName()), new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(ip21.asLong(), ip22.asLong()))))))))));
    assertThat(inputWithoutDataPlane, hasSourceNats(nullValue()));
}
Also used : SourceNat(org.batfish.datamodel.SourceNat) Configuration(org.batfish.datamodel.Configuration) Ip(org.batfish.datamodel.Ip) AclPermit(org.batfish.z3.state.AclPermit) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Vrf(org.batfish.datamodel.Vrf) IpAccessList(org.batfish.datamodel.IpAccessList) Topology(org.batfish.datamodel.Topology) Edge(org.batfish.datamodel.Edge) SynthesizerInputMatchers.hasArpTrueEdge(org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge) Interface(org.batfish.datamodel.Interface) Test(org.junit.Test)

Example 25 with Edge

use of org.batfish.datamodel.Edge in project batfish by batfish.

the class VirtualRouter method propagateOspfExternalRoutes.

public boolean propagateOspfExternalRoutes(Map<String, Node> nodes, Topology topology) {
    boolean changed = false;
    String node = _c.getHostname();
    OspfProcess proc = _vrf.getOspfProcess();
    if (proc != null) {
        int admin = RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat());
        SortedSet<Edge> edges = topology.getNodeEdges().get(node);
        if (edges == null) {
            // there are no edges, so OSPF won't produce anything
            return false;
        }
        for (Edge edge : edges) {
            if (!edge.getNode1().equals(node)) {
                continue;
            }
            String connectingInterfaceName = edge.getInt1();
            Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
            if (connectingInterface == null) {
                // wrong vrf, so skip
                continue;
            }
            String neighborName = edge.getNode2();
            Node neighbor = nodes.get(neighborName);
            String neighborInterfaceName = edge.getInt2();
            OspfArea area = connectingInterface.getOspfArea();
            Configuration nc = neighbor._c;
            Interface neighborInterface = nc.getInterfaces().get(neighborInterfaceName);
            String neighborVrfName = neighborInterface.getVrfName();
            VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
            OspfArea neighborArea = neighborInterface.getOspfArea();
            if (connectingInterface.getOspfEnabled() && !connectingInterface.getOspfPassive() && neighborInterface.getOspfEnabled() && !neighborInterface.getOspfPassive() && area != null && neighborArea != null && area.getName().equals(neighborArea.getName())) {
                /*
           * We have an ospf neighbor relationship on this edge. So we
           * should add all ospf external type 1(2) routes from this
           * neighbor into our ospf external type 1(2) staging rib. For
           * type 1, the cost of the route increases each time. For type 2,
           * the cost remains constant, but we must keep track of cost to
           * advertiser as a tie-breaker.
           */
                long connectingInterfaceCost = connectingInterface.getOspfCost();
                long incrementalCost = proc.getMaxMetricTransitLinks() != null ? proc.getMaxMetricTransitLinks() : connectingInterfaceCost;
                for (OspfExternalType1Route neighborRoute : neighborVirtualRouter._prevOspfExternalType1Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseMetric = neighborRoute.getMetric();
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    newArea = connectionArea;
                    if (oldArea != OspfRoute.NO_AREA) {
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea) {
                            if (connectionArea != 0L && oldArea != 0L) {
                                continue;
                            }
                            if (maxMetricSummaryNetworks != null) {
                                baseMetric = maxMetricSummaryNetworks + neighborRoute.getLsaMetric();
                                baseCostToAdvertiser = maxMetricSummaryNetworks;
                            }
                        }
                    }
                    long newMetric = baseMetric + incrementalCost;
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType1Route newRoute = new OspfExternalType1Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, newMetric, neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType1StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
                for (OspfExternalType2Route neighborRoute : neighborVirtualRouter._prevOspfExternalType2Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    if (oldArea == OspfRoute.NO_AREA) {
                        newArea = connectionArea;
                    } else {
                        newArea = oldArea;
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea && maxMetricSummaryNetworks != null) {
                            baseCostToAdvertiser = maxMetricSummaryNetworks;
                        }
                    }
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType2Route newRoute = new OspfExternalType2Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, neighborRoute.getMetric(), neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType2StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
            }
        }
    }
    return changed;
}
Also used : OspfExternalType2Route(org.batfish.datamodel.OspfExternalType2Route) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) OspfProcess(org.batfish.datamodel.OspfProcess) OspfExternalType1Route(org.batfish.datamodel.OspfExternalType1Route) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Aggregations

Edge (org.batfish.datamodel.Edge)46 Configuration (org.batfish.datamodel.Configuration)23 Interface (org.batfish.datamodel.Interface)19 Topology (org.batfish.datamodel.Topology)17 Test (org.junit.Test)17 Ip (org.batfish.datamodel.Ip)12 NodeInterfacePair (org.batfish.datamodel.collections.NodeInterfacePair)12 Vrf (org.batfish.datamodel.Vrf)10 BatfishException (org.batfish.common.BatfishException)9 FlowTrace (org.batfish.datamodel.FlowTrace)8 ArrayList (java.util.ArrayList)7 Set (java.util.Set)7 TreeSet (java.util.TreeSet)7 IpAccessList (org.batfish.datamodel.IpAccessList)7 HostConfiguration (org.batfish.representation.host.HostConfiguration)7 VendorConfiguration (org.batfish.vendor.VendorConfiguration)7 SynthesizerInputMatchers.hasArpTrueEdge (org.batfish.z3.matchers.SynthesizerInputMatchers.hasArpTrueEdge)7 HashMap (java.util.HashMap)6 FlowTraceHop (org.batfish.datamodel.FlowTraceHop)6 AclPermit (org.batfish.z3.state.AclPermit)6