SMR parent prefix
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / lisp / MapServerTest.java
index 32c2830b46f5e8164cd135e6d46b4434bbd0398a..b144329d6476083ea12e272d31a82a3846795379 100644 (file)
@@ -11,14 +11,12 @@ import static org.junit.Assert.assertEquals;
 
 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.junit.runner.RunWith;
@@ -27,15 +25,17 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.lispflowmapping.implementation.config.ConfigIni;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.lispflowmapping.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.type.MappingData;
 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.rev100924.PortNumber;
+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;
@@ -46,12 +46,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.lo
 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.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
 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.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.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;
@@ -59,11 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rl
 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.mappingservice.rev150906.mapping.authkey.container
-        .MappingAuthkey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container
-        .MappingAuthkeyBuilder;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 
 @RunWith(MockitoJUnitRunner.class)
 public class MapServerTest {
@@ -71,11 +66,13 @@ 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 MappingData mappingData;
 
     private static final String IPV4_STRING_1 =        "1.2.3.0";
     private static final String IPV4_STRING_2 =        "1.2.4.0";
@@ -89,12 +86,15 @@ public class MapServerTest {
     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 String IPV4_PREFIX_1 =        "/24";
+    private static final String IPV4_PREFIX_2 =        "/16";
     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_EID_1 = LispAddressUtil.asIpv4Eid(IPV4_STRING_1);
+    private static final Eid IPV4_EID_2 = LispAddressUtil.asIpv4Eid(IPV4_STRING_2);
+    private static final Eid IPV4_PREFIX_EID_1 = LispAddressUtil.asIpv4PrefixBinaryEid(IPV4_STRING_1 + IPV4_PREFIX_1);
+    private static final Eid IPV4_PREFIX_EID_2 = LispAddressUtil.asIpv4PrefixBinaryEid(IPV4_STRING_1 + IPV4_PREFIX_2);
     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);
@@ -116,17 +116,20 @@ public class MapServerTest {
     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));
+            IPV4_SOURCE_EID_1, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT,
+            new Date(System.currentTimeMillis() - TWO_DAYS));
     private static final SubscriberRLOC SUBSCRIBER_RLOC_2 = new SubscriberRLOC(RLOC_2,         // timedOut() == false
-            IPV4_SOURCE_EID_2);
+            IPV4_SOURCE_EID_2, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT);
     private static final SubscriberRLOC SUBSCRIBER_RLOC_3 = new SubscriberRLOC(RLOC_3,         // timedOut() == true
-            IPV4_SOURCE_EID_3, new Date(System.currentTimeMillis() - TWO_DAYS));
+            IPV4_SOURCE_EID_3, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT,
+            new Date(System.currentTimeMillis() - TWO_DAYS));
     private static final SubscriberRLOC SUBSCRIBER_RLOC_4 = new SubscriberRLOC(RLOC_4,         // timedOut() == false
-            IPV4_SOURCE_EID_4);
+            IPV4_SOURCE_EID_4, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT);
     private static final SubscriberRLOC SUBSCRIBER_RLOC_5 = new SubscriberRLOC(RLOC_5,         // timedOut() == true
-            IPV4_SOURCE_EID_5, new Date(System.currentTimeMillis() - TWO_DAYS));
+            IPV4_SOURCE_EID_5, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT,
+            new Date(System.currentTimeMillis() - TWO_DAYS));
     private static final SubscriberRLOC SUBSCRIBER_RLOC_6 = new SubscriberRLOC(RLOC_6,         // timedOut() == false
-            IPV4_SOURCE_EID_6);
+            IPV4_SOURCE_EID_6, SubscriberRLOC.DEFAULT_SUBSCRIBER_TIMEOUT);
 
     private static final Eid SOURCE_DEST_KEY_EID = LispAddressUtil
             .asSrcDstEid(IPV4_STRING_1, IPV4_STRING_2, MASK, MASK, VNI);
@@ -140,12 +143,14 @@ public class MapServerTest {
             .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 MappingData OLD_MAPPING_DATA_1 = new MappingData(OLD_MAPPING_RECORD_1);
+    private static final MappingData OLD_MAPPING_DATA_2 = new MappingData(OLD_MAPPING_RECORD_2);
 
     private static final Set<IpAddressBinary> DEFAULT_IP_ADDRESS_SET = getDefaultIpAddressSet();
 
     @Before
     public void init() throws NoSuchFieldException, IllegalAccessException  {
-        mapServer = new MapServer(mapService, true, true, notifyHandler, notificationService);
+        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);
@@ -153,22 +158,28 @@ public class MapServerTest {
         subscriberSetMock_3.add(SUBSCRIBER_RLOC_5);
         subscriberSetMock_3.add(SUBSCRIBER_RLOC_6);
         mapRegister = getDefaultMapRegisterBuilder().build();
+        mappingData = new MappingData(mapRegister.getMappingRecordItem().iterator().next().getMappingRecord(),
+                System.currentTimeMillis());
         setConfigIniMappingMergeField(false);
     }
 
     @Test
     public void handleMapRegisterTest_MappingMergeFalse() throws NoSuchFieldException, IllegalAccessException {
-        Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
-        Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_RECORD_1);
+        Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1)).thenReturn(OLD_MAPPING_DATA_1);
         Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS))
                 .thenReturn(subscriberSetMock_1);
 
+        mappingData.setMergeEnabled(false);
         mapServer.handleMapRegister(mapRegister);
-        Mockito.verify(mapService).addMapping(MappingOrigin.Southbound, IPV4_EID_1, mapRegister.getSiteId(),
-                mapRegister.getMappingRecordItem().iterator().next().getMappingRecord(), false);
+
+        final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
+        Mockito.verify(mapService).addMapping(Mockito.eq(MappingOrigin.Southbound), Mockito.eq(IPV4_EID_1),
+                Mockito.eq(mapRegister.getSiteId()), captor.capture());
+        assertEquals(captor.getValue().getRecord(), mappingData.getRecord());
         Mockito.verify(mapService).addData(MappingOrigin.Southbound, IPV4_EID_1, SubKeys.SUBSCRIBERS,
                 subscriberSetMock_1);
-        Mockito.verify(notifyHandler).handleMapNotify(getDefaultMapNotifyBuilder(mapRegister).build(), null);
+        Mockito.verify(notifyHandler).handleMapNotify(getDefaultMapNotifyBuilder(mapRegister)
+                .setAuthenticationData(null).build(), null);
 
         // only 1 subscriber has timed out.
         assertEquals(1, subscriberSetMock_1.size());
@@ -184,15 +195,55 @@ public class MapServerTest {
                 .setMappingRecordItem(new ArrayList<>());
         mapNotifyBuilder.getMappingRecordItem().add(mappingRecordItemBuilder.build());
 
-        Mockito.when(mapService.getAuthenticationKey(IPV4_EID_1)).thenReturn(MAPPING_AUTHKEY);
         // no mapping changes
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(OLD_MAPPING_RECORD_1);
+                .thenReturn(OLD_MAPPING_DATA_1);
+
+        mappingData.setMergeEnabled(true);
+        mapServer.handleMapRegister(mapRegister);
+
+        final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
+        Mockito.verify(mapService).addMapping(Mockito.eq(MappingOrigin.Southbound), Mockito.eq(IPV4_EID_1),
+                Mockito.eq(mapRegister.getSiteId()), captor.capture());
+        assertEquals(captor.getValue().getRecord(), mappingData.getRecord());
+        Mockito.verify(notifyHandler).handleMapNotify(mapNotifyBuilder.setAuthenticationData(null).build(), null);
+    }
+
+    @Test
+    public void handleMapRegisterTest_findNegativeSubscribers() throws NoSuchFieldException, IllegalAccessException {
+        setConfigIniMappingMergeField(true);
+
+        mapRegister.getMappingRecordItem().clear();
+        mapRegister.getMappingRecordItem().add(getDefaultMappingRecordItemBuilder(IPV4_PREFIX_EID_1).build());
+
+        final MappingRecordBuilder mappingRecordBuilder_1 = getDefaultMappingRecordBuilder()
+                // apply the change
+                .setEid(IPV4_PREFIX_EID_2);
+        final MappingRecordBuilder mappingRecordBuilder_2 = getDefaultMappingRecordBuilder();
+        final Eid maskedEid1 = LispAddressUtil.asIpv4Eid("1.2.0.0");
+
+        final SubscriberRLOC subscriber1 = Mockito.mock(SubscriberRLOC.class);
+        Mockito.when(subscriber1.timedOut()).thenReturn(true);
+        Mockito.when(subscriber1.toString()).thenReturn("sub1");
+
+        final Set<SubscriberRLOC> set1 = Sets.newHashSet(subscriber1);
+
+        Mockito.when(mapService.getAuthenticationKey(IPV4_PREFIX_EID_1)).thenReturn(MAPPING_AUTHKEY);
+        Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SRC_RLOCS))
+                .thenReturn(DEFAULT_IP_ADDRESS_SET);
+
+        Mockito.when(mapService.getParentPrefix(IPV4_PREFIX_EID_1)).thenReturn(maskedEid1);
+        Mockito.when(mapService.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS))
+                .thenReturn(null);
+        Mockito.when(mapService.getData(MappingOrigin.Southbound, maskedEid1, SubKeys.SUBSCRIBERS)).thenReturn(set1);
+
+        Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_PREFIX_EID_1))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
+                .thenReturn(null);
 
         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.build(), null);
+        Mockito.verify(subscriber1).timedOut();
     }
 
     @Test
@@ -202,9 +253,9 @@ public class MapServerTest {
         // 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());
+                .thenReturn(OLD_MAPPING_DATA_1)
+                .thenReturn(OLD_MAPPING_DATA_2)
+                .thenReturn(getDefaultMappingData(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))
@@ -239,15 +290,15 @@ public class MapServerTest {
         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);
+                .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.getDst(SOURCE_DEST_KEY_EID),
+        Mockito.when(mapService.getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID),
                 SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock_2);
 
         // ----------------- Stubbing for Ipv4 type Eid mapping ------------------------
@@ -255,8 +306,8 @@ public class MapServerTest {
         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);
+                .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);
@@ -277,7 +328,8 @@ public class MapServerTest {
         // 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.getDst(SOURCE_DEST_KEY_EID),
+        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);
@@ -307,8 +359,8 @@ public class MapServerTest {
                 .thenReturn(DEFAULT_IP_ADDRESS_SET);
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(mappingRecordBuilder_1.build())
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -333,8 +385,8 @@ public class MapServerTest {
                 .thenReturn(DEFAULT_IP_ADDRESS_SET);
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(mappingRecordBuilder_1.build())
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -359,8 +411,8 @@ public class MapServerTest {
                 .thenReturn(DEFAULT_IP_ADDRESS_SET);
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(mappingRecordBuilder_1.build())
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -385,8 +437,8 @@ public class MapServerTest {
                 .thenReturn(DEFAULT_IP_ADDRESS_SET);
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(mappingRecordBuilder_1.build())
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -412,8 +464,8 @@ public class MapServerTest {
 
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
-                .thenReturn(mappingRecordBuilder_1.build())
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_1.build()))
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -436,7 +488,7 @@ public class MapServerTest {
 
         Mockito.when(mapService.getMapping(MappingOrigin.Southbound, IPV4_EID_1))
                 .thenReturn(null)
-                .thenReturn(mappingRecordBuilder_2.build())
+                .thenReturn(getDefaultMappingData(mappingRecordBuilder_2.build()))
                 .thenReturn(null);
 
         mapServer.handleMapRegister(mapRegister);
@@ -461,25 +513,43 @@ public class MapServerTest {
         return mapRegisterBuilder;
     }
 
+    private static MappingData getDefaultMappingData(MappingRecord mappingRecord) {
+        if (mappingRecord == null) {
+            mappingRecord = getDefaultMappingRecordBuilder().build();
+        }
+        return new MappingData(mappingRecord, System.currentTimeMillis());
+    }
+
     private static MappingRecordItemBuilder getDefaultMappingRecordItemBuilder() {
+        return getDefaultMappingRecordItemBuilder(IPV4_EID_1);
+    }
+
+    private static MappingRecordItemBuilder getDefaultMappingRecordItemBuilder(Eid eid) {
         return new MappingRecordItemBuilder()
                 .setMappingRecordItemId("mapping-record-item-id")
                 .setKey(new MappingRecordItemKey("mapping-record-item-key"))
-                .setMappingRecord(getDefaultMappingRecordBuilder().build());
+                .setMappingRecord(getDefaultMappingRecordBuilder(eid).build());
     }
 
     private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
+        return getDefaultMappingRecordBuilder(IPV4_EID_1);
+    }
+
+    private static MappingRecordBuilder getDefaultMappingRecordBuilder(Eid eid) {
         return new MappingRecordBuilder()
                 .setAction(MappingRecord.Action.NoAction)
                 .setAuthoritative(false)
                 .setLocatorRecord(new ArrayList<>())
                 .setMapVersion((short) 0)
                 .setRecordTtl(60)
-                .setEid(IPV4_EID_1);
+                .setEid(eid);
     }
 
     private static MapNotifyBuilder getDefaultMapNotifyBuilder(MapRegister mapRegister) {
         final MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder()
+                .setXtrSiteIdPresent(mapRegister.isXtrSiteIdPresent())
+                .setSiteId(mapRegister.getSiteId())
+                .setXtrId(mapRegister.getXtrId())
                 .setNonce(mapRegister.getNonce())
                 .setKeyId(mapRegister.getKeyId())
                 .setMergeEnabled(mapRegister.isMergeEnabled())
@@ -504,17 +574,17 @@ public class MapServerTest {
     }
 
     private static List<TransportAddress> getTransportAddressList() {
-        TransportAddressBuilder transportAddressBuilder_1 = new TransportAddressBuilder()
+        TransportAddressBuilder transportAddressBuilder1 = new TransportAddressBuilder()
                 .setIpAddress(IPV4_BINARY_1)
                 .setPort(new PortNumber(LispMessage.PORT_NUM));
 
-        TransportAddressBuilder transportAddressBuilder_2 = new TransportAddressBuilder()
+        TransportAddressBuilder transportAddressBuilder2 = new TransportAddressBuilder()
                 .setIpAddress(IPV4_BINARY_2)
                 .setPort(new PortNumber(LispMessage.PORT_NUM));
 
         final List<TransportAddress> transportAddressList = Lists.newArrayList(
-                transportAddressBuilder_1.build(),
-                transportAddressBuilder_2.build());
+                transportAddressBuilder1.build(),
+                transportAddressBuilder2.build());
 
         return transportAddressList;
     }