@Test public void testGetInterface() { Configuration c = new Configuration("foo", ConfigurationFormat.CISCO_IOS); Interface i = Interface.builder().setBandwidth(1e9).setName("eth0").build(); c.getAllInterfaces().put(i.getName(), i); NetworkConfigurations nc = NetworkConfigurations.of(ImmutableMap.of("foo", c)); assertThat(nc.getInterface("bar", "missingIface"), equalTo(Optional.empty())); assertThat(nc.getInterface("foo", "missingIface"), equalTo(Optional.empty())); assertThat(nc.getInterface("foo", "eth0").orElse(null), equalTo(i)); } }
@Test public void testBlacklisting() { Interface i = Interface.builder().setName("iface").build(); assertThat("Interface is not blacklisted", !i.getBlacklisted()); assertThat("Interface is not disabled", i.getActive()); i.blacklist(); assertThat("Interface is blacklisted", i.getBlacklisted()); assertThat("Interface is disabled", !i.getActive()); }
@Test public void matchesType() { InterfacesSpecifier specifier = new InterfacesSpecifier("type:physical"); Configuration c = new Configuration("c", ConfigurationFormat.CISCO_IOS); Interface ifaceLoopback = Interface.builder().setName("Loopback0").setOwner(c).build(); Interface ifacePhysical = Interface.builder().setName("GigabitEthernet0").setOwner(c).build(); assertThat(specifier.matches(ifaceLoopback), equalTo(false)); assertThat(specifier.matches(ifacePhysical), equalTo(true)); }
@Test public void matchesVrf() { InterfacesSpecifier specifier = new InterfacesSpecifier("vrf:vrf1"); Interface vrf1Iface = Interface.builder().setName("iface").setVrf(new Vrf("vrf1")).build(); Interface vrf2Iface = Interface.builder().setName("iface").setVrf(new Vrf("vrf2")).build(); assertThat(specifier.matches(vrf1Iface), equalTo(true)); assertThat(specifier.matches(vrf2Iface), equalTo(false)); } }
@Test public void resolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder().setName("iface11").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface12").setOwner(node1).build(); Interface iface2 = Interface.builder().setName("iface2").setOwner(node2).build(); node1.setInterfaces(ImmutableSortedMap.of("iface11", iface11, "iface12", iface12)); node2.setInterfaces(ImmutableSortedMap.of("iface2", iface2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of("node1", node1, "node2", node2)) .build(); assertThat( new ShorthandInterfaceSpecifier(new InterfacesSpecifier("iface11")) .resolve(ImmutableSet.of("node1"), ctxt), equalTo(ImmutableSet.of(iface11))); } }
@Test public void testComputeInterfaceCost() { Interface.Builder ib = Interface.builder() .setName("eth0") .setBandwidth(1e3) .setOwner(new Configuration("r1", ConfigurationFormat.CISCO_IOS)); Interface i = ib.build(); // Round up to 1 int cost = OspfProcess.computeInterfaceCost(1.0, i); assertThat(cost, equalTo(1)); cost = OspfProcess.computeInterfaceCost(1e6, i); assertThat(cost, equalTo(1000)); _thrown.expectMessage("Interface eth0 on r1 is missing bandwidth"); _thrown.expect(IllegalStateException.class); OspfProcess.computeInterfaceCost(1e6, ib.setBandwidth(null).build()); }
@Test public void getPropertiesExcludeShutInterfaces() { Configuration conf = new Configuration("node", ConfigurationFormat.CISCO_IOS); Interface active = Interface.builder().setName("active").setOwner(conf).setActive(true).build(); Interface shut = Interface.builder().setName("shut").setOwner(conf).setActive(false).build(); conf.getAllInterfaces().putAll(ImmutableMap.of("active", active, "shut", shut)); String property = InterfacePropertySpecifier.DESCRIPTION; InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property); Multiset<Row> propertyRows = InterfacePropertiesAnswerer.getProperties( propertySpecifier, ImmutableMap.of("node", conf), ImmutableSet.of("node"), InterfacesSpecifier.ALL, true, new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier), (String) null) .toColumnMap()); // we should have exactly one row; iface1 should have been filtered out assertThat(propertyRows, hasSize(1)); assertThat( propertyRows.iterator().next(), hasColumn( InterfacePropertiesAnswerer.COL_INTERFACE, equalTo(new NodeInterfacePair("node", "active")), Schema.INTERFACE)); }
Zone zone1node2 = new Zone("zone1"); Interface iface11 = Interface.builder().setName("iface11").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface12").setOwner(node1).build(); @SuppressWarnings("unused") Interface iface13 = Interface.builder().setName("iface13").setOwner(node1).build(); Interface iface2 = Interface.builder().setName("iface2").setOwner(node2).build();
public void setup() { Vrf vrf = new Vrf(Configuration.DEFAULT_VRF_NAME); Interface.Builder ib = Interface.builder().setVrf(vrf); InterfaceAddress uniqueAddr = new InterfaceAddress(_uniqueIp, MAX_PREFIX_LENGTH - 1); InterfaceAddress secondaryUniqueAddr =
Vrf vrf3 = new Vrf("vrf2"); Interface iface11 = Interface.builder().setName("iface11").setOwner(node1).setVrf(vrf1).build(); Interface iface12 = Interface.builder().setName("iface12").setOwner(node1).setVrf(vrf2).build(); Interface iface2 = Interface.builder().setName("iface2").setOwner(node2).setVrf(vrf3).build();
public Interface toInterface(Configuration configuration, Warnings warnings) { String name = _canonicalName != null ? _canonicalName : _name; Interface.Builder iface = Interface.builder() .setName(name) .setOwner(configuration) .setAddresses(_address, _otherAddresses) .setBandwidth(_bandwidth) .setDeclaredNames(ImmutableSortedSet.of(_name)) .setProxyArp(false) .setVrf(configuration.getDefaultVrf()); if (_shared) { Ip publicIp = _address.getIp(); iface.setOutgoingTransformation(always().apply(assignSourceIp(publicIp, publicIp)).build()); } return iface.build(); } }
@Before public void setup() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); _c1 = cb.setHostname("c1").build(); _c2 = cb.setHostname("c2").build(); _aclb = nf.aclBuilder().setOwner(_c1); _c1.setIpSpaces(ImmutableSortedMap.of("ipSpace", Ip.parse("1.2.3.4").toIpSpace())); _c1.setInterfaces( ImmutableSortedMap.of( "iface", Interface.builder().setName("iface").build(), "iface2", Interface.builder().setName("iface2").build())); _c2.setInterfaces(ImmutableSortedMap.of("iface", Interface.builder().setName("iface").build())); }
@Before public void setup() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); _c1 = cb.setHostname("c1").build(); _c2 = cb.setHostname("c2").build(); _aclb = nf.aclBuilder().setOwner(_c1); _aclb2 = nf.aclBuilder().setOwner(_c2); _c1.setIpSpaces(ImmutableSortedMap.of("ipSpace", Ip.parse("1.2.3.4").toIpSpace())); _c1.setInterfaces( ImmutableSortedMap.of( "iface", Interface.builder().setName("iface").build(), "iface2", Interface.builder().setName("iface2").build())); _c2.setInterfaces(ImmutableSortedMap.of("iface", Interface.builder().setName("iface").build())); }
Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder().setName("iface1").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface2").setOwner(node1).build(); Interface iface21 = Interface.builder().setName("iface1").setOwner(node2).build();
Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder() .setName("iface11") .setOwner(node1) .build(); Interface iface12 = Interface.builder() .setName("iface12") .setActive(true) Interface.builder() .setName("iface2") .setActive(true)
@Before public void setup() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); _host1 = cb.setHostname("host1").build(); _host1.setInterfaces( ImmutableSortedMap.of( "int1", Interface.builder() .setName("int1") .setAddress(new InterfaceAddress(Ip.parse("1.1.1.1"), 24)) .build())); _host2 = cb.setHostname("host2").build(); _host2.setInterfaces( ImmutableSortedMap.of( "int2", Interface.builder() .setName("int2") .setAddress(new InterfaceAddress(Ip.parse("2.2.2.2"), 24)) .build())); _configurations = ImmutableSortedMap.of("host1", _host1, "host2", _host2); _includeNodes = ImmutableSortedSet.of("host1", "host2"); _includeRemoteNodes = ImmutableSortedSet.of("host1", "host2"); // Sending an edge from host1 to host2 in layer 3 _topology = new Topology(ImmutableSortedSet.of(Edge.of("host1", "int1", "host2", "int2"))); }
@Test public void matchesCaseInsensitive() { Interface iface = Interface.builder() .setName("Loopback0") .setOwner(new Configuration("c", ConfigurationFormat.CISCO_IOS)) .setVrf(new Vrf("vrfA")) .build(); iface.setDescription("secrets are never secrets for long"); assertTrue(new InterfacesSpecifier("name:LoopBAck.*").matches(iface)); assertTrue(new InterfacesSpecifier("desc:SECrets.*").matches(iface)); assertTrue(new InterfacesSpecifier("type:Loopback").matches(iface)); assertTrue(new InterfacesSpecifier("vrf:vrfa").matches(iface)); }