Search in sources :

Example 16 with MapReplyBuilder

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

the class MapResolverTest method handleMapRequest_withBothPolicy.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest_withBothPolicy() {
    mapResolver = new MapResolver(mapServiceMock, true, "both", lispMappingServiceMock);
    final List<IpAddress> ipAddressList = new ArrayList<>();
    // hop 1
    ipAddressList.add(IPV4_ADDRESS_1);
    // hop 2
    ipAddressList.add(IPV4_ADDRESS_2);
    final Rloc rloc = LispAddressUtil.asTeLcafRloc(ipAddressList);
    final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
    final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder().setRloc(rloc);
    // input mapping
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    final MapRequestBuilder mrb = getDefaultMapRequestBuilder();
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_1)).build());
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).build());
    Mockito.when(mapServiceMock.getMapping(mrb.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    // result
    final LocatorRecordBuilder locatorRecordBuilder_3 = getDefaultLocatorBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).setPriority((short) 1);
    final MappingRecordBuilder resultMappingRecordBuilder = getDefaultMappingRecordBuilder();
    // as Ipv4
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    // as ELP
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
    // added to the result
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_3.build());
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(resultMappingRecordBuilder.build()).build());
    // invocation
    mapResolver.handleMapRequest(mrb.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) ArrayList(java.util.ArrayList) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) Test(org.junit.Test)

Example 17 with MapReplyBuilder

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

the class MapResolverTest method handleMapRequest__withSubscribers.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest__withSubscribers() {
    // input mapping
    final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
    Mockito.when(subscriberSetMock.contains(Mockito.any(Subscriber.class))).thenReturn(false);
    // result
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
    mapResolver.handleMapRequest(mapRequestBuilder.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
    Mockito.verify(subscriberSetMock, Mockito.never()).remove(Mockito.any(Subscriber.class));
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) Test(org.junit.Test)

Example 18 with MapReplyBuilder

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

the class MapResolverTest method handleMapRequest_withReplacePolicy.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest_withReplacePolicy() {
    mapResolver = new MapResolver(mapServiceMock, true, "replace", lispMappingServiceMock);
    final List<IpAddress> ipAddressList = new ArrayList<>();
    // hop 1
    ipAddressList.add(IPV4_ADDRESS_1);
    // hop 2
    ipAddressList.add(IPV4_ADDRESS_2);
    final Rloc rloc = LispAddressUtil.asTeLcafRloc(ipAddressList);
    final LocatorRecordBuilder locatorRecordBuilder_1 = getDefaultLocatorBuilder();
    final LocatorRecordBuilder locatorRecordBuilder_2 = getDefaultLocatorBuilder().setRloc(rloc);
    // input mapping
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_2.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    final MapRequestBuilder mrb = getDefaultMapRequestBuilder();
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_1)).build());
    mrb.getItrRloc().add(new ItrRlocBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2)).build());
    Mockito.when(mapServiceMock.getMapping(mrb.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    // result
    final LocatorRecordBuilder locatorRecordBuilder_3 = getDefaultLocatorBuilder().setRloc(LispAddressUtil.asIpv4Rloc(IPV4_STRING_2));
    final MappingRecordBuilder resultMappingRecordBuilder = getDefaultMappingRecordBuilder();
    // as Ipv4
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_1.build());
    // added to the result
    resultMappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder_3.build());
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(resultMappingRecordBuilder.build()).build());
    // invocation
    mapResolver.handleMapRequest(mrb.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) ItrRlocBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) ArrayList(java.util.ArrayList) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) MapRequestBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder) Test(org.junit.Test)

Example 19 with MapReplyBuilder

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

the class MapResolverTest method handleMapRequest__withSingleLocator.

/**
 * Tests {@link MapResolver#handleMapRequest} method.
 */
@Test
public void handleMapRequest__withSingleLocator() {
    // input mapping
    final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
    final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
    mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
    final MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
    Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
    // result
    final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
    mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
    mapResolver.handleMapRequest(mapRequestBuilder.build());
    Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) Test(org.junit.Test)

Example 20 with MapReplyBuilder

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

the class MapReplySerializer method deserialize.

public MapReply deserialize(ByteBuffer replyBuffer) {
    final byte typeAndFlags = replyBuffer.get();
    final int type = typeAndFlags >> 4;
    if (MessageType.forValue(type) != MessageType.MapReply) {
        throw new LispSerializationException("Expected Map-Reply packet (type 2), but was type " + type);
    }
    MapReplyBuilder builder = new MapReplyBuilder();
    builder.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
    builder.setEchoNonceEnabled(ByteUtil.extractBit(typeAndFlags, Flags.ECHO_NONCE_ENABLED));
    builder.setSecurityEnabled(ByteUtil.extractBit(typeAndFlags, Flags.SECURITY_ENABLED));
    replyBuffer.getShort();
    int recordCount = ByteUtil.getUnsignedByte(replyBuffer);
    builder.setNonce(replyBuffer.getLong());
    builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
    for (int i = 0; i < recordCount; i++) {
        builder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(MappingRecordSerializer.getInstance().deserialize(replyBuffer)).build());
    }
    return builder.build();
}
Also used : MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) LispSerializationException(org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException)

Aggregations

MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)19 Test (org.junit.Test)16 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)15 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)15 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)8 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)8 ByteBuffer (java.nio.ByteBuffer)7 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)7 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)4 GotMapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.GotMapReply)3 MapReply (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply)3 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)3 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)3 ItrRlocBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRlocBuilder)3 MapRequestBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder)3 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)3 ArrayList (java.util.ArrayList)2 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 EidItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)2