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;
}
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);
}
}
}
}
}
}
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);
}
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;
}
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);
}
Aggregations