public static DottedQuad getDefaultInstance(String defaultValue) { return new DottedQuad(defaultValue); }
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; }
@ConstructorProperties("value") public DottedQuad(java.lang.String _value) { if (_value != null) { check_valueLength(_value); } Preconditions.checkNotNull(_value, "Supplied value may not be null"); for (Pattern p : patterns) { Preconditions.checkArgument(p.matcher(_value).matches(), "Supplied value \"%s\" does not match required pattern \"%s\"", _value, p); } this._value = _value; }
public static DottedQuad getDefaultInstance(String defaultValue) { return new DottedQuad(defaultValue); }
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; }
@ConstructorProperties("value") public DottedQuad(String _value) { if (_value != null) { check_valueLength(_value); } Objects.requireNonNull(_value, "Supplied value may not be null"); CodeHelpers.checkPattern(_value, patterns, regexes); this._value = _value; }
public static DottedQuad getDefaultInstance(String defaultValue) { return new DottedQuad(defaultValue); }
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; }
public static DottedQuad getDefaultInstance(String defaultValue) { return new DottedQuad(defaultValue); }
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); } }
public static DottedQuad createArbitraryBitMask(final byte [] bitmask) { DottedQuad dottedQuad = null; if (bitmask == null ) { dottedQuad = new DottedQuad(DEFAULT_ARBITRARY_BIT_MASK); } else { try { dottedQuad = new DottedQuad(InetAddress.getByAddress(bitmask).getHostAddress()); } catch (UnknownHostException e) { LOG.error("Failed to create the dottedQuad notation for the given mask ", e); } } return dottedQuad; }
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); } }
public static DottedQuad extractIpv4AddressMask(final Ipv4Prefix ipv4Prefix) { Iterator<String> addressParts = PREFIX_SPLITTER.split(ipv4Prefix.getValue()).iterator(); addressParts.next(); Integer cidrMask =0; if (addressParts.hasNext()) { cidrMask = Integer.parseInt(addressParts.next()); } long maskBits = 0; maskBits = 0xffffffff << IPV4_ADDRESS_LENGTH - cidrMask; String mask = String.format("%d.%d.%d.%d", (maskBits & 0x0000000000ff000000L) >> 24, (maskBits & 0x0000000000ff0000) >> 16, (maskBits & 0x0000000000ff00) >> 8, maskBits & 0xff); DottedQuad netMask = new DottedQuad(mask); return netMask; }
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);