public IpPrefix(Ipv4Prefix _ipv4Prefix) { super(); this._ipv4Prefix = _ipv4Prefix; this._ipv6Prefix = null; this._value = _ipv4Prefix.getValue().toString().toCharArray(); }
/** * Creates address array from address part of {@link Ipv4Prefix} */ public static byte[] ipv4AddressPrefixToArray(@Nonnull final Ipv4Prefix ipv4Prefix) { checkNotNull(ipv4Prefix, "Cannot convert null prefix"); byte[] retval = new byte[4]; String[] address = ipv4Prefix.getValue().substring(0, ipv4Prefix.getValue().indexOf('/')).split("\\."); for (int d = 0; d < 4; d++) { retval[d] = (byte) (Short.parseShort(address[d]) & 0xff); } return retval; }
private void subNet(Ipv4Prefix ipv4Prefix) throws UnknownHostException { String[] value = ipv4Prefix.getValue().split("/"); this.bits = Integer.parseInt(value[1]); this.ipv4Mask = -1 << (32 - this.bits); this.ipv4Subnet = ipv4ToInt(value[0]); }
private void initializeIpv4(Ipv4Prefix ipv4Prefix) throws UnknownHostException { if (ipv4Prefix != null) { subNet(ipv4Prefix); this.prefix = ipv4Prefix.getValue(); this.initialized = true; } }
public char[] getValue() { if (_value == null) { if (_ipv4Prefix != null) { _value = _ipv4Prefix.getValue().toString().toCharArray(); } else if (_ipv6Prefix != null) { _value = _ipv6Prefix.getValue().toString().toCharArray(); } } return _value == null ? null : _value.clone(); }
public static final void buildFlowspecString(final FlowspecType value, final StringBuilder buffer) { if (value instanceof DestinationPrefixCase) { buffer.append("to "); buffer.append(((DestinationPrefixCase) value).getDestinationPrefix().getValue()); } else if (value instanceof SourcePrefixCase) { buffer.append("from "); buffer.append(((SourcePrefixCase) value).getSourcePrefix().getValue()); } else if (value instanceof ProtocolIpCase) { buffer.append("where IP protocol "); buffer.append(NumericOneByteOperandParser.INSTANCE.toString(((ProtocolIpCase) value).getProtocolIps())); } }
private static byte[] toMatchValue(final Ipv4Prefix ipv4Prefix) { final String[] split = ipv4Prefix.getValue().split("/"); final byte[] addressBytes = ipv4AddressNoZoneToArray(split[0]); final byte[] mask = toByteMask(Byte.valueOf(split[1])); for (int i = 0; i < addressBytes.length; ++i) { addressBytes[i] &= mask[i]; } return addressBytes; }
private static String getDestinationAddress(final List<Subobject> subobjects, final String defaultAddress) { if ((subobjects != null) && !subobjects.isEmpty()) { final String prefix = ((IpPrefixCase) subobjects.get(subobjects.size() - 1).getSubobjectType()) .getIpPrefix().getIpPrefix().getIpv4Prefix().getValue(); return prefix.substring(0, prefix.indexOf('/')); } return defaultAddress; } }
/** * {@inheritDoc} */ @Override public String getCidrText() { return getIpPrefix().getIpv4Prefix().getValue(); }
public static IpPrefix createGwPrefix(IpAddress ipAddress, IpPrefix network) { StringBuilder buf = new StringBuilder(); buf.append(ipAddress.getValue()); String str = network.getIpv4Prefix().getValue(); buf.append(str.substring(str.indexOf("/"))); return new IpPrefix(new Ipv4Prefix(buf.toString())); }
static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix v4LispPrefixToInetPrefix( final Ipv4Prefix prefix) { return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix( prefix.getIpv4Prefix().getValue()); }
public static String getStringIpPrefix(IpPrefix ipPrefix) { Preconditions.checkNotNull(ipPrefix); if (ipPrefix.getIpv4Prefix() != null) { String ipPrefixIpv4 = ipPrefix.getIpv4Prefix().getValue(); return ipPrefixIpv4.replace('/', '_'); } String ipPrefixIpv6 = ipPrefix.getIpv6Prefix().getValue(); return ipPrefixIpv6.replace('/', '_').replace(':', '.'); }
public static String ipPrefixToStringIpAddress(IpPrefix prefix) { if (prefix.getIpv4Prefix() != null) { String[] split = prefix.getIpv4Prefix().getValue().split("/"); return split[0]; } else if (prefix.getIpv6Prefix() != null) { String[] split = prefix.getIpv6Prefix().getValue().split("/"); return split[0]; } throw new IllegalArgumentException("Cannot extract IP prefix from IP address {}" + prefix); } }
private String getIpPrefixStr(final IpPrefix ipPrefix) { final Ipv4Prefix ipv4 = ipPrefix.getIpv4Prefix(); if (ipv4 != null) { return ipv4.getValue(); } else { return ipPrefix.getIpv6Prefix().getValue(); } }
private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, final byte primaryTableId, final byte secondaryTableId) { return flaglessAddDelRouteRequest(booleanToByte(isAdd), 0, null, DEFAULT_HOP_WEIGHT, BYTE_FALSE, ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, primaryTableId, secondaryTableId, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE); }
private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, final int nextHopInterfaceIndex, @Nonnull final Ipv4Address nextHopAddress, final byte nextHopWeight, final int primaryVrf, final int secondaryVrf, final int classifyTableIndex, final boolean classifyIndexSet) { return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, ipv4AddressNoZoneToArray(nextHopAddress.getValue()), nextHopWeight, (byte)0, ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), (byte)1, primaryVrf, secondaryVrf, classifyTableIndex, booleanToByte(classifyIndexSet)); }
private IpAddDelRoute getSimpleHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, final int nextHopInterfaceIndex, @Nonnull final Ipv4Address nextHopAddress, final int primaryVrf, final int secondaryVrf, final int classifyTableIndex, final boolean classifyIndexSet) { return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, ipv4AddressNoZoneToArray(nextHopAddress.getValue()), DEFAULT_HOP_WEIGHT, BYTE_FALSE, ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, primaryVrf, secondaryVrf, classifyTableIndex, booleanToByte(classifyIndexSet)); } }
private static boolean belongsToSubnet(Ipv4Address ipv4Address, Ipv4Prefix subnetPrefix) { SubnetUtils su = new SubnetUtils(subnetPrefix.getValue()); SubnetInfo si = su.getInfo(); return si.isInRange(ipv4Address.getValue()); }
private @Nullable Ipv4Address createSenderIpAddress(EndpointL3 l3Ep, ReadTransaction rTx) { Subnet subnetOfL3Ep = readSubnet(l3Ep, rTx); if (subnetOfL3Ep == null) { return null; } SubnetInfo subnetInfo = new SubnetUtils(subnetOfL3Ep.getIpPrefix().getIpv4Prefix().getValue()).getInfo(); String senderIp = subnetInfo.getHighAddress(); if (senderIp.equals(l3Ep.getKey().getIpAddress().getIpv4Address().getValue())) { senderIp = subnetInfo.getLowAddress(); } return new Ipv4Address(senderIp); }