Search in sources :

Example 6 with Ipv4PrefixBinary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.

the class MaskUtil method normalize.

public static Eid normalize(Eid eid, short mask) {
    Address address = eid.getAddress();
    try {
        if (address instanceof Ipv4PrefixBinary) {
            byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
            return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv6PrefixBinary) {
            byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
            return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv4Prefix) {
            final String addr = getPrefixAddress(((Ipv4Prefix) address).getIpv4Prefix().getValue());
            InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
            return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address) normalized, mask);
        } else if (address instanceof Ipv6Prefix) {
            final String addr = getPrefixAddress(((Ipv6Prefix) address).getIpv6Prefix().getValue());
            InetAddress normalized = normalizeIP(InetAddresses.forString(addr), mask);
            return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address) normalized, mask);
        } else if (address instanceof InstanceId) {
            // TODO - not absolutely necessary, but should be implemented
            return eid;
        }
    } catch (UnknownHostException e) {
        LOG.warn("Failed to normalize EID {} with mask {}, returning original EID", eid, mask, e);
    }
    return eid;
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) InetAddress(java.net.InetAddress) Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) UnknownHostException(java.net.UnknownHostException) InstanceId(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId) Ipv6PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary) Inet6Address(java.net.Inet6Address) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix) InetAddress(java.net.InetAddress) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix)

Example 7 with Ipv4PrefixBinary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.

the class Ipv4PrefixBinarySerializer method serializeData.

@Override
protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
    Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) lispAddress.getAddress();
    buffer.put(prefix.getIpv4AddressBinary().getValue());
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary)

Example 8 with Ipv4PrefixBinary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.

the class Ipv4PrefixBinarySerializer method deserializeEidData.

@Override
protected Eid deserializeEidData(ByteBuffer buffer, LispAddressSerializerContext ctx) {
    byte[] ipBuffer = new byte[4];
    buffer.get(ipBuffer);
    Ipv4PrefixBinary prefix = new Ipv4PrefixBinaryBuilder().setIpv4AddressBinary(new Ipv4AddressBinary(ipBuffer)).setIpv4MaskLength(ctx.getMaskLen()).build();
    EidBuilder eb = new EidBuilder();
    eb.setAddressType(Ipv4PrefixBinaryAfi.class);
    eb.setVirtualNetworkId(getVni(ctx));
    eb.setAddress(prefix);
    return eb.build();
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) Ipv4AddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary) EidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder) Ipv4PrefixBinaryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder)

Example 9 with Ipv4PrefixBinary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.

the class LispAddressUtil method convertFromBinary.

private static Pair<Class<? extends LispAddressFamily>, Address> convertFromBinary(Address addr) {
    Address convAddr = null;
    Class<? extends LispAddressFamily> convType = null;
    if (addr instanceof Ipv4PrefixBinary) {
        convAddr = convertFromBinary((Ipv4PrefixBinary) addr);
        convType = Ipv4PrefixAfi.class;
    } else if (addr instanceof Ipv6PrefixBinary) {
        convAddr = convertFromBinary((Ipv6PrefixBinary) addr);
        convType = Ipv6PrefixAfi.class;
    } else if (addr instanceof Ipv4Binary) {
        convAddr = convertFromBinary((Ipv4Binary) addr);
        convType = Ipv4Afi.class;
    } else if (addr instanceof Ipv6Binary) {
        convAddr = convertFromBinary((Ipv6Binary) addr);
        convType = Ipv6Afi.class;
    }
    return new ImmutablePair<Class<? extends LispAddressFamily>, Address>(convType, convAddr);
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) Ipv6PrefixAfi(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6PrefixAfi) Ipv6Afi(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi) InetAddress(java.net.InetAddress) Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) KeyValueAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.KeyValueAddress) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Ipv6PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary) Ipv4Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary) Ipv6Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary)

Example 10 with Ipv4PrefixBinary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary in project lispflowmapping by opendaylight.

the class MappingSystem method getVirtualParent.

private static Eid getVirtualParent(Eid eid) {
    if (eid.getAddress() instanceof Ipv4PrefixBinary) {
        Ipv4PrefixBinary prefix = (Ipv4PrefixBinary) eid.getAddress();
        short parentPrefixLength = (short) (prefix.getIpv4MaskLength() - 1);
        byte[] parentPrefix = MaskUtil.normalizeByteArray(prefix.getIpv4AddressBinary().getValue(), parentPrefixLength);
        return LispAddressUtil.asIpv4PrefixBinaryEid(eid, parentPrefix, parentPrefixLength);
    } else if (eid.getAddress() instanceof Ipv6PrefixBinary) {
        Ipv6PrefixBinary prefix = (Ipv6PrefixBinary) eid.getAddress();
        short parentPrefixLength = (short) (prefix.getIpv6MaskLength() - 1);
        byte[] parentPrefix = MaskUtil.normalizeByteArray(prefix.getIpv6AddressBinary().getValue(), parentPrefixLength);
        return LispAddressUtil.asIpv6PrefixBinaryEid(eid, parentPrefix, parentPrefixLength);
    }
    return null;
}
Also used : Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) Ipv6PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary)

Aggregations

Ipv4PrefixBinary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary)14 Ipv6PrefixBinary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary)8 Test (org.junit.Test)5 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)5 InetAddress (java.net.InetAddress)4 Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address)4 Inet4Address (java.net.Inet4Address)3 Inet6Address (java.net.Inet6Address)3 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)3 Ipv4Binary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary)3 Ipv6Binary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary)3 EidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder)3 UnknownHostException (java.net.UnknownHostException)2 InstanceId (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId)2 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix)2 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix)2 Ipv4AddressBinary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary)2 Ipv4PrefixBinaryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinaryBuilder)2 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)2 InetSocketAddress (java.net.InetSocketAddress)1