/*
- * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.lispflowmapping.implementation.lisp;
import static org.junit.Assert.assertEquals;
-import java.util.HashMap;
-import java.util.Map;
-
-import junitx.framework.ArrayAssert;
-
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
-import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
-import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
-import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceKeyUtil;
-import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
-import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
-import org.opendaylight.lispflowmapping.type.lisp.address.IMaskable;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispMACAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-
-public class MapServerTest extends BaseTestCase {
-
- private MapServer testedMapServer;
- private ILispDAO lispDAO;
- private MapRegister mapRegister;
- private LispIpv4Address eid;
- private LispIpv4Address rloc;
- private ValueSaverAction<MappingEntry<?>[]> mappingEntriesSaver;
- private MapRegister mapRegisterWithAuthentication;
-
- @Override
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.lispflowmapping.implementation.config.ConfigIni;
+import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
+import org.opendaylight.lispflowmapping.interfaces.dao.SubscriberRLOC;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler;
+import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
+import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.lisp.util.SourceDestKeyHelper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregistermessage.MapRegisterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MapServerTest {
+
+ @Mock private static IMappingService mapService;
+ @Mock private static IMapNotifyHandler notifyHandler;
+ @Mock private static NotificationService notificationService;
+ @Spy private static Set<SubscriberRLOC> subscriberSetMock_1 = new HashSet<>();
+ @Spy private static Set<SubscriberRLOC> subscriberSetMock_2 = new HashSet<>();
+ @Spy private static Set<SubscriberRLOC> subscriberSetMock_3 = new HashSet<>();
+ private static MapServer mapServer;
+ private static MapRegister mapRegister;
+
+ private static final String IPV4_STRING_1 = "1.2.3.0";
+ private static final String IPV4_STRING_2 = "1.2.4.0";
+ private static final String IPV4_STRING_3 = "192.168.0.1";
+ private static final String IPV4_STRING_4 = "192.168.0.2";
+ private static final String IPV4_STRING_5 = "192.168.0.3";
+ private static final String IPV4_STRING_6 = "192.168.0.4";
+ private static final String IPV4_SOURCE_STRING_1 = "127.0.0.1";
+ private static final String IPV4_SOURCE_STRING_2 = "127.0.0.2";
+ private static final String IPV4_SOURCE_STRING_3 = "127.0.0.3";
+ private static final String IPV4_SOURCE_STRING_4 = "127.0.0.4";
+ private static final String IPV4_SOURCE_STRING_5 = "127.0.0.5";
+ private static final String IPV4_SOURCE_STRING_6 = "127.0.0.6";
+ private static final String IPV4_PREFIX = "/24";
+ private static final int MASK = 24;
+ private static final int VNI = 10;
+
+ private static final Eid IPV4_EID_1 = LispAddressUtil.asIpv4PrefixEid(IPV4_STRING_1 + IPV4_PREFIX);
+ private static final Eid IPV4_EID_2 = LispAddressUtil.asIpv4PrefixEid(IPV4_STRING_2 + IPV4_PREFIX);
+ private static final Eid IPV4_SOURCE_EID_1 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_1);
+ private static final Eid IPV4_SOURCE_EID_2 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_2);
+ private static final Eid IPV4_SOURCE_EID_3 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_3);
+ private static final Eid IPV4_SOURCE_EID_4 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_4);
+ private static final Eid IPV4_SOURCE_EID_5 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_5);
+ private static final Eid IPV4_SOURCE_EID_6 = LispAddressUtil.asIpv4Eid(IPV4_SOURCE_STRING_6);
+ private static final Rloc RLOC_1 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_1);
+ private static final Rloc RLOC_2 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_2);
+ private static final Rloc RLOC_3 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_3);
+ private static final Rloc RLOC_4 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_4);
+ private static final Rloc RLOC_5 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_5);
+ private static final Rloc RLOC_6 = LispAddressUtil.asIpv4Rloc(IPV4_STRING_6);
+
+ private static final IpAddressBinary IPV4_BINARY_1 =
+ new IpAddressBinary(new Ipv4AddressBinary(new byte[] {1, 2, 3, 0}));
+ private static final IpAddressBinary IPV4_BINARY_2 =
+ new IpAddressBinary(new Ipv4AddressBinary(new byte[] {1, 2, 4, 0}));
+
+ private static final long TWO_DAYS = 86400000L * 2;
+
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_1 = new SubscriberRLOC(RLOC_1, // timedOut() == true
+ IPV4_SOURCE_EID_1, new Date(System.currentTimeMillis() - TWO_DAYS));
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_2 = new SubscriberRLOC(RLOC_2, // timedOut() == false
+ IPV4_SOURCE_EID_2);
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_3 = new SubscriberRLOC(RLOC_3, // timedOut() == true
+ IPV4_SOURCE_EID_3, new Date(System.currentTimeMillis() - TWO_DAYS));
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_4 = new SubscriberRLOC(RLOC_4, // timedOut() == false
+ IPV4_SOURCE_EID_4);
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_5 = new SubscriberRLOC(RLOC_5, // timedOut() == true
+ IPV4_SOURCE_EID_5, new Date(System.currentTimeMillis() - TWO_DAYS));
+ private static final SubscriberRLOC SUBSCRIBER_RLOC_6 = new SubscriberRLOC(RLOC_6, // timedOut() == false
+ IPV4_SOURCE_EID_6);
+
+ private static final Eid SOURCE_DEST_KEY_EID = LispAddressUtil
+ .asSrcDstEid(IPV4_STRING_1, IPV4_STRING_2, MASK, MASK, VNI);
+ private static final MappingAuthkey MAPPING_AUTHKEY = new MappingAuthkeyBuilder().setKeyType(0).build();
+ private static final ConfigIni CONFIG_INI = ConfigIni.getInstance();
+
+ private static final LocatorRecord LOCATOR_RECORD_1 = new LocatorRecordBuilder().setRloc(RLOC_1).build();
+ private static final LocatorRecord LOCATOR_RECORD_2 = new LocatorRecordBuilder().setRloc(RLOC_2).build();
+
+ private static final MappingRecord OLD_MAPPING_RECORD_1 = getDefaultMappingRecordBuilder()
+ .setLocatorRecord(Lists.newArrayList(LOCATOR_RECORD_1)).build();
+ private static final MappingRecord OLD_MAPPING_RECORD_2 = getDefaultMappingRecordBuilder()
+ .setLocatorRecord(Lists.newArrayList(LOCATOR_RECORD_2)).build();
+
+ private static final Set<IpAddressBinary> DEFAULT_IP_ADDRESS_SET = getDefaultIpAddressSet();
+
@Before
- public void before() throws Exception {
- super.before();
- lispDAO = context.mock(ILispDAO.class);
- testedMapServer = new MapServer(lispDAO);
- mapRegister = new MapRegister();
- eid = new LispIpv4Address("10.31.0.5");
- rloc = new LispIpv4Address(0xC0A8880A);
- EidToLocatorRecord record = new EidToLocatorRecord();
- record.setPrefix(eid).setMaskLength(32);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegisterWithAuthentication = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
- + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
- + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
- + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
- mappingEntriesSaver = new ValueSaverAction<MappingEntry<?>[]>();
+ public void init() throws NoSuchFieldException, IllegalAccessException {
+ mapServer = new MapServer(mapService, true, notifyHandler, notificationService);
+ subscriberSetMock_1.add(SUBSCRIBER_RLOC_1);
+ subscriberSetMock_1.add(SUBSCRIBER_RLOC_2);
+ subscriberSetMock_2.add(SUBSCRIBER_RLOC_3);
+ subscriberSetMock_2.add(SUBSCRIBER_RLOC_4);
+ subscriberSetMock_3.add(SUBSCRIBER_RLOC_5);
+ subscriberSetMock_3.add(SUBSCRIBER_RLOC_6);
+ mapRegister = getDefaultMapRegisterBuilder().build();
+ setConfigIniMappingMergeField(false);
}
@Test
- public void handleMapRegister__NonSetMBit() throws Exception {
- mapRegister.setWantMapNotify(false);
+ public void handleMapRegisterTest_MappingMergeFalse() throws NoSuchFieldException, IllegalAccessException {
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_RECORD_1);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS))
+ .thenReturn(subscriberSetMock_1);
- addDefaultPutAndGetExpectations(eid, 32);
- assertNull(testedMapServer.handleMapRegister(mapRegister));
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(mapService).addMapping(MappingOrigin.Southbound, IPV4_EID_1, mapRegister.getSiteId(),
+ mapRegister.getMappingRecordItem().iterator().next().getMappingRecord(), false);
+ Mockito.verify(mapService).addData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS,
+ subscriberSetMock_1);
+ Mockito.verify(notifyHandler).handleMapNotify(getDefaultMapNotifyBuilder(mapRegister)
+ .setAuthenticationData(null).build(), null);
- MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
- assertEquals(1, entries.length);
-
- assertEquals("value", entries[0].getKey());
- assertEquals(rloc, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord().getLocator());
+ // only 1 subscriber has timed out.
+ assertEquals(1, subscriberSetMock_1.size());
}
@Test
- public void handleMapRegisterIpv4__ValidNotifyEchoesRegister() throws Exception {
- mapRegister.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispNoAddress()));
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(eid, 32);
- addDefaultPutAndGetExpectations(new LispNoAddress(), 32);
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ public void handleMapRegisterTest_MappingMergeTrue() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- @Test
- public void handleMapRegisterIpv4__CloneNotOwnYouClown() throws Exception {
- mapRegister = new MapRegister();
- mapRegister.setKeyId((byte) 0);
- mapRegister.setWantMapNotify(true);
- EidToLocatorRecord eidToLocator = new EidToLocatorRecord();
- eidToLocator.setMaskLength(32);
- eid = new LispIpv4Address(1);
- eidToLocator.setPrefix(eid);
+ final MappingRecordItemBuilder mappingRecordItemBuilder = new MappingRecordItemBuilder()
+ .setMappingRecord(OLD_MAPPING_RECORD_1);
+ final MapNotifyBuilder mapNotifyBuilder = getDefaultMapNotifyBuilder(mapRegister)
+ .setMappingRecordItem(new ArrayList<>());
+ mapNotifyBuilder.getMappingRecordItem().add(mappingRecordItemBuilder.build());
- LocatorRecord locator = new LocatorRecord();
- locator.setLocator(new LispIpv4Address(2));
- locator.setPriority((byte) 55);
- eidToLocator.addLocator(locator);
-
- mapRegister.addEidToLocator(eidToLocator);
-
- addDefaultPutAndGetExpectations(eid, 32);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
-
- mapRegister.getEidToLocatorRecords().get(0).setPrefix(new LispIpv4Address(55));
- mapRegister.getEidToLocatorRecords().get(0).getLocators().get(0).setPriority((byte) 1);
-
- EidToLocatorRecord actualEidToLocator = mapNotify.getEidToLocatorRecords().get(0);
- assertEquals(new LispIpv4Address(1), actualEidToLocator.getPrefix());
- assertEquals((byte) 55, actualEidToLocator.getLocators().get(0).getPriority());
+ // no mapping changes
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(OLD_MAPPING_RECORD_1);
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(mapService).addMapping(MappingOrigin.Southbound, IPV4_EID_1, mapRegister.getSiteId(),
+ mapRegister.getMappingRecordItem().iterator().next().getMappingRecord(), true);
+ Mockito.verify(notifyHandler).handleMapNotify(mapNotifyBuilder.setAuthenticationData(null).build(), null);
}
@Test
- public void handleMapRegisterIpv4__ValidMask() throws Exception {
- int mask = 16;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- record.setPrefix(eid).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(eid, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv4Address("10.31.0.0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
+ public void handleMapRegisterTest_verifyTransportAddresses() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
+
+ // input
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(OLD_MAPPING_RECORD_1)
+ .thenReturn(OLD_MAPPING_RECORD_2)
+ .thenReturn(getDefaultMappingRecordBuilder().build());
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS))
+ .thenReturn(subscriberSetMock_1);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
+
+ // result
+ final List<TransportAddress> transportAddressList = getTransportAddressList();
+ final MapNotifyBuilder mapNotifyBuilder = getDefaultMapNotifyBuilder(mapRegister);
+ mapNotifyBuilder.setMappingRecordItem(new ArrayList<>());
+ mapNotifyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder()
+ .setMappingRecord(getDefaultMappingRecordBuilder().build()).build());
+
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(mapNotifyBuilder.build(), transportAddressList);
}
@Test
- public void handleMapRegister__NonMaskable() throws Exception {
- int mask = 16;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispMACAddress addr = new LispMACAddress(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 });
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(addr, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
-
- private void addDefaultPutAndGetExpectations(LispAddress addr, int mask) {
- addPutExpectations(addr, mask);
- addGetExpectations(addr, mask);
+ 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))
+ // ensure mappings are different
+ .thenReturn(OLD_MAPPING_RECORD_1)
+ .thenReturn(OLD_MAPPING_RECORD_2)
+ .thenReturn(OLD_MAPPING_RECORD_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))
+ // ensure mappings are different
+ .thenReturn(OLD_MAPPING_RECORD_1)
+ .thenReturn(OLD_MAPPING_RECORD_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));
+ Mockito.verify(mapService).addData(MappingOrigin.Southbound, SOURCE_DEST_KEY_EID, SubKeys.SUBSCRIBERS,
+ subscriberSetMock_1);
+ 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));
+ Mockito.verify(mapService).addData(MappingOrigin.Southbound,
+ SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID),
+ SubKeys.SUBSCRIBERS, subscriberSetMock_2);
+ 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(1)).handleSMR(captor_3.capture(), Mockito.eq(RLOC_6));
+ Mockito.verify(mapService).addData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS,
+ subscriberSetMock_3);
+ final Eid resultEid_3 = captor_3.getValue().getEidItem().iterator().next().getEid();
+ assertEquals(IPV4_SOURCE_EID_6, resultEid_3);
}
@Test
- public void handleMapRegister__ZeroMask() throws Exception {
- int mask = 0;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispMACAddress addr = new LispMACAddress(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 });
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(addr, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withDifferentEid() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- @Test
- public void handleMapRegisterIPv4__ZeroMask() throws Exception {
- int mask = 0;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- record.setPrefix(eid).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(eid, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv4Address("0.0.0.0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder()
+ // apply the change
+ .setEid(IPV4_EID_2);
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- @Test
- public void handleMapRegisterIpv4__ValidMask32() throws Exception {
- int mask = 32;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- record.setPrefix(new LispIpv4Address("10.31.0.5")).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(eid, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv4Address("10.31.0.5"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
- @Test
- public void handleMapRegisterIpv6__ValidMask96() throws Exception {
- int mask = 96;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv6Address("1:1:1:1:1:1:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(mappingRecordBuilder_1.build())
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
- @Test
- public void handleMapRegisterIpv6__ZeroMask() throws Exception {
- int mask = 0;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv6Address("0:0:0:0:0:0:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
@Test
- public void handleMapRegisterIPV4AndIpv6__ValidMask96() throws Exception {
- int mask = 96;
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:0");
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(eid, 32);
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv6Address("1:1:1:1:1:1:0:0"), mapNotify.getEidToLocatorRecords().get(1).getPrefix());
- assertEquals(eid, mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withDifferentRLOC() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- @Test
- public void handleMapRegisterIpv6__ValidMask32() throws Exception {
- int mask = 48;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispIpv6Address addr = new LispIpv6Address("1:1:1:1:0:0:0:0");
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addDefaultPutAndGetExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv6Address("1:1:1:0:0:0:0:0"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mask, mapNotify.getEidToLocatorRecords().get(0).getMaskLength());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
- }
+ final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder();
+ // apply the change
+ mappingRecordBuilder_1.getLocatorRecord().add(new LocatorRecordBuilder().build());
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- @Test
- public void handleMapRegisterIpv6__ValidMask128() throws Exception {
- int mask = 128;
- mapRegister = new MapRegister();
- EidToLocatorRecord record = new EidToLocatorRecord();
- LispIpv6Address addr = new LispIpv6Address("1:1:1:1:1:1:1:2");
- record.setPrefix(addr).setMaskLength(mask);
- record.addLocator(new LocatorRecord().setLocator(rloc));
- mapRegister.addEidToLocator(record);
- mapRegister.setWantMapNotify(true);
-
- addPutExpectations(addr, mask);
-
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- assertEquals(new LispIpv6Address("1:1:1:1:1:1:1:2"), mapNotify.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(mapRegister.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
- assertEquals(mapRegister.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegister.getNonce(), mapNotify.getNonce());
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
+
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(mappingRecordBuilder_1.build())
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
+
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
@Test
- public void handleMapRegister__MultipleRLOCs() throws Exception {
- addDefaultPutAndGetExpectations(eid, 32);
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withDifferentAction() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- LispIpv4Address rloc0 = rloc;
- LispIpv6Address rloc1 = new LispIpv6Address("::7");
- mapRegister.getEidToLocatorRecords().get(0).addLocator(new LocatorRecord().setLocator(rloc1));
+ final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder()
+ // apply the change
+ .setAction(MappingRecord.Action.NativelyForward);
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- testedMapServer.handleMapRegister(mapRegister);
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
- MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
- assertEquals(1, entries.length);
-
- assertEquals("value", entries[0].getKey());
- assertEquals(rloc0, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord().getLocator());
- assertEquals(rloc1, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(1).getRecord().getLocator());
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(mappingRecordBuilder_1.build())
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
@Test
- public void handleMapRegister__MultipleEIDs() throws Exception {
- addDefaultPutAndGetExpectations(eid, 32);
-
- LispIpv4Address rloc0 = rloc;
- LispIpv6Address rloc1 = new LispIpv6Address("::7");
- mapRegister.getEidToLocatorRecords().get(0).addLocator(new LocatorRecord().setLocator(rloc1));
- mapRegister.setWantMapNotify(true);
-
- EidToLocatorRecord etlr = new EidToLocatorRecord();
- LispIpv4Address address = new LispIpv4Address("1.1.1.1");
- etlr.setPrefix(address);
- etlr.setMaskLength(32);
- int recordTtl = 5;
- etlr.setRecordTtl(recordTtl);
- etlr.addLocator(new LocatorRecord().setLocator(new LispIpv4Address("2.2.2.2")).setPriority((byte) 10));
- mapRegister.addEidToLocator(etlr);
- addPutExpectations(address, 32);
- addGetExpectations(address, 32);
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
-
- assertEquals(rloc0, mapNotify.getEidToLocatorRecords().get(0).getLocators().get(0).getLocator());
- assertEquals(rloc1, mapNotify.getEidToLocatorRecords().get(0).getLocators().get(1).getLocator());
- assertEquals(new LispIpv4Address("2.2.2.2"), mapNotify.getEidToLocatorRecords().get(1).getLocators().get(0).getLocator());
- assertEquals(recordTtl, mapNotify.getEidToLocatorRecords().get(1).getRecordTtl());
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withDifferentTTL() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- }
+ final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder()
+ // apply the change
+ .setRecordTtl(10);
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- @Test
- public void handleMapRegisterIpv4__ChekWrongPassword() throws Exception {
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
- addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 0, 31, "bla");
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
- assertEquals(null, mapNotify);
- }
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(mappingRecordBuilder_1.build())
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
- @Test
- public void handleMapRegisterIpv4__ChcekNoPasswordAndThenPassword() throws Exception {
-
- addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 25, "password");
- addPutExpectations(new LispIpv4Address("153.16.254.1"), 32);
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
- assertEquals(mapRegisterWithAuthentication.getEidToLocatorRecords(), mapNotify.getEidToLocatorRecords());
- assertEquals(mapRegisterWithAuthentication.getKeyId(), mapNotify.getKeyId());
- assertEquals(mapRegisterWithAuthentication.getNonce(), mapNotify.getNonce());
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
@Test
- public void handleMapRegisterIpv4__ChcekNoPassword() throws Exception {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withDifferentMapVersion() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 0, "password");
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
- assertEquals(null, mapNotify);
- }
+ final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder()
+ // apply the change
+ .setMapVersion((short) 10);
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- @Test
- public void handleMapRegisterIpv4__ChcekNoreturn() throws Exception {
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
- addGetExpectations(new LispIpv4Address("153.16.254.1"), 32);
- MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
- assertEquals(mapNotify, null);
- }
- @Test
- public void handleAddAuthenticationKey() throws Exception {
- IMappingServiceKey key = getDefualtKey();
- MappingServiceValue value = getDefualtValue();
- MappingEntry<MappingServiceValue> mappingEntry = new MappingEntry<MappingServiceValue>("value", value);
- oneOf(lispDAO).get(weq(key));
- oneOf(lispDAO).put(weq(key), weq(convertToArray(mappingEntry)));
- assertEquals(true, testedMapServer.addAuthenticationKey(eid, key.getMask(), value.getKey()));
- }
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(mappingRecordBuilder_1.build())
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
- @Test
- public void handleGetAuthenticationKey() throws Exception {
- IMappingServiceKey key = getDefualtKey();
- MappingServiceValue value = getDefualtValue();
- Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
- map.put("value", value);
- atLeast(1).of(lispDAO).get(weq(key));
- ret(map);
- assertEquals(value.getKey(), testedMapServer.getAuthenticationKey(eid, key.getMask()));
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
@Test
- public void handleGetAuthenticationKeyNoIteration() throws Exception {
- testedMapServer.setShouldIterateMask(false);
- IMappingServiceKey key = getDefualtKey();
- IMappingServiceKey passKey = getKey(30);
- MappingServiceValue value = getDefualtValue();
- Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
- map.put("value", value);
- oneOf(lispDAO).get(weq(key));
- allowing(lispDAO).get(weq(passKey));
- ret(map);
- assertEquals(null, testedMapServer.getAuthenticationKey(eid, key.getMask()));
- }
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void mappingChangedTest_withNullMap() throws NoSuchFieldException, IllegalAccessException {
+ setConfigIniMappingMergeField(true);
- @Test
- public void handleRemoveAuthenticationKey() throws Exception {
- IMappingServiceKey key = getDefualtKey();
- MappingServiceValue value = new MappingServiceValue();
- Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
- map.put("value", value);
- oneOf(lispDAO).get(weq(key));
- ret(map);
- oneOf(lispDAO).remove(weq(key));
- assertEquals(true, testedMapServer.removeAuthenticationKey(eid, key.getMask()));
- }
+ final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+ final ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
- @Test
- public void handleRemoveAuthenticationKeyWhereKeyDosntExist() throws Exception {
- IMappingServiceKey key = getDefualtKey();
- MappingServiceValue value = new MappingServiceValue();
- Map<String, MappingServiceValue> map = new HashMap<String, MappingServiceValue>();
- map.put("value", value);
- oneOf(lispDAO).get(weq(key));
- assertEquals(false, testedMapServer.removeAuthenticationKey(eid, key.getMask()));
+ Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
+ Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SRC_RLOCS))
+ .thenReturn(DEFAULT_IP_ADDRESS_SET);
+
+ Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
+ .thenReturn(null)
+ .thenReturn(mappingRecordBuilder_2.build())
+ .thenReturn(null);
+
+ mapServer.handleMapRegister(mapRegister);
+ Mockito.verify(notifyHandler).handleMapNotify(Mockito.any(MapNotify.class), captor.capture());
+ // verify that a list of transport addresses has 2 values - happens only if mappingUpdated == true
+ assertEquals(2, captor.getValue().size());
}
- @SuppressWarnings("rawtypes")
- private MappingEntry[] convertToArray(MappingEntry<MappingServiceValue> entry) {
- MappingEntry[] arr = new MappingEntry[1];
- arr[0] = entry;
- return arr;
+ private static MapRegisterBuilder getDefaultMapRegisterBuilder() {
+ final MapRegisterBuilder mapRegisterBuilder = new MapRegisterBuilder()
+ .setProxyMapReply(true)
+ .setWantMapNotify(true)
+ .setKeyId((short) 0)
+ .setMappingRecordItem(new ArrayList<>())
+ .setMergeEnabled(true)
+ .setNonce(1L)
+ .setSiteId(new SiteId(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}))
+ .setXtrId(new XtrId(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}))
+ .setXtrSiteIdPresent(true);
+ mapRegisterBuilder.getMappingRecordItem().add(getDefaultMappingRecordItemBuilder().build());
+
+ return mapRegisterBuilder;
}
- private void addGetExpectations(LispAddress address, int mask) {
- addGetExpectations(address, mask, 0, 0, "password");
+ private static MappingRecordItemBuilder getDefaultMappingRecordItemBuilder() {
+ return new MappingRecordItemBuilder()
+ .setMappingRecordItemId("mapping-record-item-id")
+ .setKey(new MappingRecordItemKey("mapping-record-item-key"))
+ .setMappingRecord(getDefaultMappingRecordBuilder().build());
}
- private void addPutExpectations(LispAddress address, int mask) {
- LispAddress clonedAddress = address;
- if (address instanceof IMaskable) {
- clonedAddress = (LispAddress) ((IMaskable) address).clone();
- }
- oneOf(lispDAO).put(weq(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) mask)), with(mappingEntriesSaver));
+ private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
+ return new MappingRecordBuilder()
+ .setAction(MappingRecord.Action.NoAction)
+ .setAuthoritative(false)
+ .setLocatorRecord(new ArrayList<>())
+ .setMapVersion((short) 0)
+ .setRecordTtl(60)
+ .setEid(IPV4_EID_1);
}
- private void addGetExpectations(LispAddress address, int mask, int withoutPassword, int withPassword, String password) {
- LispAddress clonedAddress = address;
- if (address instanceof IMaskable) {
- clonedAddress = (LispAddress) ((IMaskable) address).clone();
- }
-
- if (withoutPassword > 0) {
- Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
- result.put("value", new MappingServiceValue());
- allowing(lispDAO)
- .getSpecific(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) withoutPassword)), with("value"));
- ret(result);
- }
- if (address instanceof IMaskable) {
- clonedAddress = (LispAddress) ((IMaskable) address).clone();
- }
- if (withPassword > 0) {
- Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
- result.put("value", new MappingServiceValue());
- result.get("value").setKey(password);
- allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) withPassword)));
- ret(result);
- }
- for (int i = mask; i >= 0; i--) {
- if (address instanceof IMaskable) {
- clonedAddress = (LispAddress) ((IMaskable) address).clone();
- }
- allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(clonedAddress, (byte) i)));
- ret(new HashMap<String, MappingServiceValue>());
- }
+ private static MapNotifyBuilder getDefaultMapNotifyBuilder(MapRegister mapRegister) {
+ final MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder()
+ .setNonce(mapRegister.getNonce())
+ .setKeyId(mapRegister.getKeyId())
+ .setMergeEnabled(mapRegister.isMergeEnabled())
+ .setMappingRecordItem(new ArrayList<>())
+ .setAuthenticationData(new byte[]{});
+ mapNotifyBuilder.getMappingRecordItem().add(getDefaultMappingRecordItemBuilder().build());
+
+ return mapNotifyBuilder;
}
- private IMappingServiceKey getDefualtKey() {
- return getKey(32);
+ private static void setConfigIniMappingMergeField(boolean value) throws NoSuchFieldException,
+ IllegalAccessException {
+ final Field mappingMergeField = CONFIG_INI.getClass().getDeclaredField("mappingMerge");
+ mappingMergeField.setAccessible(true);
+ mappingMergeField.setBoolean(CONFIG_INI, value);
}
- private IMappingServiceKey getKey(int mask) {
- IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid, mask);
- return key;
+ private static Set<IpAddressBinary> getDefaultIpAddressSet() {
+ final Set<IpAddressBinary> addressSet = Sets.newHashSet(IPV4_BINARY_1, IPV4_BINARY_2);
+
+ return addressSet;
}
- private MappingServiceValue getDefualtValue() {
- MappingServiceValue value = new MappingServiceValue();
- String password = "pass";
- value.setKey(password);
- return value;
+ private static List<TransportAddress> getTransportAddressList() {
+ TransportAddressBuilder transportAddressBuilder_1 = new TransportAddressBuilder()
+ .setIpAddress(IPV4_BINARY_1)
+ .setPort(new PortNumber(LispMessage.PORT_NUM));
+
+ TransportAddressBuilder transportAddressBuilder_2 = new TransportAddressBuilder()
+ .setIpAddress(IPV4_BINARY_2)
+ .setPort(new PortNumber(LispMessage.PORT_NUM));
+
+ final List<TransportAddress> transportAddressList = Lists.newArrayList(
+ transportAddressBuilder_1.build(),
+ transportAddressBuilder_2.build());
+
+ return transportAddressList;
}
}