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; }
@Override protected IpPrefix ipv6Prefix(final Ipv6Prefix addr) { return new IpPrefix(addr); }
public static String getSubnetCidrAsString(IpPrefix subnet) { return (subnet == null) ? StringUtils.EMPTY : String.valueOf(subnet.getValue()); } public static <T> List<T> emptyIfNull(List<T> list) {
private Subnets findSubnets(List<Subnets> subnets, String subnetIp) { for (Subnets subnet : subnets) { IpPrefix subnetPrefix = new IpPrefix(subnetIp.toCharArray()); if (subnet.getPrefix().equals(subnetPrefix)) { return subnet; } } Subnets retSubnet = newSubnets(subnetIp); subnets.add(retSubnet); return retSubnet; }
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())); }
private String stripToCidr(final IpPrefix value) { return value.getIpv4Prefix().getValue(); } }
@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); } }
@Override public boolean isEqualTo(final IpPrefix value) { return myValue.equals(value); } }
public static boolean isPlain(final IpPrefix key) { return key.getIpv4Prefix().getValue().endsWith(FULL_IPV4_MASK_SUFFIX); }
@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); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HwVtep HwVtep = (HwVtep) o; if (vlanID != HwVtep.vlanID) return false; if (!transportZone.equals(HwVtep.transportZone)) return false; if (tunnel_type != null ? !tunnel_type.equals(HwVtep.tunnel_type) : HwVtep.tunnel_type != null) return false; if (!ipPrefix.equals(HwVtep.ipPrefix)) return false; if (gatewayIP != null ? !gatewayIP.equals(HwVtep.gatewayIP) : HwVtep.gatewayIP != null) return false; if (!topo_id.equals(HwVtep.topo_id)) return false; if (!node_id.equals(HwVtep.node_id)) return false; return hwIp.equals(HwVtep.hwIp); }
/** * 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; }
@Override protected IpPrefix ipv4Prefix(Ipv4Prefix addr) { return new IpPrefix(addr); }
private static void translate(@Nonnull final IpPrefix prefix, final IpAddDelRoute request) { // BGP Prefix SID for v6 is not supported final Ipv4Prefix ipv4Prefix = prefix.getIpv4Prefix(); checkArgument(ipv4Prefix != null, "Unsupported IpPrefix: %s, ipv4Prefix is missing.", prefix); request.dstAddressLength = Ipv4Translator.INSTANCE.extractPrefix(ipv4Prefix); request.dstAddress = Ipv4Translator.INSTANCE.ipv4AddressPrefixToArray(ipv4Prefix); }
public static int getMask(IpPrefix ip) { StringBuilder buf = new StringBuilder(); boolean foundSlash = false; for (char x : ip.getValue()) { if (!foundSlash && x == '/') { foundSlash = true; continue; } if (foundSlash) { buf.append(x); } } return Integer.parseInt(buf.toString()); }
@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); } }
public static VtepConfigSchema validateForAddVtepConfigSchema(VtepConfigSchema schema, List<VtepConfigSchema> existingSchemas) { VtepConfigSchema validSchema = validateVtepConfigSchema(schema); for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) { if (!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName()) && schema.getSubnet().equals(existingSchema.getSubnet())) { String subnetCidr = getSubnetCidrAsString(schema.getSubnet()); Preconditions.checkArgument(false, new StringBuilder("VTEP schema with subnet [").append(subnetCidr) .append("] already exists. Multiple VTEP schemas with same subnet is not allowed.").toString()); } } if (isNotEmpty(getDpnIdList(validSchema.getDpnIds()))) { String tzone = validSchema.getTransportZoneName(); List<BigInteger> lstDpns = getConflictingDpnsAlreadyConfiguredWithTz(validSchema.getSchemaName(), tzone, getDpnIdList(validSchema.getDpnIds()), existingSchemas); if (!lstDpns.isEmpty()) { Preconditions.checkArgument(false, new StringBuilder("DPN's ").append(lstDpns).append(" already configured for transport zone ") .append(tzone).append(". Only one end point per transport Zone per Dpn is allowed.") .toString()); } if (schema.getTunnelType().equals(TunnelTypeGre.class)){ validateForSingleGreTep(validSchema.getSchemaName(), getDpnIdList(validSchema.getDpnIds()), existingSchemas); } } return validSchema; } private static void validateForSingleGreTep(String schemaName, List<BigInteger> lstDpnsForAdd,
@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 protected IpPrefix ipv6Prefix(Ipv6Prefix addr) { return new IpPrefix(addr); }
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; } }