use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.
the class MapServerTest method handleMapRegisterTest_withTwoMappingRecords.
@Test
@Ignore
public void handleMapRegisterTest_withTwoMappingRecords() throws NoSuchFieldException, IllegalAccessException {
setConfigIniMappingMergeField(true);
// Input
// Add a MappingRecord with SrcDestKey Eid Type
final MappingRecordItemBuilder mappingRecordItemBuilder = new MappingRecordItemBuilder().setMappingRecord(getDefaultMappingRecordBuilder().setEid(SOURCE_DEST_KEY_EID).build());
final MapRegisterBuilder mapRegisterSrcDstBuilder = getDefaultMapRegisterBuilder();
final List<MappingRecordItem> list = mapRegisterSrcDstBuilder.getMappingRecordItem();
list.add(mappingRecordItemBuilder.build());
// ------------- Stubbing for SourceDestKey type Eid mapping -------------------
Mockito.when(mapService.getAuthenticationKey(SOURCE_DEST_KEY_EID)).thenReturn(MAPPING_AUTHKEY);
Mockito.when(mapService.getMapping(MappingOrigin.Southbound, SOURCE_DEST_KEY_EID)).thenReturn(OLD_MAPPING_DATA_1).thenReturn(OLD_MAPPING_DATA_2).thenReturn(OLD_MAPPING_DATA_2);
// return a subscriberSet for SrcDestKeyEid MappingRecord
Mockito.when(mapService.getData(MappingOrigin.Southbound, SOURCE_DEST_KEY_EID, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_1);
// return a subscriberSet for SrcDestKeyEid destination MappingRecord
Mockito.when(mapService.getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_2);
// ----------------- Stubbing for Ipv4 type Eid mapping ------------------------
Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_DATA_1).thenReturn(OLD_MAPPING_DATA_2);
// return a subscriberSet for Ipv4Eid MappingRecord
Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_3);
// -----------------------------------------------------------------------------
// result
mapServer.handleMapRegister(mapRegisterSrcDstBuilder.build());
// for SrcDstKey mapping
final ArgumentCaptor<MapRequest> captor_1 = ArgumentCaptor.forClass(MapRequest.class);
Mockito.verify(notifyHandler, Mockito.times(1)).handleSMR(captor_1.capture(), Mockito.eq(RLOC_2));
final Eid resultEid_1 = captor_1.getValue().getEidItem().iterator().next().getEid();
assertEquals(IPV4_SOURCE_EID_2, resultEid_1);
// for SrcDst destination mapping
final ArgumentCaptor<MapRequest> captor_2 = ArgumentCaptor.forClass(MapRequest.class);
Mockito.verify(notifyHandler, Mockito.times(1)).handleSMR(captor_2.capture(), Mockito.eq(RLOC_4));
final Eid resultEid_2 = captor_2.getValue().getEidItem().iterator().next().getEid();
assertEquals(IPV4_SOURCE_EID_4, resultEid_2);
// for Ipv4 mapping
final ArgumentCaptor<MapRequest> captor_3 = ArgumentCaptor.forClass(MapRequest.class);
Mockito.verify(notifyHandler, Mockito.times(2)).handleSMR(captor_3.capture(), Mockito.eq(RLOC_6));
final Eid resultEid_3 = captor_3.getValue().getEidItem().iterator().next().getEid();
assertEquals(IPV4_SOURCE_EID_6, resultEid_3);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.
the class LispNotificationHelperTest method getDefaultAddMapping.
private static AddMapping getDefaultAddMapping(boolean isXtrSiteIdPresent) {
final MappingRecordItem mappingRecordItem_1 = new MappingRecordItemBuilder().setMappingRecord(new MappingRecordBuilder().setEid(EID_IPV4).build()).build();
final MappingRecordItem mappingRecordItem_2 = new MappingRecordItemBuilder().setMappingRecord(new MappingRecordBuilder().setEid(EID_IPV6).build()).build();
final MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder().setMappingRecordItem(Lists.newArrayList(mappingRecordItem_1, mappingRecordItem_2)).setXtrSiteIdPresent(isXtrSiteIdPresent).setSiteId(SITE_ID);
return new AddMappingBuilder().setMapRegister(mapRegisterBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem in project lispflowmapping by opendaylight.
the class MapNotifySerializer method serialize.
public ByteBuffer serialize(MapNotify mapNotify) {
int size = Length.HEADER_SIZE;
if (mapNotify.getAuthenticationData() != null) {
size += mapNotify.getAuthenticationData().length;
}
if (mapNotify.isXtrSiteIdPresent() != null && mapNotify.isXtrSiteIdPresent()) {
size += org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.XTRID_SIZE + org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.Length.SITEID_SIZE;
}
for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
size += MappingRecordSerializer.getInstance().getSerializationSize(mappingRecord.getMappingRecord());
}
ByteBuffer replyBuffer = ByteBuffer.allocate(size);
replyBuffer.put((byte) ((byte) (MessageType.MapNotify.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapNotify.isXtrSiteIdPresent()), Flags.XTRSITEID)));
replyBuffer.position(replyBuffer.position() + Length.RES);
replyBuffer.put(ByteUtil.boolToBit(BooleanUtils.isTrue(mapNotify.isMergeEnabled()), Flags.MERGE_ENABLED));
if (mapNotify.getMappingRecordItem() != null) {
replyBuffer.put((byte) mapNotify.getMappingRecordItem().size());
} else {
replyBuffer.put((byte) 0);
}
replyBuffer.putLong(NumberUtil.asLong(mapNotify.getNonce()));
replyBuffer.putShort(NumberUtil.asShort(mapNotify.getKeyId()));
if (mapNotify.getAuthenticationData() != null) {
replyBuffer.putShort((short) mapNotify.getAuthenticationData().length);
replyBuffer.put(mapNotify.getAuthenticationData());
} else {
replyBuffer.putShort((short) 0);
}
if (mapNotify.getMappingRecordItem() != null) {
for (MappingRecordItem mappingRecord : mapNotify.getMappingRecordItem()) {
MappingRecordSerializer.getInstance().serialize(replyBuffer, mappingRecord.getMappingRecord());
}
}
if (mapNotify.isXtrSiteIdPresent() != null && mapNotify.isXtrSiteIdPresent()) {
replyBuffer.put(mapNotify.getXtrId().getValue());
replyBuffer.put(mapNotify.getSiteId().getValue());
}
replyBuffer.clear();
return replyBuffer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem 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();
}
Aggregations