private void identifyDeviceTypes(Collection<Configuration> configurations) { for (Configuration c : configurations) { if (c.getDeviceType() != null) { continue; } // Set device type to host iff the configuration format is HOST if (c.getConfigurationFormat() == ConfigurationFormat.HOST) { c.setDeviceType(DeviceType.HOST); } else if (c.getVrfs().values().stream() .anyMatch( vrf -> vrf.getBgpProcess() != null || !vrf.getEigrpProcesses().isEmpty() || vrf.getOspfProcess() != null || vrf.getRipProcess() != null)) { // If any vrf on device has BGP, EIGRP, OSPF, or RIP, set device type to router c.setDeviceType(DeviceType.ROUTER); } else { // If device was not a host or router, call it a switch c.setDeviceType(DeviceType.SWITCH); } } }
@Test public void emptyConfigurationIsSwitch() { Configuration c = _cb.build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.SWITCH)); }
@Test public void hostConfigIsHost() { Configuration c = _cb.setConfigurationFormat(ConfigurationFormat.HOST).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.HOST)); }
@Test public void configWithEmptyVrfIsSwitch() { Configuration c = _cb.build(); _vb.setOwner(c).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.SWITCH)); }
private void postProcessConfiguration(Configuration c) { // Set device type to host iff the configuration format is HOST if (c.getConfigurationFormat() == ConfigurationFormat.HOST) { c.setDeviceType(DeviceType.HOST); } for (Vrf vrf : c.getVrfs().values()) { // If vrf has BGP, OSPF, or RIP process and device isn't a host, set device type to router if (c.getDeviceType() == null && (vrf.getBgpProcess() != null || vrf.getOspfProcess() != null || vrf.getRipProcess() != null)) { c.setDeviceType(DeviceType.ROUTER); } // Compute OSPF interface costs where they are missing OspfProcess proc = vrf.getOspfProcess(); if (proc != null) { proc.initInterfaceCosts(c); } } // If device was not a host or router, call it a switch if (c.getDeviceType() == null) { c.setDeviceType(DeviceType.SWITCH); } } }
@Test public void configWithRipIsRouter() { Configuration c = _cb.build(); Vrf vrf = _vb.setOwner(c).build(); _nf.ospfProcessBuilder().setVrf(vrf).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.ROUTER)); }
@Test public void configWithBgpIsRouter() { Configuration c = _cb.build(); Vrf vrf = _vb.setOwner(c).build(); _nf.bgpProcessBuilder().setVrf(vrf).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.ROUTER)); }
@Test public void configWithOspfIsRouter() { Configuration c = _cb.build(); Vrf vrf = _vb.setOwner(c).build(); _nf.ospfProcessBuilder().setVrf(vrf).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.ROUTER)); }
throw new BatfishException("Node '" + nodeName + "' not found in configurations"); Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode); Node pojoNode = new Node(configuration.getHostname(), configuration.getDeviceType()); pojoTopology.getNodes().add(pojoNode);
@Test public void hostWithBgpIsHost() { Configuration c = _cb.setConfigurationFormat(ConfigurationFormat.HOST).build(); Vrf vrf = _vb.setOwner(c).build(); _nf.bgpProcessBuilder().setVrf(vrf).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.HOST)); }
@Test public void configWithFirstVrfEmptyIsRouter() { Configuration c = _cb.build(); _vb.setOwner(c).build(); Vrf vrf = _vb.setOwner(c).build(); _nf.bgpProcessBuilder().setVrf(vrf).build(); postProcessConfiguration(c); assertThat(c.getDeviceType(), is(DeviceType.ROUTER)); }