public static final byte[] convertArbitraryMaskToByteArray(DottedQuad mask) { String maskValue; if (mask != null && mask.getValue() != null) { maskValue = mask.getValue(); } else { maskValue = DEFAULT_ARBITRARY_BIT_MASK; } InetAddress maskInIpFormat = null; try { maskInIpFormat = InetAddress.getByName(maskValue); } catch (UnknownHostException e) { LOG.error ("Failed to resolve the ip address of the mask ",e); } byte[] bytes = maskInIpFormat.getAddress(); return bytes; }
static final byte[] convertArbitraryMaskToByteArray(DottedQuad mask) { String maskValue; if (mask.getValue() != null) { maskValue = mask.getValue(); } else { maskValue = DEFAULT_ARBITRARY_BIT_MASK; } InetAddress maskInIpFormat = null; try { maskInIpFormat = InetAddress.getByName(maskValue); } catch (UnknownHostException e) { LOG.error("Failed to recognize the host while converting mask ", e); } byte[] bytes = maskInIpFormat.getAddress(); return bytes; }
static String normalizeIpv4Address(Ipv4Address ipAddress, DottedQuad netMask) { String actualIpAddress=""; String[] netMaskParts = netMask.getValue().split("\\."); String[] ipAddressParts = ipAddress.getValue().split("\\."); for (int i=0; i<ipAddressParts.length;i++) { int integerFormatIpAddress=Integer.parseInt(ipAddressParts[i]); int integerFormatNetMask=Integer.parseInt(netMaskParts[i]); int ipAddressPart=(integerFormatIpAddress) & (integerFormatNetMask); actualIpAddress += ipAddressPart; if (i != ipAddressParts.length -1 ) { actualIpAddress = actualIpAddress+"."; } } return actualIpAddress; }
private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier<Address> id, @Nonnull final String subInterfaceName, final int subInterfaceIndex, @Nonnull final Address address, @Nonnull final Netmask subnet) throws WriteFailedException { try { LOG.debug("Setting Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", subInterfaceName, subInterfaceIndex, subnet, address); final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", subInterfaceName, subInterfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } }
private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier<Address> id, @Nonnull final String interfaceName, final int interfaceIndex, @Nonnull final Address address, @Nonnull final Netmask subnet) throws WriteFailedException { try { LOG.debug("Setting Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } }
private static Function<Address, Short> toPrefixLength() { return (final Address address) -> { final Subnet subnet = address.getSubnet(); if (subnet instanceof PrefixLength) { return ((PrefixLength) subnet).getPrefixLength(); } if (address.getSubnet() instanceof Netmask) { return (short) Ipv4WriteUtils.getSubnetMaskLength( checkNotNull(((Netmask) subnet).getNetmask(), "No netmask defined for %s", subnet) .getValue()); } throw new IllegalArgumentException("Unsupported subnet : " + subnet); }; } }
String statsDstIpAddress = normalizeIpv4Address(statsIpv4MatchArbitraryBitMask.getIpv4DestinationAddressNoMask(), statsIpv4MatchArbitraryBitMask.getIpv4DestinationArbitraryBitmask()); if (MatchComparatorHelper.compareStringNullSafe(storedIpv4MatchArbitraryBitMask.getIpv4DestinationArbitraryBitmask().getValue(), statsIpv4MatchArbitraryBitMask.getIpv4DestinationArbitraryBitmask().getValue())) { verdict = MatchComparatorHelper.compareStringNullSafe(storedDstIpAddress, statsDstIpAddress); String statsSrcIpAddress = normalizeIpv4Address(statsIpv4MatchArbitraryBitMask.getIpv4SourceAddressNoMask() ,statsIpv4MatchArbitraryBitMask.getIpv4SourceArbitraryBitmask()); if (MatchComparatorHelper.compareStringNullSafe(storedIpv4MatchArbitraryBitMask.getIpv4SourceArbitraryBitmask().getValue(), statsIpv4MatchArbitraryBitMask.getIpv4SourceArbitraryBitmask().getValue())) { verdict = MatchComparatorHelper.compareStringNullSafe(storedSrcIpAddress, statsSrcIpAddress);