Search in sources :

Example 21 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingServiceTest method getMappingTest.

/**
 * Tests {@link MappingService#getMapping} method.
 */
@Test
public void getMappingTest() throws ExecutionException, InterruptedException {
    // input
    final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
    final MappingData mappingData = getDefaultMappingData();
    final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder().setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
    Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingData);
    final RpcResult<GetMappingOutput> rpc = RpcResultBuilder.success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
    // result
    final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
    final RpcResult<GetMappingOutput> rpcResult = result.get();
    assertEquals(rpc.getResult(), rpcResult.getResult());
    assertEquals(rpc.getErrors(), rpcResult.getErrors());
    assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
}
Also used : GetMappingInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInputBuilder) GetMappingInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingInput) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) GetMappingOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutputBuilder) GetMappingOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 22 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingDataListenerTest method onDataTreeChangedTest_subtreeModified_NB.

/**
 * Tests {@link MappingDataListener#onDataTreeChanged} method with SUBTREE_MODIFIED modification type from
 * northbound.
 */
@Test
@Ignore
@SuppressWarnings("unchecked")
public void onDataTreeChangedTest_subtreeModified_NB() throws InterruptedException {
    final List<DataTreeModification<Mapping>> changes = Lists.newArrayList(change_subtreeModified);
    final MappingChanged mapChanged = MSNotificationInputUtil.toMappingChanged(MAPPING_EID_2_NB.getMappingRecord(), null, null, null, MappingChange.Updated);
    Mockito.when(mod_subtreeModified.getDataAfter()).thenReturn(MAPPING_EID_2_NB);
    mappingDataListener.onDataTreeChanged(changes);
    final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
    Mockito.verify(iMappingSystemMock).addMapping(Mockito.eq(MappingOrigin.Northbound), Mockito.eq(IPV4_EID_2), captor.capture());
    assertEquals(captor.getValue().getRecord(), MAPPING_EID_2_NB.getMappingRecord());
    Mockito.verify(notificationPublishServiceMock).putNotification(mapChanged);
}
Also used : DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) MappingChanged(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChanged) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingDataListenerTest method onDataTreeChangedTest_write_NB.

/**
 * Tests {@link MappingDataListener#onDataTreeChanged} method with WRITE modification type from northbound.
 */
@Test
@Ignore
@SuppressWarnings("unchecked")
public void onDataTreeChangedTest_write_NB() throws InterruptedException {
    final List<DataTreeModification<Mapping>> changes = Lists.newArrayList(change_write);
    final MappingChanged mapChanged = MSNotificationInputUtil.toMappingChanged(MAPPING_EID_3_NB.getMappingRecord(), null, null, null, MappingChange.Created);
    Mockito.when(mod_write.getDataAfter()).thenReturn(MAPPING_EID_3_NB);
    mappingDataListener.onDataTreeChanged(changes);
    final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
    Mockito.verify(iMappingSystemMock).addMapping(Mockito.eq(MappingOrigin.Northbound), Mockito.eq(IPV4_EID_3), captor.capture());
    assertEquals(captor.getValue().getRecord(), MAPPING_EID_3_NB.getMappingRecord());
    Mockito.verify(notificationPublishServiceMock).putNotification(mapChanged);
}
Also used : DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) MappingChanged(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChanged) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class TimeBucketWheelUnitTest method mappingRefreshedProperlyTest.

/**
 * Tests {@link TimeBucketWheel#refreshMappping(Eid, MappingData, long, int)} method.
 * {@link ClassCastException} can be thrown.
 */
@Test
public void mappingRefreshedProperlyTest() {
    PowerMockito.mockStatic(System.class);
    long frozenTimeStamp = System.currentTimeMillis();
    PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
    TimeBucketWheel timeBucketWheel = getDefaultTimeBucketWheel();
    final int bucketId1 = timeBucketWheel.add(IPV4_EID_1, getDefaultMappingData(IPV4_EID_1), System.currentTimeMillis());
    frozenTimeStamp += 2000;
    PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
    MappingData newMappingData = getDefaultMappingData(IPV4_EID_1);
    int currentBucketId = timeBucketWheel.refreshMappping(IPV4_EID_1, newMappingData, System.currentTimeMillis(), bucketId1);
    List<TimeBucket> bucketList = extractBucketList(timeBucketWheel);
    TimeBucket pastTimeBucket = bucketList.get(bucketId1);
    MappingData oldStoredMappingData = getMappingDataFromTimeBucket(pastTimeBucket, IPV4_EID_1);
    Assert.assertNull(oldStoredMappingData);
    TimeBucket presentTimeBucket = bucketList.get(currentBucketId);
    MappingData newStoredMappingData = getMappingDataFromTimeBucket(presentTimeBucket, IPV4_EID_1);
    Assert.assertEquals(newMappingData, newStoredMappingData);
}
Also used : TimeBucketWheel(org.opendaylight.lispflowmapping.implementation.timebucket.containers.TimeBucketWheel) TimeBucket(org.opendaylight.lispflowmapping.implementation.timebucket.containers.TimeBucket) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class TimeBucketWheelUnitTest method checkOlderThanCurrentCase.

private void checkOlderThanCurrentCase(TimeBucketWheel timeBucketWheel) {
    long frozenTimeStamp = System.currentTimeMillis();
    int bucketId1 = timeBucketWheel.add(IPV4_EID_1, getDefaultMappingData(IPV4_EID_1), frozenTimeStamp);
    MappingData toBeExpiredMappingData = getDefaultMappingData(IPV4_EID_2);
    int bucketId2 = timeBucketWheel.add(IPV4_EID_2, toBeExpiredMappingData, frozenTimeStamp - 1000);
    Assert.assertEquals((bucketId1 + 1) % NUMBER_OF_BUCKETS, bucketId2);
    // expired at proper time
    frozenTimeStamp = frozenTimeStamp + 3000;
    PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
    timeBucketWheel.clearExpiredMappingAndRotate();
    Mockito.verify(mappingSystem).handleSbExpiredMapping(IPV4_EID_2, null, toBeExpiredMappingData);
}
Also used : MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Aggregations

MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)69 Test (org.junit.Test)40 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)14 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)11 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)9 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)9 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)7 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)7 ArrayList (java.util.ArrayList)5 Ignore (org.junit.Ignore)5 Date (java.util.Date)4 InstanceIdType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType)4 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)4 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)4 Mapping (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping)4 Set (java.util.Set)3 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)3 IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)3