Search in sources :

Example 1 with LispAddressSerializerContext

use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.

the class InstanceIdSerializerTest method deserialize__Simple.

@Test
public void deserialize__Simple() throws Exception {
    Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(// 
    "40 03 00 00 " + // 
    "02 20 00 0A " + // instance ID
    "00 BB CC DD " + // AFI=1, IP=0x11223344
    "00 01 11 22 33 44"), new LispAddressSerializerContext(null));
    assertEquals(Ipv4BinaryAfi.class, address.getAddressType());
    Ipv4Binary ipv4 = (Ipv4Binary) address.getAddress();
    assertArrayEquals(new byte[] { 0x11, 0x22, 0x33, 0x44 }, ipv4.getIpv4Binary().getValue());
    assertEquals(0x00BBCCDD, address.getVirtualNetworkId().getValue().longValue());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) Ipv4Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary) Test(org.junit.Test)

Example 2 with LispAddressSerializerContext

use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.

the class SourceDestKeySerializerTest method deserialize__Simple.

@Test
public void deserialize__Simple() throws Exception {
    Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(// 
    "40 03 00 00 " + // 
    "0C 20 00 10 " + // reserved + masks
    "00 00 10 18 " + // AFI=1, IP=0x11223344
    "00 01 11 22 33 44 " + // AFI=1, IP=0x22334455
    "00 01 22 33 44 55"), new LispAddressSerializerContext(null));
    assertEquals(SourceDestKeyLcaf.class, address.getAddressType());
    SourceDestKey srcDestAddress = (SourceDestKey) address.getAddress();
    assertEquals((byte) 0x10, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getSource()));
    assertEquals((byte) 0x18, MaskUtil.getMaskForAddress(srcDestAddress.getSourceDestKey().getDest()));
    assertEquals("17.34.51.68/16", String.valueOf(srcDestAddress.getSourceDestKey().getSource().getValue()));
    assertEquals("34.51.68.85/24", String.valueOf(srcDestAddress.getSourceDestKey().getDest().getValue()));
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) SourceDestKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) Test(org.junit.Test)

Example 3 with LispAddressSerializerContext

use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.

the class MapRequestSerializer method deserialize.

@SuppressWarnings("checkstyle:IllegalCatch")
public MapRequest deserialize(ByteBuffer requestBuffer, InetAddress sourceRloc) {
    try {
        final byte typeAndFlags = requestBuffer.get();
        final int type = typeAndFlags >> 4;
        if (MessageType.forValue(type) != MessageType.MapRequest) {
            throw new LispSerializationException("Expected Map-Request packet (type 1), but was type " + type);
        }
        MapRequestBuilder builder = new MapRequestBuilder();
        builder.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
        builder.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
        builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
        builder.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
        final byte moreFlags = requestBuffer.get();
        builder.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
        builder.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
        final int itrCount = ByteUtil.getUnsignedByte(requestBuffer) + 1;
        final int recordCount = ByteUtil.getUnsignedByte(requestBuffer);
        builder.setNonce(requestBuffer.getLong());
        LispAddressSerializerContext ctx = new LispAddressSerializerContext(LispAddressSerializerContext.MASK_LEN_MISSING);
        builder.setSourceEid(new SourceEidBuilder().setEid(LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx)).build());
        if (builder.getItrRloc() == null) {
            builder.setItrRloc(new ArrayList<ItrRloc>());
        }
        for (int i = 0; i < itrCount; i++) {
            builder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressSerializer.getInstance().deserializeRloc(requestBuffer)).build());
        }
        if (builder.getEidItem() == null) {
            builder.setEidItem(new ArrayList<EidItem>());
        }
        for (int i = 0; i < recordCount; i++) {
            builder.getEidItem().add(new EidItemBuilder().setEid(EidRecordSerializer.getInstance().deserialize(requestBuffer)).build());
        }
        if (builder.isMapDataPresent() && requestBuffer.hasRemaining()) {
            try {
                builder.setMapReply(new org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.MapReplyBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(requestBuffer)).build()).build();
            } catch (RuntimeException re) {
                LOG.warn("Couldn't deserialize Map-Reply encapsulated in Map-Request", re);
            }
        }
        builder.setSourceRloc(LispAddressUtil.addressBinaryFromInet(sourceRloc));
        return builder.build();
    } catch (RuntimeException re) {
        throw new LispSerializationException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
    }
}
Also used : LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) EidItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder) EidItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) SourceEidBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)

Example 4 with LispAddressSerializerContext

use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.

the class MappingRecordSerializer method deserializeToBuilder.

public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
    MappingRecordBuilder builder = new MappingRecordBuilder();
    builder.setRecordTtl(buffer.getInt());
    final byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
    final short maskLength = ((short) ByteUtil.getUnsignedByte(buffer));
    final byte actionAndAuthoritative = buffer.get();
    Action act = Action.forValue(actionAndAuthoritative >> 5);
    if (act == null) {
        act = Action.NoAction;
    }
    builder.setAction(act);
    builder.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
    buffer.position(buffer.position() + Length.RESERVED);
    builder.setMapVersion(buffer.getShort());
    LispAddressSerializerContext ctx = new LispAddressSerializerContext(maskLength);
    builder.setEid(LispAddressSerializer.getInstance().deserializeEid(buffer, ctx));
    builder.setLocatorRecord(new ArrayList<LocatorRecord>());
    for (int i = 0; i < locatorCount; i++) {
        builder.getLocatorRecord().add(LocatorRecordSerializer.getInstance().deserialize(buffer));
    }
    return builder;
}
Also used : LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)

Example 5 with LispAddressSerializerContext

use of org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext in project lispflowmapping by opendaylight.

the class InstanceIdSerializerTest method deserialize__Ipv6.

@Test
public void deserialize__Ipv6() throws Exception {
    Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer(// 
    "40 03 00 00 " + // 
    "02 20 00 0A " + // instance ID
    "00 BB CC DD " + // AFI=2,
    "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), new LispAddressSerializerContext(null));
    // IPv6
    assertArrayEquals(new byte[] { (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66, (byte) 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD }, ((Ipv6Binary) address.getAddress()).getIpv6Binary().getValue());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) LispAddressSerializerContext(org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext) Ipv6Binary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary) Test(org.junit.Test)

Aggregations

LispAddressSerializerContext (org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext)8 Test (org.junit.Test)5 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)5 SourceDestKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey)2 LispSerializationException (org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)1 ServicePath (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath)1 Ipv4Binary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv4Binary)1 Ipv6Binary (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.binary.address.types.rev160504.augmented.lisp.address.address.Ipv6Binary)1 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)1 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)1 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord.Action)1 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)1 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)1 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)1 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)1 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)1