@Test public void testComputeRoutesWithNextHop() { String c1 = "c1"; String v1 = "v1"; String i1 = "i1"; ConnectedRoute r1 = new ConnectedRoute(P1, i1); Map<String, Map<String, Fib>> fibs = ImmutableMap.of( c1, ImmutableMap.of( v1, MockFib.builder() .setRoutesByNextHopInterface(ImmutableMap.of(i1, ImmutableSet.of(r1))) .build())); Configuration config = _cb.setHostname(c1).build(); Vrf vrf = _vb.setName(v1).setOwner(config).build(); _ib.setName(i1).setVrf(vrf).setOwner(config).build(); Map<String, Map<String, Map<String, Set<AbstractRoute>>>> result = ForwardingAnalysisImpl.computeRoutesWithNextHop(ImmutableMap.of(c1, config), fibs); assertThat( result, equalTo( ImmutableMap.of(c1, ImmutableMap.of(v1, ImmutableMap.of(i1, ImmutableSet.of(r1)))))); }
@Test public void testOspfAreaBuilder() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(CONFIG_FORMAT).build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); OspfProcess.Builder ob = nf.ospfProcessBuilder(); OspfProcess ospfProcess = ob.setVrf(vrf).build(); OspfArea.Builder oab = nf.ospfAreaBuilder(); OspfArea oa1 = oab.build(); OspfArea oa2 = oab.setOspfProcess(ospfProcess).build(); Interface iface = nf.interfaceBuilder().setOwner(c).setActive(false).setVrf(vrf).setOspfArea(oa2).build(); assertThat(oa1.getAreaNumber(), not(equalTo(oa2.getAreaNumber()))); assertThat(oa1, not(sameInstance(oa2))); assertThat(ospfProcess.getAreas().get(oa2.getAreaNumber()), sameInstance(oa2)); assertThat(oa2, OspfAreaMatchers.hasInterfaces(hasItem(iface.getName()))); assertThat(iface.getOspfAreaName(), equalTo(oa2.getAreaNumber())); } }
@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 testToLogicalEdgePresent() { String c1Name = "c1"; String c2Name = "c2"; String iName = "i1"; Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1); _ib.setName(iName).build(); Configuration c2 = _cb.setHostname(c2Name).build(); Vrf v2 = _vb.setOwner(c2).build(); _ib.setOwner(c2).setVrf(v2); _ib.setName(iName).build(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1, c2Name, c2)); Layer1Edge edge = new Layer1Edge(new Layer1Node(c1Name, iName), new Layer1Node(c2Name, iName)); // If both nodes of a layer-1 physical edge, can be mapped to a layer-1 logical node, the // resulting edge should contain those logical nodes. assertThat( edge.toLogicalEdge(networkConfigurations), equalTo( new Layer1Edge( edge.getNode1().toLogicalNode(networkConfigurations), edge.getNode2().toLogicalNode(networkConfigurations)))); } }
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();
@Test public void testInterfaceBuilder() { NetworkFactory nf = new NetworkFactory(); Interface.Builder ib = nf.interfaceBuilder(); Interface i1 = ib.build(); Interface i2 = ib.build(); Configuration c = nf.configurationBuilder().setConfigurationFormat(CONFIG_FORMAT).build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); ib.setOwner(c); Interface i3 = ib.build(); ib.setVrf(vrf); Interface i4 = ib.build(); assertThat(i1.getName(), is(notNullValue())); assertThat(i1.getName(), not(equalTo(i2.getName()))); assertThat(c.getAllInterfaces(), not(hasKey(i1.getName()))); assertThat(i2.getName(), is(notNullValue())); assertThat(c.getAllInterfaces(), not(hasKey(i2.getName()))); assertThat(c.getAllInterfaces(), hasKey(i3.getName())); assertThat(i3.getOwner(), sameInstance(c)); assertThat(vrf.getInterfaces(), not(hasKey(i3.getName()))); assertThat(c.getAllInterfaces(), hasKey(i4.getName())); assertThat(vrf.getInterfaces(), hasKey(i4.getName())); assertThat(i4.getVrf(), sameInstance(vrf)); }
private static SortedMap<String, Configuration> aclNetwork() { NetworkFactory nf = new NetworkFactory(); Configuration.Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS); ImmutableSortedMap.Builder<String, Configuration> configs = new ImmutableSortedMap.Builder<>(Comparator.naturalOrder()); Configuration c1 = cb.build(); configs.put(c1.getHostname(), c1); Vrf v1 = nf.vrfBuilder().setOwner(c1).build(); // destination interface nf.interfaceBuilder() .setAddress(new InterfaceAddress("1.1.1.0/31")) .setOwner(c1) .setOutgoingFilter( nf.aclBuilder() .setOwner(c1) .setLines(ImmutableList.of(IpAccessListLine.REJECT_ALL)) .build()) .setVrf(v1) .build(); return configs.build(); }
private Batfish maxTracesBatfish() throws IOException { // create a simple network with two paths for a given destination Prefix dst = Prefix.parse("1.1.1.1/32"); NetworkFactory nf = new NetworkFactory(); Configuration config = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf vrf = nf.vrfBuilder().setOwner(config).build(); Interface.Builder ifaceBuilder = nf.interfaceBuilder().setActive(true).setOwner(config).setVrf(vrf); Interface lo0 = ifaceBuilder.setAddress(new InterfaceAddress("5.5.5.5/32")).build(); Interface lo1 = ifaceBuilder.setAddress(new InterfaceAddress("6.6.6.6/32")).build(); Builder routeBuilder = StaticRoute.builder().setNetwork(dst).setAdministrativeCost(1); vrf.setStaticRoutes( ImmutableSortedSet.of( routeBuilder.setNextHopInterface(lo0.getName()).build(), routeBuilder.setNextHopInterface(lo1.getName()).build())); Batfish batfish = BatfishTestUtils.getBatfish(ImmutableSortedMap.of(config.getHostname(), config), _folder); batfish.computeDataPlane(); return batfish; }
@Test public void testToLogicalEdgeNode2Absent() { String c1Name = "c1"; String c2Name = "c2"; String iName = "i1"; Configuration c1 = _cb.setHostname(c1Name).build(); Vrf v1 = _vb.setOwner(c1).build(); _ib.setOwner(c1).setVrf(v1); _ib.setName(iName).build(); Configuration c2 = _cb.setHostname(c2Name).build(); Vrf v2 = _vb.setOwner(c2).build(); _ib.setOwner(c2).setVrf(v2); // force node2 to map to null _ib.setName(iName).build().setChannelGroup("missing"); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1, c2Name, c2)); Layer1Edge edge = new Layer1Edge(new Layer1Node(c1Name, iName), new Layer1Node(c2Name, iName)); // If node2 of a layer-1 physical edge cannot be mapped to a layer-1 logical node, a null edge // should be returned. assertThat(edge.toLogicalEdge(networkConfigurations), nullValue()); }
@Before public void setup() { _nf = new NetworkFactory(); Configuration c = _nf.configurationBuilder() .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setHostname(NODE) .build(); Vrf v = _nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME).setOwner(c).build(); _ib = _nf.interfaceBuilder().setOwner(c).setVrf(v).setName(INTERFACE).setActive(true); _configurations = ImmutableMap.of(c.getHostname(), c); _vnb = VniSettings.builder().setBumTransportMethod(BumTransportMethod.MULTICAST_GROUP); _specifierContext = new TestSpecifierContext() { @Override public Map<String, Configuration> getConfigs() { return _configurations; } }; }
@Test public void testToLogicalEdgeNode1Absent() { String c1Name = "c1"; String c2Name = "c2"; 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"); Configuration c2 = _cb.setHostname(c2Name).build(); Vrf v2 = _vb.setOwner(c2).build(); _ib.setOwner(c2).setVrf(v2); _ib.setName(iName).build(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1, c2Name, c2)); Layer1Edge edge = new Layer1Edge(new Layer1Node(c1Name, iName), new Layer1Node(c2Name, iName)); // If node1 of a layer-1 physical edge cannot be mapped to a layer-1 logical node, a null edge // should be returned. assertThat(edge.toLogicalEdge(networkConfigurations), nullValue()); }
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(); } }
@Test public void testSynthesizeTopology_selfEdges() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf v1 = nf.vrfBuilder().setOwner(c).setName("v1").build(); Vrf v2 = nf.vrfBuilder().setOwner(c).setName("v2").build(); Interface.Builder builder = nf.interfaceBuilder().setOwner(c); Interface i1 = builder.setAddresses(new InterfaceAddress("1.2.3.4/24")).setVrf(v1).build(); Interface i2 = builder.setAddresses(new InterfaceAddress("1.2.3.5/24")).setVrf(v1).build(); Interface i3 = builder.setAddresses(new InterfaceAddress("1.2.3.6/24")).setVrf(v2).build(); Topology t = TopologyUtil.synthesizeL3Topology(ImmutableMap.of(c.getHostname(), c)); assertThat( t.getEdges(), equalTo( ImmutableSet.of( new Edge(i1, i3), new Edge(i3, i1), new Edge(i2, i3), new Edge(i3, i2)))); }
@Test public void testToLogicalNodeAggregate() { 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).build(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(ImmutableSortedMap.of(c1Name, c1)); Layer1Node node = new Layer1Node(c1Name, iName); // If node is member of an aggregate, the resulting logical node should be for the aggregate // interface. assertThat(node.toLogicalNode(networkConfigurations), equalTo(new Layer1Node(c1Name, aName))); }
@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 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 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)); }
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 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)); } }
@Before public void setup() { _nf = new NetworkFactory(); _cb = _nf.configurationBuilder() .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .setHostname(HOSTNAME); _c = _cb.build(); _vb = _nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME).setOwner(_c); _v = _vb.build(); _ib = _nf.interfaceBuilder().setVrf(_v).setOwner(_c).setName(INTERFACE_NAME); }