private static Ip parseMask(String str) { if (str.contains(":")) { String[] parts = str.split(":"); if (parts.length != 2) { throw new BatfishException("Invalid IpWildcard string: '" + str + "'"); } else { return Ip.parse(parts[1]); } } else if (str.contains("/")) { String[] parts = str.split("/"); if (parts.length != 2) { throw new BatfishException("Invalid IpWildcard string: '" + str + "'"); } else { int prefixLength = Integer.parseInt(parts[1]); return Ip.numSubnetBitsToSubnetMask(prefixLength).inverted(); } } else { return Ip.ZERO; } }
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 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; }