/** * Detects whether {@code IpPrefix} is ipv6 */ public static boolean isIpv6(IpPrefix address) { checkNotNull(address, "Address cannot be null"); checkState(!(address.getIpv4Prefix() == null && address.getIpv6Prefix() == null), "Invalid address"); return address.getIpv6Prefix() != null; }
private byte resolveTrafficType(IpPrefix prefix) { if (prefix.getIpv4Prefix() != null) { return VPP_IPV4_TYPE; } else if (prefix.getIpv6Prefix() != null) { return VPP_IPV6_TYPE; } return VPP_UNRESOLVED_TYPE; }
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); } }
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(':', '.'); }
@Override public void serializeTlvBody(final IpPrefix tlv, final ByteBuf body) { if (tlv.getIpv4Prefix() != null) { ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv4Prefix(), body); } else if (tlv.getIpv6Prefix() != null) { ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv6Prefix(), body); } }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); final ByteBuf body = Unpooled.buffer(); Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory."); writeIpv6Prefix(prefix.getIpv6Prefix(), body); body.writeZero(RESERVED); EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer); } }
private String getIpPrefixStr(final IpPrefix ipPrefix) { final Ipv4Prefix ipv4 = ipPrefix.getIpv4Prefix(); if (ipv4 != null) { return ipv4.getValue(); } else { return ipPrefix.getIpv6Prefix().getValue(); } }
/** * Initial IPPrefixHelper. * @param ipPrefix * @throws UnknownHostException */ public IPPrefixHelper(IpPrefix ipPrefix) throws UnknownHostException { initializeIpv4(ipPrefix.getIpv4Prefix()); initializeIpv6(ipPrefix.getIpv6Prefix()); }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH); Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory."); writeIpv6Prefix(prefix.getIpv6Prefix(), body); Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } }
/** * Create an {@link IpNetwork} instance which represents the IP network * specified by the given {@link IpPrefix} instance. * * @param ipp An {@link IpPrefix} instance which represents the IP * network. * @return An {@link IpNetwork} instance which represents the IP network * specified by {@code ipp}. Note that {@code null} is returned * if {@code ipp} is {@code null} or it does not contain valid * value. * @throws IllegalArgumentException * The given {@link IpPrefix} instance is invalid. */ public static final IpNetwork create(IpPrefix ipp) { if (ipp != null) { Ipv4Prefix ipv4 = ipp.getIpv4Prefix(); if (ipv4 != null) { return create(ipv4.getValue()); } if (ipp.getIpv6Prefix() != null) { throw new IllegalArgumentException( "Unsupported IP prefix: " + ipp); } } return null; }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass()); if (prefix.getIpv6Prefix() != null) { new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer); } else { final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH); Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory."); writeIpv4Prefix(prefix.getIpv4Prefix(), body); body.writeZero(RESERVED); EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer); } } }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable()); flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse()); final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH); Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory."); writeIpv6Prefix(prefix.getIpv6Prefix(), body); flags.toByteBuf(body); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); } }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass()); if (prefix.getIpv6Prefix() != null) { new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer); } else { final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH); Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory."); writeIpv4Prefix(prefix.getIpv4Prefix(), body); Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory."); writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body); XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer); } } }
@Override public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) { Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass()); final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix(); final IpPrefix prefix = specObj.getIpPrefix(); Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass()); if (prefix.getIpv6Prefix() != null) { new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer); } else { final BitArray flags = new BitArray(FLAGS_SIZE); flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable()); flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse()); final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH); Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory."); writeIpv4Prefix(prefix.getIpv4Prefix(), body); flags.toByteBuf(body); RROSubobjectUtil.formatSubobject(TYPE, body, buffer); } } }
? MatchFieldType.ipv6_source : MatchFieldType.ipv6_destination; flowMatches.add(new MatchInfo(MatchFieldType.eth_type, new long[] {NwConstants.ETHTYPE_IPV6})); flowMatches.add(new MatchInfo(matchFieldType, new String[] {ipPrefix.getIpv6Prefix().getValue()}));
etherType = IPv4; prefixLength = Integer.valueOf(l3Prefix.getIpPrefix().getIpv4Prefix().getValue().split("/")[1]); } else if (l3Prefix.getIpPrefix().getIpv6Prefix() != null) { etherType = IPv6; prefixLength = Integer.valueOf(l3Prefix.getIpPrefix().getIpv6Prefix().getValue().split("/")[1]); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Prefix);
private Layer3Match createLayer3Match(IpPrefix ipPrefix, boolean isSrc) { if (ipPrefix.getIpv4Prefix() != null) { if (isSrc) { return new Ipv4MatchBuilder().setIpv4Source(ipPrefix.getIpv4Prefix()).build(); } else { return new Ipv4MatchBuilder().setIpv4Destination(ipPrefix.getIpv4Prefix()).build(); } } else { if (isSrc) { return new Ipv6MatchBuilder().setIpv6Source(ipPrefix.getIpv6Prefix()).build(); } else { return new Ipv6MatchBuilder().setIpv6Destination(ipPrefix.getIpv6Prefix()).build(); } } }
if (isDirectionIngress) { aceIpv6Builder.setSourceIpv6Network(new Ipv6Prefix( securityRule.getRemoteIpPrefix().getIpv6Prefix().getValue())); } else { aceIpv6Builder.setDestinationIpv6Network(new Ipv6Prefix( securityRule.getRemoteIpPrefix().getIpv6Prefix().getValue()));
rule.getRemoteIpPrefix().getIpv4Prefix().getValue():rule.getRemoteIpPrefix().getIpv6Prefix().getValue());
rule.getRemoteIpPrefix().getIpv4Prefix().getValue():rule.getRemoteIpPrefix().getIpv6Prefix().getValue());