Search in sources :

Example 1 with InstanceId

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId 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 2 with InstanceId

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId in project lispflowmapping by opendaylight.

the class MappingServiceIntegrationTest method registerAndQuery__SegmentLCAF.

public void registerAndQuery__SegmentLCAF() throws SocketTimeoutException {
    cleanUP();
    String ipString = "10.20.255.30";
    int instanceId = 6;
    EidBuilder eb = new EidBuilder();
    eb.setAddressType(Ipv4PrefixAfi.class);
    eb.setVirtualNetworkId(new InstanceIdType((long) instanceId));
    eb.setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix(ipString)).build());
    MapReply reply = registerAddressAndQuery(eb.build());
    Eid receivedAddress = reply.getMappingRecordItem().get(0).getMappingRecord().getEid();
    assertEquals(Ipv4PrefixAfi.class, receivedAddress.getAddressType());
    assertEquals(ipString, ((Ipv4Prefix) receivedAddress.getAddress()).getIpv4Prefix().getValue());
    assertEquals(instanceId, receivedAddress.getVirtualNetworkId().getValue().intValue());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MapReply(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply) GotMapReply(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply) InstanceIdType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType) Ipv4PrefixBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder) SourceEidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder) EidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix)

Example 3 with InstanceId

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId in project lispflowmapping by opendaylight.

the class MaskUtil method normalize.

public static Eid normalize(Eid eid) {
    Address address = eid.getAddress();
    try {
        if (address instanceof Ipv4PrefixBinary) {
            byte[] addr = ((Ipv4PrefixBinary) address).getIpv4AddressBinary().getValue();
            short mask = ((Ipv4PrefixBinary) address).getIpv4MaskLength();
            return LispAddressUtil.asIpv4PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv6PrefixBinary) {
            byte[] addr = ((Ipv6PrefixBinary) address).getIpv6AddressBinary().getValue();
            short mask = ((Ipv6PrefixBinary) address).getIpv6MaskLength();
            return LispAddressUtil.asIpv6PrefixBinaryEid(eid, normalizeByteArray(addr, mask), mask);
        } else if (address instanceof Ipv4Prefix) {
            String[] v4prefix = splitPrefix(((Ipv4Prefix) address).getIpv4Prefix().getValue());
            short mask = Short.parseShort(v4prefix[1]);
            InetAddress normalized = normalizeIP(InetAddresses.forString(v4prefix[0]), mask);
            return LispAddressUtil.asIpv4PrefixEid(eid, (Inet4Address) normalized, mask);
        } else if (address instanceof Ipv6Prefix) {
            String[] v6prefix = splitPrefix(((Ipv6Prefix) address).getIpv6Prefix().getValue());
            short mask = Short.parseShort(v6prefix[1]);
            InetAddress normalized = normalizeIP(InetAddresses.forString(v6prefix[0]), mask);
            return LispAddressUtil.asIpv6PrefixEid(eid, (Inet6Address) normalized, mask);
        } else if (address instanceof Ipv4) {
            return LispAddressUtil.asIpv4PrefixEid(((Ipv4) address).getIpv4(), eid.getVirtualNetworkId());
        } else if (address instanceof Ipv6) {
            return LispAddressUtil.asIpv6PrefixEid(((Ipv6) address).getIpv6(), eid.getVirtualNetworkId());
        } else if (address instanceof InstanceId) {
            // TODO - not absolutely necessary, but should be implemented
            return eid;
        } else if (address instanceof SourceDestKey) {
            return normalizeSrcDst(eid);
        } else if (address instanceof ServicePath) {
            // Build new Service Path eid with service index set to 0
            long spi = ((ServicePath) address).getServicePath().getServicePathId().getValue();
            long vni = eid.getVirtualNetworkId() != null ? eid.getVirtualNetworkId().getValue() : -1;
            return LispAddressUtil.asServicePathEid(vni, spi, (short) 0);
        }
    } catch (UnknownHostException e) {
        LOG.warn("Failed to normalize EID {}, returning original", eid, e);
    }
    return eid;
}
Also used : 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) Ipv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6) InstanceId(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId) Ipv4(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4) Ipv6PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary) Inet6Address(java.net.Inet6Address) ServicePath(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix) Ipv4PrefixBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary) SourceDestKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) 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)

Example 4 with InstanceId

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId in project lispflowmapping by opendaylight.

the class InstanceIdSerializer method deserializeLcafEidData.

@Override
protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
    long instanceId = (int) ByteUtil.asUnsignedInteger(buffer.getInt());
    if (instanceId > MAX_INSTANCE_ID) {
        throw new LispSerializationException("Instance ID is longer than 24 bits: " + instanceId);
    }
    ctx.setVni(new InstanceIdType(instanceId));
    return LispAddressSerializer.getInstance().deserializeEid(buffer, ctx);
}
Also used : InstanceIdType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)

Example 5 with InstanceId

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId in project lispflowmapping by opendaylight.

the class InstanceIdSerializer method serializeData.

@Override
protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
    InstanceId iid = (InstanceId) lispAddress.getAddress();
    // The IID mask-len field is in the LCAF header on the res2 position
    buffer.put(buffer.position() - 3, iid.getInstanceId().getMaskLength().byteValue());
    buffer.putInt(iid.getInstanceId().getIid().getValue().intValue());
    LispAddressSerializer.getInstance().serialize(buffer, lispAddress);
}
Also used : InstanceId(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId)

Aggregations

InstanceId (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix)3 Inet4Address (java.net.Inet4Address)2 Inet6Address (java.net.Inet6Address)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 InstanceIdType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType)2 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)2 Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address)2 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix)2 Ipv4PrefixBinary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4PrefixBinary)2 Ipv6PrefixBinary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6PrefixBinary)2 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)1 Ipv4 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4)1 Ipv4PrefixBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder)1 Ipv6 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6)1 ServicePath (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath)1 SourceDestKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey)1 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)1 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)1