private void addNullRouteEdges() { for (Entry<String, List<StaticRoute>> entry : _nullStaticRoutes.entrySet()) { String router = entry.getKey(); List<StaticRoute> srs = entry.getValue(); for (StaticRoute sr : srs) { String name = sr.getNextHopInterface(); // Create null route interface Interface iface = new Interface(name); iface.setActive(true); iface.setAddress( new InterfaceAddress(sr.getNetwork().getStartIp(), sr.getNextHopIp().numSubnetBits())); iface.setBandwidth(0.); // Add static route to all static routes list Map<String, List<StaticRoute>> map = _staticRoutes.get(router); List<StaticRoute> routes = map.computeIfAbsent(name, k -> new ArrayList<>()); routes.add(sr); // Create and add graph edge for null route GraphEdge ge = new GraphEdge(iface, null, router, null, false, true); _allRealEdges.add(ge); _allEdges.add(ge); List<GraphEdge> edges = _edgeMap.computeIfAbsent(router, k -> new ArrayList<>()); edges.add(ge); } } }
private static Configuration createTestConfiguration( String nodeName, ConfigurationFormat configFormat, String... interfaceNames) { Configuration config = new Configuration(nodeName, configFormat); for (String interfaceName : interfaceNames) { config.getAllInterfaces().put(interfaceName, new Interface(interfaceName, config)); } return config; }
private Interface createIbgpInterface(BgpActivePeerConfig n, String peer) { Interface iface = new Interface("iBGP-" + peer); iface.setActive(true); // TODO is this valid. iface.setAddress(new InterfaceAddress(n.getPeerAddress(), Prefix.MAX_PREFIX_LENGTH)); iface.setBandwidth(0.); return iface; }
@Test public void matchesName() { InterfacesSpecifier specifier = new InterfacesSpecifier("name:Loopback.*"); Interface loopbackInterface = new Interface("Loopback0"); Interface nonLoopbackInterface = new Interface("Ethetnet0/0"); assertThat(specifier.matches(loopbackInterface), equalTo(true)); assertThat(specifier.matches(nonLoopbackInterface), equalTo(false)); }
@Test public void matchesDesc() { InterfacesSpecifier specifier = new InterfacesSpecifier("desc:secret.*"); Interface secretInterface = new Interface("Loopback0"); secretInterface.setDescription("secrets are never secrets for long"); Interface nonSecretInterface = new Interface("Ethetnet0/0"); nonSecretInterface.setDescription("this interface couldn't keep its secret"); assertThat(specifier.matches(secretInterface), equalTo(true)); assertThat(specifier.matches(nonSecretInterface), equalTo(false)); }
@Test public void fillPropertyMap() { Configuration configuration = new Configuration("hostname", ConfigurationFormat.CISCO_IOS); configuration.setInterfaces(ImmutableSortedMap.of("i1", new Interface("i1"))); String property = NodePropertySpecifier.INTERFACES; PropertyDescriptor<Configuration> propertyDescriptor = NodePropertySpecifier.JAVA_MAP.get(property); RowBuilder row = Row.builder(); PropertySpecifier.fillProperty(propertyDescriptor, configuration, property, row); // the row should be filled out with the right list and the schemas map should be List<String> assertThat(row.build(), equalTo(Row.builder().put(property, ImmutableList.of("i1")).build())); }
private org.batfish.datamodel.Interface toInterface(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setActive(true); // TODO: may have to change newIface.setBandwidth(iface.getBandwidth()); newIface.setDescription(iface.getDescription()); InterfaceAddress address = iface.getAddress(); if (address != null) { newIface.setAddress(iface.getAddress()); } newIface.getAllAddresses().addAll(iface.getAllAddresses()); for (InterfaceAddress p : newIface.getAllAddresses()) { _ipToInterfaceMap.put(p.getIp(), newIface); } return newIface; }
Interface vpcIface = new Interface(vpcIfaceName, vpcConfigNode); InterfaceAddress vpcIfaceAddress = vpcLink.getSecond(); vpcIface.setAddress(vpcIfaceAddress);
private org.batfish.datamodel.Interface toInterface(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setDescription(iface.getDescription());
/** * Tests that two edges that have the same interface definition but different nodes are not equal. */ @Test public void testEquals() { Interface i1 = new Interface("eth0"); VerboseEdge edge1 = new VerboseEdge(i1, i1, Edge.of("node1", "eth0", "node2", "eth0")); assertEquals(edge1, edge1); VerboseEdge edge2 = new VerboseEdge(i1, i1, Edge.of("node2", "eth0", "node1", "eth0")); assertNotEquals(edge1, edge2); } }
/** * Convert a non-unit interface to the VI {@link org.batfish.datamodel.Interface}. * * <p>Note that bulk of the configuration is stored at the logical interface level, see {@link * #toInterface(Interface)} for those conversions. Here we convert aggregation and bandwidth * settings; track VRF membership. */ private org.batfish.datamodel.Interface toInterfaceNonUnit(Interface iface) { String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c); newIface.setDeclaredNames(ImmutableSortedSet.of(name)); newIface.setDescription(iface.getDescription()); // 802.3ad link aggregation if (iface.get8023adInterface() != null) { newIface.setChannelGroup(iface.get8023adInterface()); } // Redundant ethernet if (iface.getRedundantParentInterface() != null) { newIface.setChannelGroup(iface.getRedundantParentInterface()); } newIface.setBandwidth(iface.getBandwidth()); newIface.setVrf(_c.getVrfs().get(iface.getRoutingInstance())); return newIface; }
Interface remoteVpcIface = new Interface(remoteVpcIfaceName, remoteVpcCfgNode); remoteVpcCfgNode.getAllInterfaces().put(remoteVpcIfaceName, remoteVpcIface); remoteVpcCfgNode
@Override public Interface build() { String name = _name != null ? _name : generateName(); Interface iface = new Interface(name, _owner); ImmutableSet.Builder<InterfaceAddress> allAddresses = ImmutableSet.builder(); iface.setActive(_active);
private static Configuration createConfigurationWithDynamicSession( Configuration.Builder cb, Ip localIp, Prefix remotePrefix, List<Long> remoteAsList) { Configuration node = cb.setHostname("node4").build(); Interface iface = new Interface("iface", node, InterfaceType.PHYSICAL); iface.setAllAddresses( ImmutableList.of(new InterfaceAddress(localIp, Ip.numSubnetBitsToSubnetMask(32)))); BgpPassivePeerConfig peerConfig = BgpPassivePeerConfig.builder() .setLocalAs(3L) .setRemoteAs(remoteAsList) .setLocalIp(localIp) .setPeerPrefix(remotePrefix) .build(); BgpProcess bgpProcess = new BgpProcess(); bgpProcess.setPassiveNeighbors(ImmutableSortedMap.of(remotePrefix, peerConfig)); Vrf vrf1 = new Vrf("vrf"); vrf1.setBgpProcess(bgpProcess); node.setVrfs(ImmutableMap.of("vrf", vrf1)); node.setInterfaces(ImmutableSortedMap.of("iface", iface)); return node; }
private org.batfish.datamodel.Interface toInterface( String ifaceName, Interface iface, Map<String, IpAccessList> ipAccessLists, Configuration c) { org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface( ifaceName, c, computeInterfaceType(iface.getName(), c.getConfigurationFormat())); if (newIface.getInterfaceType() == InterfaceType.VLAN) {
private static Configuration createConfiguration( Configuration.Builder cb, String nodeName, Ip localIp, Ip remoteIp, Long localAs, Long remoteAs) { Configuration node = cb.setHostname(nodeName).build(); Interface iface = new Interface("iface", node, InterfaceType.PHYSICAL); iface.setAllAddresses( ImmutableList.of(new InterfaceAddress(localIp, Ip.numSubnetBitsToSubnetMask(32)))); BgpActivePeerConfig peerConfig = BgpActivePeerConfig.builder() .setLocalAs(localAs) .setRemoteAs(remoteAs) .setLocalIp(localIp) .setPeerAddress(remoteIp) .build(); BgpProcess bgpProcess = new BgpProcess(); bgpProcess.setNeighbors(ImmutableSortedMap.of(Prefix.create(remoteIp, 32), peerConfig)); Vrf vrf1 = new Vrf("vrf"); vrf1.setBgpProcess(bgpProcess); node.setVrfs(ImmutableMap.of("vrf", vrf1)); node.setInterfaces(ImmutableSortedMap.of("iface", iface)); return node; }
String name = iface.getName(); org.batfish.datamodel.Interface newIface = new org.batfish.datamodel.Interface(name, _c, InterfaceType.PHYSICAL); Integer mtu = iface.getMtu(); if (mtu != null) {
c1.setInterfaces( interfaceBuilder .put("Tunnel1", new Interface("Tunnel1", c1)) .put("Tunnel3", new Interface("Tunnel3", c1)) .put("interface5", new Interface("interface5", c1)) .put("Tunnel9", new Interface("Tunnel9", c1)) .put("Tunnel7", new Interface("Tunnel7", c1)) .build()); interfaceBuilder = ImmutableSortedMap.naturalOrder(); c2.setInterfaces( interfaceBuilder .put("Tunnel2", new Interface("Tunnel2", c2)) .put("Tunnel4", new Interface("Tunnel4", c2)) .put("interface6", new Interface("interface6", c2)) .put("Tunnel8", new Interface("Tunnel8", c2)) .put("Tunnel10", new Interface("Tunnel10", c2)) .build());