@Test public void testTryAddInterfaceToVlanIncludedVlan() { Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); Interface iface = _ib.build(); int vlan = 1; IntegerSpace vlans = IntegerSpace.of(vlan); tryAddInterfaceToVlan(switchedVlanInterfaces, NODE, iface, vlan, vlans); assertThat(switchedVlanInterfaces, hasKey(vlan)); assertThat( switchedVlanInterfaces.get(vlan).build(), contains(new NodeInterfacePair(NODE, INTERFACE))); }
@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 testHsrpGroupsEmpty() { _ib.build(); String property = InterfacePropertySpecifier.HSRP_GROUPS; assertThat(getActualValue(property, Schema.set(Schema.STRING)), equalTo(ImmutableSet.of())); }
@Test public void testToLogicalNodeNonAggregate() { String c1Name = "c1"; String iName = "i1"; Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1); _ib.setName(iName).build(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1)); Layer1Node node = new Layer1Node(c1Name, iName); // If node is not member of an aggregate, the resulting logical node should reference the // physical interface name. assertThat(node.toLogicalNode(networkConfigurations), equalTo(node)); } }
@Test public void testComputeIpsAssignedToThisInterface() { Configuration config = _cb.build(); Map<String, Configuration> configs = ImmutableMap.of(config.getHostname(), config); _ib.setOwner(config); InterfaceAddress primary = new InterfaceAddress(P1.getStartIp(), P1.getPrefixLength()); InterfaceAddress secondary = new InterfaceAddress(P2.getStartIp(), P2.getPrefixLength()); Interface i = _ib.setAddresses(primary, secondary).build(); _interfaceOwnedIps = TopologyUtil.computeInterfaceOwnedIps(configs, false); ForwardingAnalysisImpl forwardingAnalysisImpl = initForwardingAnalysisImpl(); IpSpace result = forwardingAnalysisImpl.computeIpsAssignedToThisInterface(i); assertThat(result, containsIp(P1.getStartIp())); assertThat(result, containsIp(P2.getStartIp())); assertThat(result, not(containsIp(P2.getEndIp()))); }
@Test public void testToLogicalNodeInactiveAggregate() { String c1Name = "c1"; String iName = "i1"; String aName = "a1"; Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1); _ib.setName(iName).build().setChannelGroup(aName); _ib.setName(aName).setActive(false).build(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1)); Layer1Node node = new Layer1Node(c1Name, iName); // If node is member of a disabled aggregate, the result should be null assertThat(node.toLogicalNode(networkConfigurations), nullValue()); }
@Test public void testSynthesizeTopology_asymmetricSharedIp() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = cb.build(); Configuration c2 = cb.build(); nf.interfaceBuilder().setOwner(c1).setAddresses(new InterfaceAddress("1.2.3.4/24")).build(); nf.interfaceBuilder().setOwner(c2).setAddresses(new InterfaceAddress("1.2.3.4/28")).build(); Topology t = TopologyUtil.synthesizeL3Topology( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)); assertThat(t.getEdges(), empty()); } }
@Test public void testSynthesizeTopology_asymmetricPartialOverlap() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); Configuration c1 = cb.build(); Configuration c2 = cb.build(); nf.interfaceBuilder().setOwner(c1).setAddresses(new InterfaceAddress("1.2.3.4/24")).build(); nf.interfaceBuilder().setOwner(c2).setAddresses(new InterfaceAddress("1.2.3.17/28")).build(); Topology t = TopologyUtil.synthesizeL3Topology( ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2)); assertThat(t.getEdges(), empty()); }
@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)); }
@Test public void testToLogicalNodeMissingAggregate() { String c1Name = "c1"; String iName = "i1"; Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1); _ib.setName(iName).build().setChannelGroup("missing"); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1)); Layer1Node node = new Layer1Node(c1Name, iName); // If node is member of a missing aggregate, the result should be null assertThat(node.toLogicalNode(networkConfigurations), nullValue()); }
@Test public void testTryAddInterfaceToVlanNullVlan() { Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); Interface iface = _ib.build(); Integer vlan = null; IntegerSpace vlans = IntegerSpace.of(2); tryAddInterfaceToVlan(switchedVlanInterfaces, NODE, iface, vlan, vlans); assertThat(switchedVlanInterfaces, anEmptyMap()); }
@Test public void testTryAddInterfaceToVlanExcludedVlan() { Map<Integer, ImmutableSet.Builder<NodeInterfacePair>> switchedVlanInterfaces = new HashMap<>(); Interface iface = _ib.build(); int vlan = 1; IntegerSpace vlans = IntegerSpace.of(2); tryAddInterfaceToVlan(switchedVlanInterfaces, NODE, iface, vlan, vlans); assertThat(switchedVlanInterfaces, anEmptyMap()); }
public static Interface newInterface( String name, Configuration c, InterfaceAddress primaryAddress) { return FACTORY .interfaceBuilder() .setName(name) .setOwner(c) .setVrf(c.getDefaultVrf()) .setAddress(primaryAddress) .build(); }
@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 testHsrpVersion() { _ib.setHsrpVersion("2").build(); String property = InterfacePropertySpecifier.HSRP_VERSION; assertThat(getActualValue(property, Schema.STRING), equalTo("2")); }
/** Make an interface with the specified parameters */ private Interface iface(String interfaceName, String ip, boolean active, boolean blacklisted) { return _nf.interfaceBuilder() .setName(interfaceName) .setActive(active) .setAddress(new InterfaceAddress(ip)) .setBlacklisted(blacklisted) .build(); }
@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 testHsrpGroups() { _ib.setHsrpGroups(ImmutableMap.of(1, HsrpGroup.builder().setGroupNumber(1).build())).build(); String property = InterfacePropertySpecifier.HSRP_GROUPS; assertThat(getActualValue(property, Schema.set(Schema.STRING)), equalTo(ImmutableSet.of("1"))); }
@Test public void testHsrpVersionUnset() { _ib.build(); String property = InterfacePropertySpecifier.HSRP_VERSION; assertThat(getActualValue(property, Schema.STRING), nullValue()); } }