Search in sources :

Example 1 with ItrRlocBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder in project lispflowmapping by opendaylight.

the class MapRequestUtilTest method selectItrRlocTest_Ipv6Binary.

/**
 * Tests {@link MapRequestUtil#selectItrRloc} method with Ipv6Binary.
 */
@Test
public void selectItrRlocTest_Ipv6Binary() {
    final ItrRlocBuilder itrRloc = new ItrRlocBuilder().setRloc(new RlocBuilder().setAddress(IPV6_ADDRESS_BINARY).build());
    final MapRequest request = new MapRequestBuilder().setItrRloc(Lists.newArrayList(itrRloc.build())).build();
    // expected result
    InetAddress expectedResult = InetAddresses.forString(IPV6_STRING);
    // result
    InetAddress result = MapRequestUtil.selectItrRloc(request);
    assertEquals(expectedResult, result);
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) RlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with ItrRlocBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder in project lispflowmapping by opendaylight.

the class MapRequestUtilTest method selectItrRlocTest_Ipv4.

/**
 * Tests {@link MapRequestUtil#selectItrRloc} method with Ipv4.
 */
@Test
public void selectItrRlocTest_Ipv4() {
    final ItrRlocBuilder itrRloc = new ItrRlocBuilder().setRloc(new RlocBuilder().setAddress(IPV4_ADDRESS).build());
    final MapRequest request = new MapRequestBuilder().setItrRloc(Lists.newArrayList(itrRloc.build())).build();
    // expected result
    InetAddress expectedResult = InetAddresses.forString(IPV4_STRING);
    // result
    InetAddress result = MapRequestUtil.selectItrRloc(request);
    assertEquals(expectedResult, result);
}
Also used : MapRequest(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) RlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 3 with ItrRlocBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder in project lispflowmapping by opendaylight.

the class MapRequestSerializationTest method serialize__MultipleItrRloc.

@Test
public void serialize__MultipleItrRloc() throws Exception {
    MapRequestBuilder mrBuilder = new MapRequestBuilder();
    mrBuilder.setItrRloc(new ArrayList<ItrRloc>());
    mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("1.2.3.4")).build());
    mrBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc("4.3.2.1")).build());
    ByteBuffer expected = hexToByteBuffer(// 
    "10 00 01 00 00 00 " + "00 00 00 00 00 00 00 00 00 01 01 02 03 04 00 01 04 03 02 01");
    assertArrayEquals(expected.array(), MapRequestSerializer.getInstance().serialize(mrBuilder.build()).array());
}
Also used : 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) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with ItrRlocBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder 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 5 with ItrRlocBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder in project lispflowmapping by opendaylight.

the class MappingServiceIntegrationTest method queryForAddress.

private MapReply queryForAddress(Eid eid, String srcEid) throws SocketTimeoutException {
    MapRequestBuilder mapRequestBuilder = new MapRequestBuilder();
    mapRequestBuilder.setNonce((long) 4);
    mapRequestBuilder.setEidItem(new ArrayList<EidItem>());
    mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(eid).build());
    mapRequestBuilder.setItrRloc(new ArrayList<ItrRloc>());
    if (srcEid != null) {
        mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(srcEid)).build());
    } else {
        mapRequestBuilder.setSourceEid(new SourceEidBuilder().setEid(LispAddressUtil.asIpv4Eid(ourAddress)).build());
    }
    mapRequestBuilder.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(ourAddress)).build());
    mapRequestBuilder.setAuthoritative(false);
    mapRequestBuilder.setMapDataPresent(false);
    mapRequestBuilder.setPitr(false);
    mapRequestBuilder.setProbe(false);
    mapRequestBuilder.setSmr(false);
    mapRequestBuilder.setSmrInvoked(false);
    sendMapRequest(mapRequestBuilder.build());
    return receiveMapReply();
}
Also used : 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) 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)

Aggregations

ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)19 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)13 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)12 Test (org.junit.Test)11 SourceEidBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.SourceEidBuilder)8 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)7 MapRequest (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest)6 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)6 RlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.RlocBuilder)6 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)5 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestmessage.MapRequestBuilder)5 InetAddress (java.net.InetAddress)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)4 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)3 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)2 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)2