@Test public void testCreate() { NetworkFactory nf = new NetworkFactory(); Configuration c1 = nf.configurationBuilder().setHostname("c1").build(); Configuration c2 = nf.configurationBuilder().setHostname("c2").build(); Configuration c3 = nf.configurationBuilder().setHostname("c3").build(); org.batfish.datamodel.Interface c12 = nf.interfaceBuilder().setOwner(c1).setName("to-c2").setType(InterfaceType.UNKNOWN).build(); org.batfish.datamodel.Interface c21 = nf.interfaceBuilder().setOwner(c2).setName("to-c1").setType(InterfaceType.UNKNOWN).build(); org.batfish.datamodel.Interface c23 = nf.interfaceBuilder().setOwner(c2).setName("to-c3").setType(InterfaceType.UNKNOWN).build(); org.batfish.datamodel.Interface c32 = nf.interfaceBuilder().setOwner(c3).setName("to-c2").setType(InterfaceType.UNKNOWN).build(); org.batfish.datamodel.Topology rawL3Topology = new org.batfish.datamodel.Topology( ImmutableSortedSet.of( new Edge(c12, c21), new Edge(c21, c12), new Edge(c23, c32), new Edge(c32, c23))); Topology pojoTopology = Topology.create( "test", ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2, c3.getHostname(), c3), rawL3Topology); Node c1Node = new Node(c1.getHostname()); Node c2Node = new Node(c2.getHostname()); Node c3Node = new Node(c3.getHostname()); assertThat(pojoTopology.getNodes(), equalTo(ImmutableSet.of(c1Node, c2Node, c3Node))); Interface c12Interface = new Interface(c1Node.getId(), c12.getName()); Interface c21Interface = new Interface(c2Node.getId(), c21.getName()); Interface c23Interface = new Interface(c2Node.getId(), c23.getName()); Interface c32Interface = new Interface(c3Node.getId(), c32.getName()); assertThat( pojoTopology.getInterfaces(), equalTo(ImmutableSet.of(c12Interface, c21Interface, c23Interface, c32Interface))); assertThat( pojoTopology.getLinks(), equalTo( ImmutableSet.of( new Link(c12Interface.getId(), c21Interface.getId()), new Link(c21Interface.getId(), c12Interface.getId()), new Link(c23Interface.getId(), c32Interface.getId()), new Link(c32Interface.getId(), c23Interface.getId())))); }
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.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Map<String, org.batfish.datamodel.Interface> nodeInterfaces = configuration.getAllInterfaces(); for (Edge edge : topology.getNodeEdges().get(nodeName)) { if (!edge.getNode1().equals(nodeName)) { continue; } String interface1 = edge.getInt1(); String interface2 = edge.getInt2(); InterfaceType iface1type = nodeInterfaces.containsKey(interface1) ? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; Configuration configuration2 = configurations.get(edge.getNode2()); assert configuration2 != null; InterfaceType iface2type = configuration2.getAllInterfaces().containsKey(interface2) ? configuration2.getAllInterfaces().get(interface2).getInterfaceType() : InterfaceType.UNKNOWN; Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); LinkType linkType = Link.interfaceTypesToLinkType(iface1type, iface2type); Link pojoLink = new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); pojoTopology.getInterfaces().add(pojoInterface); pojoTopology.getLinks().add(pojoLink); } } for (Configuration configuration : configurations.values()) { Node pojoNode = new Node( configuration.getHostname(), configuration.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) { putInAwsAggregate(pojoTopology, configuration, pojoNode); } } return pojoTopology; }
Topology extends BfObject { 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.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Map<String, org.batfish.datamodel.Interface> nodeInterfaces = configuration.getAllInterfaces(); for (Edge edge : topology.getNodeEdges().get(nodeName)) { if (!edge.getNode1().equals(nodeName)) { continue; } String interface1 = edge.getInt1(); String interface2 = edge.getInt2(); InterfaceType iface1type = nodeInterfaces.containsKey(interface1) ? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; Configuration configuration2 = configurations.get(edge.getNode2()); assert configuration2 != null; InterfaceType iface2type = configuration2.getAllInterfaces().containsKey(interface2) ? configuration2.getAllInterfaces().get(interface2).getInterfaceType() : InterfaceType.UNKNOWN; Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); LinkType linkType = Link.interfaceTypesToLinkType(iface1type, iface2type); Link pojoLink = new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); pojoTopology.getInterfaces().add(pojoInterface); pojoTopology.getLinks().add(pojoLink); } } for (Configuration configuration : configurations.values()) { Node pojoNode = new Node( configuration.getHostname(), configuration.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) { putInAwsAggregate(pojoTopology, configuration, pojoNode); } } return pojoTopology; } }
Topology extends BfObject { 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.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Map<String, org.batfish.datamodel.Interface> nodeInterfaces = configuration.getAllInterfaces(); for (Edge edge : topology.getNodeEdges().get(nodeName)) { if (!edge.getNode1().equals(nodeName)) { continue; } String interface1 = edge.getInt1(); String interface2 = edge.getInt2(); InterfaceType iface1type = nodeInterfaces.containsKey(interface1) ? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; Configuration configuration2 = configurations.get(edge.getNode2()); assert configuration2 != null; InterfaceType iface2type = configuration2.getAllInterfaces().containsKey(interface2) ? configuration2.getAllInterfaces().get(interface2).getInterfaceType() : InterfaceType.UNKNOWN; Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); LinkType linkType = Link.interfaceTypesToLinkType(iface1type, iface2type); Link pojoLink = new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); pojoTopology.getInterfaces().add(pojoInterface); pojoTopology.getLinks().add(pojoLink); } } for (Configuration configuration : configurations.values()) { Node pojoNode = new Node( configuration.getHostname(), configuration.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) { putInAwsAggregate(pojoTopology, configuration, pojoNode); } } return pojoTopology; } Topology(String testrigName); @JsonCreator  Topology(
      @JsonProperty(PROP_ID) String topologyId,
      @JsonProperty(PROP_TESTRIG_NAME) String testrigName); }
Topology extends BfObject { 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.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Map<String, org.batfish.datamodel.Interface> nodeInterfaces = configuration.getAllInterfaces(); for (Edge edge : topology.getNodeEdges().get(nodeName)) { if (!edge.getNode1().equals(nodeName)) { continue; } String interface1 = edge.getInt1(); String interface2 = edge.getInt2(); InterfaceType iface1type = nodeInterfaces.containsKey(interface1) ? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; Configuration configuration2 = configurations.get(edge.getNode2()); assert configuration2 != null; InterfaceType iface2type = configuration2.getAllInterfaces().containsKey(interface2) ? configuration2.getAllInterfaces().get(interface2).getInterfaceType() : InterfaceType.UNKNOWN; Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); LinkType linkType = Link.interfaceTypesToLinkType(iface1type, iface2type); Link pojoLink = new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); pojoTopology.getInterfaces().add(pojoInterface); pojoTopology.getLinks().add(pojoLink); } } for (Configuration configuration : configurations.values()) { Node pojoNode = new Node( configuration.getHostname(), configuration.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) { putInAwsAggregate(pojoTopology, configuration, pojoNode); } } return pojoTopology; } Topology(String testrigName); @JsonCreator  Topology(
      @JsonProperty(PROP_ID) String topologyId,
      @JsonProperty(PROP_TESTRIG_NAME) String testrigName); static Topology create(
      String testrigName,
      Map<String, Configuration> configurations,
      org.batfish.datamodel.Topology topology); Set<Aggregate> getAggregates(); static String getId(String testrigName); Set<Interface> getInterfaces(); Set<Link> getLinks(); Set<Node> getNodes(); Aggregate getOrCreateAggregate(String name, AggregateType aggType); @JsonProperty(PROP_TESTRIG_NAME) String getTestrigName(); void setAggregates(Set<Aggregate> aggregates); void setInterfaces(Set<Interface> interfaces); void setLinks(Set<Link> links); void setNodes(Set<Node> nodes); }
Topology extends BfObject { 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.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Map<String, org.batfish.datamodel.Interface> nodeInterfaces = configuration.getAllInterfaces(); for (Edge edge : topology.getNodeEdges().get(nodeName)) { if (!edge.getNode1().equals(nodeName)) { continue; } String interface1 = edge.getInt1(); String interface2 = edge.getInt2(); InterfaceType iface1type = nodeInterfaces.containsKey(interface1) ? nodeInterfaces.get(interface1).getInterfaceType() : InterfaceType.UNKNOWN; Configuration configuration2 = configurations.get(edge.getNode2()); assert configuration2 != null; InterfaceType iface2type = configuration2.getAllInterfaces().containsKey(interface2) ? configuration2.getAllInterfaces().get(interface2).getInterfaceType() : InterfaceType.UNKNOWN; Interface pojoInterface = new Interface(pojoNode.getId(), interface1, iface1type); LinkType linkType = Link.interfaceTypesToLinkType(iface1type, iface2type); Link pojoLink = new Link( pojoInterface.getId(), Interface.getId(Node.makeId(edge.getNode2()), interface2), linkType); pojoTopology.getInterfaces().add(pojoInterface); pojoTopology.getLinks().add(pojoLink); } } for (Configuration configuration : configurations.values()) { Node pojoNode = new Node( configuration.getHostname(), configuration.getDeviceModel(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); if (configuration.getConfigurationFormat() == ConfigurationFormat.AWS) { putInAwsAggregate(pojoTopology, configuration, pojoNode); } } return pojoTopology; } Topology(String testrigName); @JsonCreator  Topology(
      @JsonProperty(PROP_ID) String topologyId,
      @JsonProperty(PROP_TESTRIG_NAME) String testrigName); static Topology create(
      String testrigName,
      Map<String, Configuration> configurations,
      org.batfish.datamodel.Topology topology); Set<Aggregate> getAggregates(); static String getId(String testrigName); Set<Interface> getInterfaces(); Set<Link> getLinks(); Set<Node> getNodes(); Aggregate getOrCreateAggregate(String name, AggregateType aggType); @JsonProperty(PROP_TESTRIG_NAME) String getTestrigName(); void setAggregates(Set<Aggregate> aggregates); void setInterfaces(Set<Interface> interfaces); void setLinks(Set<Link> links); void setNodes(Set<Node> nodes);  }