Search in sources :

Example 31 with Edge

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

the class Batfish method getSymmetricEdgePairs.

private Set<Edge> getSymmetricEdgePairs(SortedSet<Edge> edges) {
    Set<Edge> consumedEdges = new LinkedHashSet<>();
    for (Edge edge : edges) {
        if (consumedEdges.contains(edge)) {
            continue;
        }
        Edge reverseEdge = new Edge(edge.getInterface2(), edge.getInterface1());
        consumedEdges.add(edge);
        consumedEdges.add(reverseEdge);
    }
    return consumedEdges;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Edge(org.batfish.datamodel.Edge)

Example 32 with Edge

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

the class Batfish method initRemoteRipNeighbors.

@Override
public void initRemoteRipNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
    for (Entry<String, Configuration> e : configurations.entrySet()) {
        String hostname = e.getKey();
        Configuration c = e.getValue();
        for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
            Vrf vrf = e2.getValue();
            RipProcess proc = vrf.getRipProcess();
            if (proc != null) {
                proc.setRipNeighbors(new TreeMap<>());
                String vrfName = e2.getKey();
                for (String ifaceName : proc.getInterfaces()) {
                    Interface iface = vrf.getInterfaces().get("ifaceName");
                    SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
                    boolean hasNeighbor = false;
                    Ip localIp = iface.getAddress().getIp();
                    if (ifaceEdges != null) {
                        for (Edge edge : ifaceEdges) {
                            if (edge.getNode1().equals(hostname)) {
                                String remoteHostname = edge.getNode2();
                                String remoteIfaceName = edge.getInt2();
                                Configuration remoteNode = configurations.get(remoteHostname);
                                Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
                                Vrf remoteVrf = remoteIface.getVrf();
                                String remoteVrfName = remoteVrf.getName();
                                RipProcess remoteProc = remoteVrf.getRipProcess();
                                if (remoteProc != null) {
                                    if (remoteProc.getRipNeighbors() == null) {
                                        remoteProc.setRipNeighbors(new TreeMap<>());
                                    }
                                    if (remoteProc.getInterfaces().contains(remoteIfaceName)) {
                                        Ip remoteIp = remoteIface.getAddress().getIp();
                                        Pair<Ip, Ip> localKey = new Pair<>(localIp, remoteIp);
                                        RipNeighbor neighbor = proc.getRipNeighbors().get(localKey);
                                        if (neighbor == null) {
                                            hasNeighbor = true;
                                            // initialize local neighbor
                                            neighbor = new RipNeighbor(localKey);
                                            neighbor.setVrf(vrfName);
                                            neighbor.setOwner(c);
                                            neighbor.setInterface(iface);
                                            proc.getRipNeighbors().put(localKey, neighbor);
                                            // initialize remote neighbor
                                            Pair<Ip, Ip> remoteKey = new Pair<>(remoteIp, localIp);
                                            RipNeighbor remoteNeighbor = new RipNeighbor(remoteKey);
                                            remoteNeighbor.setVrf(remoteVrfName);
                                            remoteNeighbor.setOwner(remoteNode);
                                            remoteNeighbor.setInterface(remoteIface);
                                            remoteProc.getRipNeighbors().put(remoteKey, remoteNeighbor);
                                            // link neighbors
                                            neighbor.setRemoteRipNeighbor(remoteNeighbor);
                                            remoteNeighbor.setRemoteRipNeighbor(neighbor);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!hasNeighbor) {
                        Pair<Ip, Ip> key = new Pair<>(localIp, Ip.ZERO);
                        RipNeighbor neighbor = new RipNeighbor(key);
                        neighbor.setVrf(vrfName);
                        neighbor.setOwner(c);
                        neighbor.setInterface(iface);
                        proc.getRipNeighbors().put(key, neighbor);
                    }
                }
            }
        }
    }
}
Also used : RipNeighbor(org.batfish.datamodel.RipNeighbor) HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) Ip(org.batfish.datamodel.Ip) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Vrf(org.batfish.datamodel.Vrf) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) RipProcess(org.batfish.datamodel.RipProcess) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface) Pair(org.batfish.common.Pair) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair)

Example 33 with Edge

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

the class GNS3TopologyExtractor method exitEdge_line.

@Override
public void exitEdge_line(Edge_lineContext ctx) {
    String int1 = convertInterfaceName(ctx.int1.getText());
    String node2 = ctx.host2.getText();
    String int2 = convertInterfaceName(ctx.int2.getText());
    Edge edge = new Edge(_currentRouter, int1, node2, int2);
    _edges.add(edge);
}
Also used : Edge(org.batfish.datamodel.Edge)

Example 34 with Edge

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

the class Topology method create.

public static Topology create(String testrigName, Map<String, Configuration> configurations, org.batfish.datamodel.Topology topology) {
    Topology pojoTopology = new Topology(testrigName);
    for (String nodeName : topology.getNodeEdges().keySet()) {
        Configuration configuration = configurations.get(nodeName);
        if (configuration == null) {
            throw new BatfishException("Node '" + nodeName + "' not found in configurations");
        }
        Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType());
        pojoTopology.getNodes().add(pojoNode);
        // add interfaces and links
        for (Edge edge : topology.getNodeEdges().get(nodeName)) {
            org.batfish.datamodel.pojo.Interface pojoInterface = new org.batfish.datamodel.pojo.Interface(pojoNode.getId(), edge.getInterface1().getInterface());
            Link pojoLink = new Link(pojoInterface.getId(), org.batfish.datamodel.pojo.Interface.getId(Node.getId(edge.getNode2()), edge.getInt2()));
            pojoTopology.getInterfaces().add(pojoInterface);
            pojoTopology.getLinks().add(pojoLink);
        }
        // and then put that container in their container
        if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) {
            if (configuration.getVendorFamily().getAws().getSubnetId() != null) {
                String subnetId = configuration.getVendorFamily().getAws().getSubnetId();
                Aggregate subnetAggregate = pojoTopology.getOrCreateAggregate(subnetId, AggregateType.SUBNET);
                subnetAggregate.getContents().add(pojoNode.getId());
                String vpcId = configuration.getVendorFamily().getAws().getVpcId();
                Aggregate vpcAggregate = pojoTopology.getOrCreateAggregate(vpcId, AggregateType.VNET);
                vpcAggregate.getContents().add(subnetAggregate.getId());
            } else if (configuration.getVendorFamily().getAws().getVpcId() != null) {
                String vpcId = configuration.getVendorFamily().getAws().getVpcId();
                Aggregate vpcAggregate = pojoTopology.getOrCreateAggregate(vpcId, AggregateType.VNET);
                vpcAggregate.getContents().add(pojoNode.getId());
                String region = configuration.getVendorFamily().getAws().getRegion();
                Aggregate regionAggregate = pojoTopology.getOrCreateAggregate(region, AggregateType.REGION);
                regionAggregate.getContents().add(vpcAggregate.getId());
            } else if (configuration.getVendorFamily().getAws().getRegion() != null) {
                String region = configuration.getVendorFamily().getAws().getRegion();
                Aggregate regionAggregate = pojoTopology.getOrCreateAggregate(region, AggregateType.REGION);
                regionAggregate.getContents().add(pojoNode.getId());
                Aggregate awsAggregate = pojoTopology.getOrCreateAggregate("aws", AggregateType.CLOUD);
                awsAggregate.getContents().add(regionAggregate.getId());
            } else {
                Aggregate awsAggregate = pojoTopology.getOrCreateAggregate("aws", AggregateType.CLOUD);
                awsAggregate.getContents().add(pojoNode.getId());
            }
        }
    }
    // add nodes that were not in Topology (because they have no Edges)
    for (Configuration configuration : configurations.values()) {
        Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType());
        pojoTopology.getNodes().add(pojoNode);
    }
    return pojoTopology;
}
Also used : BatfishException(org.batfish.common.BatfishException) Configuration(org.batfish.datamodel.Configuration) Edge(org.batfish.datamodel.Edge)

Example 35 with Edge

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

the class CounterExample method buildFlowTraceHop.

/*
   * Build an individual flow hop along a path
   */
private FlowTraceHop buildFlowTraceHop(GraphEdge ge, String route) {
    String node1 = ge.getRouter();
    String int1 = ge.getStart().getName();
    String node2 = ge.getPeer() == null ? "(none)" : ge.getPeer();
    String int2 = ge.getEnd() == null ? "null_interface" : ge.getEnd().getName();
    Edge edge = new Edge(node1, int1, node2, int2);
    SortedSet<String> routes = new TreeSet<>();
    routes.add(route);
    return new FlowTraceHop(edge, routes, null);
}
Also used : FlowTraceHop(org.batfish.datamodel.FlowTraceHop) TreeSet(java.util.TreeSet) Edge(org.batfish.datamodel.Edge) GraphEdge(org.batfish.symbolic.GraphEdge)

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