@JsonIgnore public @Nullable Prefix getPrimaryNetwork() { return _address != null ? _address.getPrefix() : null; }
@VisibleForTesting public static Set<String> getPrefixes(Map<String, Configuration> configurations) { ImmutableSet.Builder<String> prefixes = ImmutableSet.builder(); configurations .values() .forEach( configuration -> configuration .getAllInterfaces() .values() .forEach( iface -> iface.getAllAddresses().stream() .map(interfaceAddress -> interfaceAddress.getPrefix().toString()) .forEach(prefixes::add))); return prefixes.build(); }
private boolean interfaceAddressMatchesIpSpace(InterfaceAddress i) { return !_ipSpaceBdd.and(_ipSpaceToBdd.toBDD(i.getPrefix())).isZero(); }
@Override public IpSpace visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { String node = interfaceLinkLocation.getNodeName(); String iface = interfaceLinkLocation.getInterfaceName(); @Nullable IpSpace linkIpSpace = AclIpSpace.union( interfaceAddresses(node, iface).stream() /* * Only include addresses on networks that might have hosts. */ .filter(address -> address.getNetworkBits() <= HOST_SUBNET_MAX_PREFIX_LENGTH) .map(address -> address.getPrefix().toHostIpSpace()) .collect(Collectors.toList())); return linkIpSpace == null ? EmptyIpSpace.INSTANCE : AclIpSpace.difference(linkIpSpace, _specifierContext.getSnapshotDeviceOwnedIps()); }
BgpActivePeerConfig n = ns.get(i); Interface iface = ge.getStart(); if (ip != null && iface.getAddress().getPrefix().containsIp(ip)) { _ebgpNeighbors.put(ge, n);
/** * Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to * neighbors). */ @VisibleForTesting void initConnectedRib() { // Look at all connected interfaces for (Interface i : _vrf.getInterfaces().values()) { if (i.getActive()) { // Make sure the interface is active // Create a route for each interface prefix for (InterfaceAddress ifaceAddress : i.getAllAddresses()) { Prefix prefix = ifaceAddress.getPrefix(); ConnectedRoute cr = new ConnectedRoute(prefix, i.getName()); _connectedRib.mergeRoute(cr); } } } }
Set<IpWildcard> whitelist = nonNattedInterfaceAddresses.stream() .map(address -> new IpWildcard(address.getPrefix())) .collect(ImmutableSet.toImmutableSet()); IpWildcardSetIpSpace ipSpace =
vrf.getInterfaces().values().stream() .flatMap(i -> i.getAllAddresses().stream()) .filter(ia -> ia != null && ia.getPrefix().containsIp(prefix.getStartIp())) .map(InterfaceAddress::getIp) .findFirst();
if (iface.getActive()) { for (InterfaceAddress address : iface.getAllAddresses()) { Prefix basePrefix = address.getPrefix(); if (!ifaceBasePrefixes.contains(basePrefix)) { ifaceBasePrefixes.add(basePrefix); Prefix basePrefix = address.getPrefix(); if (nodePrefixes.count(basePrefix) > 1) { Ip ip = address.getIp();
Prefix prefix = address.getPrefix(); List<Interface> interfaceBucket = prefixInterfaces.computeIfAbsent(prefix, k -> new LinkedList<>());
public void computeNetworks(Collection<Interface> interfaces) { for (Interface i : interfaces) { InterfaceAddress address = i.getAddress(); if (address == null) { continue; } for (IpWildcard wn : _wildcardNetworks) { // Check if the interface IP address matches the eigrp network // when the wildcard is ORed to both long wildcardLong = wn.getWildcard().asLong(); long eigrpNetworkLong = wn.getIp().asLong(); long intIpLong = address.getIp().asLong(); long wildcardedNetworkLong = eigrpNetworkLong | wildcardLong; long wildcardedIntIpLong = intIpLong | wildcardLong; if (wildcardedNetworkLong == wildcardedIntIpLong) { // since we have a match, we add the INTERFACE network, ignoring // the wildcard stuff from before _networks.add(address.getPrefix()); break; } } } }
/** * Generate IS-IS from a given interface for a given level (with a given metric/admin cost) and * merge them into the appropriate RIB. */ private static Set<IsisRoute> generateIsisInterfaceRoutesPerLevel( int adminCost, IsisRoute.Builder routeBuilder, Interface iface, IsisLevel level) { IsisInterfaceLevelSettings ifaceLevelSettings = level == IsisLevel.LEVEL_1 ? iface.getIsis().getLevel1() : iface.getIsis().getLevel2(); RoutingProtocol isisProtocol = level == IsisLevel.LEVEL_1 ? RoutingProtocol.ISIS_L1 : RoutingProtocol.ISIS_L2; long metric = ifaceLevelSettings.getMode() == IsisInterfaceMode.PASSIVE ? 0L : firstNonNull(ifaceLevelSettings.getCost(), IsisRoute.DEFAULT_METRIC); routeBuilder.setAdmin(adminCost).setLevel(level).setMetric(metric).setProtocol(isisProtocol); return iface.getAllAddresses().stream() .map( address -> routeBuilder.setNetwork(address.getPrefix()).setNextHopIp(address.getIp()).build()) .collect(ImmutableSet.toImmutableSet()); }
@Override public void enterRoa_interface(Roa_interfaceContext ctx) { String ifaceName = getCanonicalInterfaceName(ctx.iname.getText()); _configuration.referenceStructure( INTERFACE, ifaceName, OSPF_AREA_INTERFACE, ctx.iname.getStart().getLine()); Interface iface = _configuration.getInterfaces().get(ifaceName); if (iface == null) { _w.redFlag("OSPF: Interface: '" + ifaceName + "' not declared before OSPF process"); iface = addInterface(ifaceName, ctx.iname, false); } // might cause problems if interfaces are declared after ospf, but // whatever for (InterfaceAddress address : iface.getAllAddresses()) { Prefix prefix = address.getPrefix(); OspfNetwork network = new OspfNetwork(prefix, _currentOspfArea); _currentOspfProcess.getNetworks().add(network); } _currentOspfInterface = iface.getName(); }
public void computeNetworks(Collection<Interface> interfaces) { for (Interface i : interfaces) { InterfaceAddress address = i.getAddress(); if (address == null) { continue; } for (OspfWildcardNetwork wn : _wildcardNetworks) { // first we check if the interface ip address matches the ospf // network when the wildcard is ORed to both long wildcardLong = wn.getWildcard().asLong(); long ospfNetworkLong = wn.getNetworkAddress().asLong(); long intIpLong = address.getIp().asLong(); long wildcardedOspfNetworkLong = ospfNetworkLong | wildcardLong; long wildcardedIntIpLong = intIpLong | wildcardLong; if (wildcardedOspfNetworkLong == wildcardedIntIpLong) { // since we have a match, we add the INTERFACE network, ignoring // the wildcard stuff from before Prefix newOspfNetwork = address.getPrefix(); _networks.add(new OspfNetwork(newOspfNetwork, wn.getArea())); break; } } } }
@Test public void testGetPrefixes() { String nodeName = "nodeName"; String int1 = "int1"; String int2 = "int2"; String address1 = "10.1.3.7/30"; String address2 = "128.212.155.30/24"; String address3 = "124.51.32.2/20"; InterfaceAddress interfaceAddress1 = new InterfaceAddress(address1); InterfaceAddress interfaceAddress2 = new InterfaceAddress(address2); InterfaceAddress interfaceAddress3 = new InterfaceAddress(address3); Map<String, Configuration> configs = new HashMap<>(); Configuration config = createTestConfiguration(nodeName, ConfigurationFormat.HOST, int1, int2); config .getAllInterfaces() .get(int1) .setAllAddresses(ImmutableSet.of(interfaceAddress1, interfaceAddress2)); config .getAllInterfaces() .get(int2) .setAllAddresses(ImmutableSet.of(interfaceAddress2, interfaceAddress3)); configs.put(nodeName, config); assertThat( getPrefixes(configs), equalTo( ImmutableSet.of( interfaceAddress1.getPrefix().toString(), interfaceAddress2.getPrefix().toString(), interfaceAddress3.getPrefix().toString()))); }
private void addLinkFailureConstraints( Encoder enc, Set<GraphEdge> dstPorts, Set<GraphEdge> failSet) { Graph graph = enc.getMainSlice().getGraph(); for (List<GraphEdge> edges : graph.getEdgeMap().values()) { for (GraphEdge ge : edges) { ArithExpr f = enc.getSymbolicFailures().getFailedVariable(ge); assert f != null; if (!failSet.contains(ge)) { enc.add(enc.mkEq(f, enc.mkInt(0))); } else if (dstPorts.contains(ge)) { // Don't fail an interface if it is for the destination ip we are considering // Otherwise, any failure can trivially make equivalence false Prefix pfx = ge.getStart().getAddress().getPrefix(); BitVecExpr dstIp = enc.getMainSlice().getSymbolicPacket().getDstIp(); BoolExpr relevant = enc.getMainSlice().isRelevantFor(pfx, dstIp); BoolExpr notFailed = enc.mkEq(f, enc.mkInt(0)); enc.add(enc.mkImplies(relevant, notFailed)); } } } }
for (org.batfish.datamodel.Interface iface : vrf.getInterfaces().values()) { for (InterfaceAddress interfaceAddress : iface.getAllAddresses()) { if (interfaceAddress.getPrefix().containsIp(neighborAddress)) { Ip ifaceAddress = interfaceAddress.getIp(); updateSource = ifaceAddress;
Prefix pfx = ge.getStart().getAddress().getPrefix(); IpWildcard dst = new IpWildcard(pfx); headerSpace.setDstIps(AclIpSpace.union(headerSpace.getDstIps(), dst.toIpSpace())); Prefix pfx = ge.getStart().getAddress().getPrefix(); IpWildcard dst = new IpWildcard(pfx); headerSpace.setDstIps(AclIpSpace.union(headerSpace.getDstIps(), dst.toIpSpace()));