use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegisterBuilder in project lispflowmapping by opendaylight.
the class MapRegisterSerializationTest method serialize__Fields.
@Test
public void serialize__Fields() throws Exception {
MapRegisterBuilder mrBuilder = new MapRegisterBuilder();
mrBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
MappingRecordBuilder recordBuilder = new MappingRecordBuilder();
recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.1/32"));
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
recordBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("0.0.0.73/32"));
mrBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(recordBuilder.build()).build());
mrBuilder.setNonce(6161616161L);
mrBuilder.setKeyId((short) 0x0001);
mrBuilder.setWantMapNotify(true);
mrBuilder.setProxyMapReply(true);
mrBuilder.setXtrSiteIdPresent(true);
byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98, (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d, (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f, (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9, (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e, (byte) 0x8c, (byte) 0x41 };
mrBuilder.setAuthenticationData(authenticationData);
XtrId xtrId = new XtrId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 });
mrBuilder.setXtrId(xtrId);
SiteId siteId = new SiteId(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 });
mrBuilder.setSiteId(siteId);
ByteBuffer bb = MapRegisterSerializer.getInstance().serialize(mrBuilder.build());
// Type + MSByte of reserved
assertHexEquals((byte) 0x3a, bb.get());
// Rest of reserved + want map notify
assertEquals(1, bb.getShort());
// Record Count
assertEquals(2, bb.get());
// Nonce
assertEquals(6161616161L, bb.getLong());
// Key ID
assertHexEquals((short) 0x0001, bb.getShort());
assertEquals(authenticationData.length, bb.getShort());
byte[] actualAuthenticationData = new byte[20];
bb.get(actualAuthenticationData);
ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
// EID in first record
bb.position(bb.position() + 12);
assertEquals(0x1, bb.getInt());
// EID in second record
bb.position(bb.position() + 12);
assertEquals(73, bb.getInt());
byte[] actualXtrId = new byte[Length.XTRID_SIZE];
bb.get(actualXtrId);
ArrayAssert.assertEquals(xtrId.getValue(), actualXtrId);
byte[] actualSiteId = new byte[Length.SITEID_SIZE];
bb.get(actualSiteId);
ArrayAssert.assertEquals(siteId.getValue(), actualSiteId);
assertEquals(bb.position(), bb.capacity());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegisterBuilder 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.mapregistermessage.MapRegisterBuilder 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();
}
Aggregations