gatewayIF = tryFindIP(map, InetAddress.getByName(subnet.getInfo().getLowAddress()));
} catch (UnknownHostException ex) {
Logger.debug("Unable to find gateway-interface", ex);
}
if (gatewayIF == null) { // create a gateway if none was found
gateway = new Host(Type.Router);
gatewayIF = new PhysicalIF(gateway, gToS, subnet.getInfo().getLowAddress());
map.addVertex(gateway);
gateway.addInterface(gatewayIF);
} else {
gateway = gatewayIF.getDevice();
}
try { // try to find the switch attached to the gateway
aSwitch = map.getOpposite(gateway, gatewayIF.getConnection());
// if the opposite is not a switch, reset
if (aSwitch != null && !aSwitch.getType().toString().toLowerCase().contains("switch")) aSwitch = null;
} catch (Exception e) {
Logger.debug("Unable to find opposite", e);
}
if (aSwitch == null) { // create a switch if necessary
aSwitch = new Host(Type.Switch);
map.addVertex(aSwitch);
aSwitch.addInterface(new TransparentIF(aSwitch, gToS, gatewayIF));
map.addEdge(gToS, gateway, aSwitch);
}
final Device gw = gateway, sw = aSwitch;
final NetworkIF gif = gatewayIF;
for (final InetAddress address : hosts.keySet()) {
Scheduler.execute(new Runnable() {
@Override
public void run() {
try {
if (!address.equals(gif.getAddress())) {
if (tryFindIP(map, address) != null) return;
Logger.debug("Adding Interface "+address);
Connection c = new Connection();
Device d = new Host();
d.setName(address.getHostName());
PhysicalIF pif = new PhysicalIF(d, c, address.getHostAddress());
pif.setPingMethod(hosts.get(address));
pif.setSubnet(subnet.getInfo().getNetmask());
pif.setGateway(subnet.getInfo().getLowAddress());
d.addInterface(pif);
SNMP.inferProperties(d);
sw.addInterface(new TransparentIF(sw, c, pif));
map.addVertex(d);
map.addEdge(c, d, sw);
} else {