fixed northbound source dest mapping and auth TELSDN-644: #close
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / lisp / MapResolverTest.java
index 779dbd81714993f1754e8efd667ababcb6cf2898..9cfeacd2139b9e226ad0abf3d646ed14b981e030 100644 (file)
@@ -13,20 +13,27 @@ import org.jmock.api.Invocation;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.LispMappingService;
+import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil;
+import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
-import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceKeyUtil;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOC;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
-import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.MapReply;
-import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
-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.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecordBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequest.ItrRloc;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequest.SourceEidBuilder;
+import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.maprequestnotification.MapRequestBuilder;
 
 /*
  * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
@@ -38,12 +45,13 @@ import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
 
 public class MapResolverTest extends BaseTestCase {
 
-    private MapResolver testedMapResolver;
+    // private MapResolver testedMapResolver;
+    private LispMappingService testedMapResolver;
 
     private ILispDAO lispDAO;
-    private MapRequest mapRequest;
-    private LispIpv4Address v4Address;
-    private LispIpv6Address v6Address;
+    private MapRequestBuilder mapRequest;
+    private LispAFIAddress v4Address;
+    private LispAFIAddress v6Address;
 
     private HashMap<IMappingServiceKey, Map<String, MappingServiceValue>> daoResults;
 
@@ -52,257 +60,324 @@ public class MapResolverTest extends BaseTestCase {
     public void before() throws Exception {
         super.before();
         lispDAO = context.mock(ILispDAO.class);
-        testedMapResolver = new MapResolver(lispDAO);
+        testedMapResolver = new LispMappingService();
+        testedMapResolver.basicInit(lispDAO);
 
-        mapRequest = new MapRequest();
-        v4Address = new LispIpv4Address("1.2.3.4");
-        v6Address = new LispIpv6Address("0:0:0:0:0:0:0:1");
+        mapRequest = new MapRequestBuilder();
+        v4Address = LispAFIConvertor.asIPAfiAddress("1.2.3.4");
+        v6Address = LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1");
         daoResults = new HashMap<IMappingServiceKey, Map<String, MappingServiceValue>>();
     }
 
     @Test
-    @Ignore
-    public void handleMapRequest__NumRLOCsMismatch() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x44332211)));
-        // Map<String, Object> rlocs = prepareMapping(record);
-        // rlocs.put("NumRLOCs", 5);
-
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
-
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(1, eidToLocators.getLocators().size());
-        assertLocator(new LispIpv4Address(0x44332211), eidToLocators.getLocators().get(0));
+    public void handleMapRequest__ReplyWithSingleLocator() throws Exception {
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32)
+                        .setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.4"))).build());
+
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(v4Address));
+
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLocalLocator(false);
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        locator.setRouted(true);
+        locator.setMulticastPriority((short) 5);
+        locator.setWeight((short) 17);
+        locator.setPriority((short) 16);
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
+
+        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest.build());
+
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals(1, eidToLocators.getLocatorRecord().size());
+        LocatorRecord resultLocator = mapReply.getEidToLocatorRecord().get(0).getLocatorRecord().get(0);
+        assertEquals(locator.isLocalLocator(), resultLocator.isLocalLocator());
+        assertEquals(locator.isRouted(), resultLocator.isRouted());
+        assertEquals(locator.getMulticastPriority(), resultLocator.getMulticastPriority());
+        assertEquals(locator.getMulticastWeight(), resultLocator.getMulticastWeight());
+        assertEquals(locator.getPriority(), resultLocator.getPriority());
+        assertEquals(locator.getWeight(), resultLocator.getWeight());
+
+        assertLocator(LispAFIConvertor.asIPAfiAddress("4.3.2.1"), eidToLocators.getLocatorRecord().get(0));
     }
 
     @Test
-    @Ignore
-    public void handleMapRequest__BadRLOCType() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x71717171)));
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x44332211)));
-        // Map<String, Object> rlocs = prepareMapping(record);
-        // rlocs.put("RLOC0", "Ooga booga");
-
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
-
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(1, eidToLocators.getLocators().size());
-        assertLocator(new LispIpv4Address(0x44332211), eidToLocators.getLocators().get(0));
-    }
+    public void handleMapRequest__VerifyBasicFields() throws Exception {
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(v4Address)).build());
 
-    @Test
-    @Ignore
-    public void handleMapRequest__NoNumRLOCs() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
-        allowing(lispDAO).get(wany(IMappingServiceKey.class));
-        ret(new HashMap<String, Object>());
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(v4Address));
+        record.setRecordTtl(100);
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        record.setAuthoritative(true);
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
 
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(0, eidToLocators.getLocators().size());
-    }
+        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest.build());
 
-    @Test
-    @Ignore
-    public void handleMapRequest__IllegalNumRLOCs() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x44332211)));
-        // Map<String, Object> rlocs = prepareMapping(record);
-        // rlocs.put("NumRLOCs", "Bla");
-
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
-
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(0, eidToLocators.getLocators().size());
+        assertEquals(mapRequest.getNonce(), mapReply.getNonce());
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals((byte) 32, eidToLocators.getMaskLength().byteValue());
+        assertEquals(v4Address, LispAFIConvertor.toAFI(eidToLocators.getLispAddressContainer()));
+        assertEquals(record.isAuthoritative(), eidToLocators.isAuthoritative());
+        assertEquals(record.getAction(), eidToLocators.getAction());
+        assertEquals(record.getRecordTtl(), eidToLocators.getRecordTtl());
     }
 
     @Test
-    public void handleMapRequest__ReplyWithSingleLocator() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, new LispIpv4Address("1.2.3.4")));
+    public void handleMapRequest__VerifyMask() throws Exception {
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(v4Address)).build());
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.3.0")));
+        record.setMaskLength((short) 24);
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
 
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(1, eidToLocators.getLocators().size());
+        MapRequest mr = mapRequest.build();
 
-        assertLocator(new LispIpv4Address(0x04030201), eidToLocators.getLocators().get(0));
+        MapReply mapReply = testedMapResolver.handleMapRequest(mr);
+
+        assertEquals(mr.getNonce(), mapReply.getNonce());
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals((byte) 32, eidToLocators.getMaskLength().byteValue());
+        assertEquals(v4Address, LispAFIConvertor.toAFI(eidToLocators.getLispAddressContainer()));
     }
 
-    private Map<String, MappingServiceValue> prepareMapping(EidToLocatorRecord... records) {
-        if (records.length > 0) {
-            for (EidToLocatorRecord eidToLocatorRecord : records) {
-                MappingServiceValue value = new MappingServiceValue();
-                Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
-                result.put("value", value);
-                List<MappingServiceRLOC> rlocs = new ArrayList<MappingServiceRLOC>();
-                for (LocatorRecord locator : eidToLocatorRecord.getLocators()) {
-                    rlocs.add(new MappingServiceRLOC(locator, eidToLocatorRecord.getRecordTtl()));
-                }
-                value.setRlocs(rlocs);
+    @Test
+    public void handleMapRequest__VerifyMaskIPv6() throws Exception {
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 128).setLispAddressContainer(LispAFIConvertor.toContainer(v6Address)).build());
 
-                daoResults.put(
-                        MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getPrefix(), (byte) eidToLocatorRecord.getMaskLength()),
-                        result);
-            }
-        }
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:0")));
+        record.setMaskLength((short) 128);
 
-        ValueSaverAction<IMappingServiceKey> daoGetSaverAction = new ValueSaverAction<IMappingServiceKey>() {
-            @Override
-            protected boolean validate(IMappingServiceKey value) {
-                return true;
-            }
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
 
-            @Override
-            public Object invoke(Invocation invocation) throws Throwable {
-                return daoResults.get(lastValue);
-            }
-        };
+        MapRequest mr = mapRequest.build();
 
-        allowing(lispDAO).get(with(daoGetSaverAction));
-        will(daoGetSaverAction);
+        MapReply mapReply = testedMapResolver.handleMapRequest(mr);
 
-        return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(v4Address));
+        assertEquals(mr.getNonce(), mapReply.getNonce());
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals((byte) 128, eidToLocators.getMaskLength().byteValue());
+        assertEquals(v6Address, LispAFIConvertor.toAFI(eidToLocators.getLispAddressContainer()));
     }
 
     @Test
-    public void handleMapRequest__VerifyBasicFields() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
+    public void handleMapRequest__VerifyMaskIPv6NoMatch() throws Exception {
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 128).setLispAddressContainer(LispAFIConvertor.toContainer(v6Address)).build());
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("0:1:0:0:0:0:0:1")));
+        record.setMaskLength((short) 112);
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
 
-        assertEquals(mapRequest.getNonce(), mapReply.getNonce());
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals((byte) 0, eidToLocators.getMaskLength());
-        assertEquals(v4Address, eidToLocators.getPrefix());
+        MapRequest mr = mapRequest.build();
+
+        MapReply mapReply = testedMapResolver.handleMapRequest(mr);
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals(0, eidToLocators.getLocatorRecord().size());
     }
 
     @Test
-    public void handleMapRequest__VerifyMask() throws Exception {
-        EidRecord mapRequestRecord = new EidRecord((byte) 0, v4Address);
-        mapRequestRecord.setMaskLength(32);
-        mapRequest.addEidRecord(mapRequestRecord);
+    public void handleMapRequest__VerifyMaskNoMatch() throws Exception {
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(new LispIpv4Address("1.2.3.0")).setMaskLength(24);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(v4Address)).build());
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.2.4.0")));
+        record.setMaskLength((short) 24);
 
-        assertEquals(mapRequest.getNonce(), mapReply.getNonce());
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals((byte) 32, eidToLocators.getMaskLength());
-        assertEquals(v4Address, eidToLocators.getPrefix());
-    }
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        prepareMapping(record.build());
 
-    @Test
-    public void handleMapRequest__VerifyMaskIPv6() throws Exception {
-        EidRecord mapRequestRecord = new EidRecord((byte) 0, v6Address);
-        mapRequestRecord.setMaskLength(128);
-        mapRequest.addEidRecord(mapRequestRecord);
+        MapRequest mr = mapRequest.build();
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(new LispIpv6Address("0:0:0:0:0:0:0:0")).setMaskLength(128);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        MapReply mapReply = testedMapResolver.handleMapRequest(mr);
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals(0, eidToLocators.getLocatorRecord().size());
 
-        assertEquals(mapRequest.getNonce(), mapReply.getNonce());
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals((byte) 128, eidToLocators.getMaskLength());
-        assertEquals(v6Address, eidToLocators.getPrefix());
     }
 
     @Test
-    public void handleMapRequest__VerifyMaskIPv6NoMatch() throws Exception {
-        EidRecord mapRequestRecord = new EidRecord((byte) 128, v6Address);
-        mapRequest.addEidRecord(mapRequestRecord);
+    public void handleMapRequest__ReplyWithMultipleLocators() throws Exception {
+
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(v4Address)).build());
+
+        EidToLocatorRecordBuilder record = getDefaultEidToLocatorBuilder();
+        record.setLispAddressContainer(LispAFIConvertor.toContainer(v4Address));
+
+        LocatorRecordBuilder locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record.getLocatorRecord().add(locator.build());
+        locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1")));
+        record.getLocatorRecord().add(locator.build());
+        locator = getDefaultLocatorBuilder();
+        locator.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("1.8.2.7")));
+        record.getLocatorRecord().add(locator.build());
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(new LispIpv6Address("0:0:0:0:0:0:0:1")).setMaskLength(112);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        prepareMapping(record.build());
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest.build());
 
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(0, eidToLocators.getLocators().size());
+        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals(3, eidToLocators.getLocatorRecord().size());
+
+        assertLocator(LispAFIConvertor.asIPAfiAddress("4.3.2.1"), eidToLocators.getLocatorRecord().get(0));
+        assertLocator(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1"), eidToLocators.getLocatorRecord().get(1));
+        assertLocator(LispAFIConvertor.asIPAfiAddress("1.8.2.7"), eidToLocators.getLocatorRecord().get(2));
     }
 
     @Test
-    public void handleMapRequest__VerifyMaskNoMatch() throws Exception {
-        EidRecord mapRequestRecord = new EidRecord((byte) 0, v4Address);
-        mapRequestRecord.setMaskLength(32);
-        mapRequest.addEidRecord(mapRequestRecord);
+    public void handleMapRequest__MultipleEIDs() throws Exception {
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(new LispIpv4Address("1.2.4.0")).setMaskLength(24);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        prepareMapping(record);
+        mapRequest = getDefaultMapRequestBuilder();
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 32).setLispAddressContainer(LispAFIConvertor.toContainer(v4Address)).build());
+        mapRequest.getEidRecord().add(
+                new EidRecordBuilder().setMask((short) 128).setLispAddressContainer(LispAFIConvertor.toContainer(v6Address)).build());
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        EidToLocatorRecordBuilder record1 = getDefaultEidToLocatorBuilder();
+        record1.setLispAddressContainer(LispAFIConvertor.toContainer(v4Address));
+        record1.setRecordTtl(100);
 
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(0, eidToLocators.getLocators().size());
+        LocatorRecordBuilder locator1 = getDefaultLocatorBuilder();
+        locator1.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("4.3.2.1")));
+        record1.getLocatorRecord().add(locator1.build());
 
-    }
+        EidToLocatorRecordBuilder record2 = getDefaultEidToLocatorBuilder();
+        record2.setLispAddressContainer(LispAFIConvertor.toContainer(v6Address));
+        record2.setMaskLength((short) 128);
+        record2.setRecordTtl(100);
 
-    @Test
-    public void handleMapRequest__ReplyWithMultipleLocators() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
+        LocatorRecordBuilder locator2 = getDefaultLocatorBuilder();
+        locator2.setLispAddressContainer(LispAFIConvertor.toContainer(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1")));
+        record2.getLocatorRecord().add(locator2.build());
 
-        EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv6Address("::1")));
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address("1.8.2.7")));
-        prepareMapping(record);
+        prepareMapping(record1.build(), record2.build());
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest.build());
 
-        EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(3, eidToLocators.getLocators().size());
+        EidToLocatorRecord eidToLocators1 = mapReply.getEidToLocatorRecord().get(0);
+        assertEquals(1, eidToLocators1.getLocatorRecord().size());
+        assertLocator(LispAFIConvertor.asIPAfiAddress("4.3.2.1"), eidToLocators1.getLocatorRecord().get(0));
 
-        assertLocator(new LispIpv4Address(0x04030201), eidToLocators.getLocators().get(0));
-        assertLocator(new LispIpv6Address("::1"), eidToLocators.getLocators().get(1));
-        assertLocator(new LispIpv4Address("1.8.2.7"), eidToLocators.getLocators().get(2));
+        EidToLocatorRecord eidToLocators2 = mapReply.getEidToLocatorRecord().get(1);
+        assertEquals(1, eidToLocators2.getLocatorRecord().size());
+        assertLocator(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:1"), eidToLocators2.getLocatorRecord().get(0));
     }
 
-    private void assertLocator(LispAddress expectedAddress, LocatorRecord locatorRecord) {
-        assertEquals(expectedAddress, locatorRecord.getLocator());
+    private void assertLocator(LispAFIAddress expectedAddress, LocatorRecord locatorRecord) {
+        assertEquals(LispAFIConvertor.toContainer(expectedAddress), locatorRecord.getLispAddressContainer());
         Assert.assertTrue(locatorRecord.isRouted());
     }
 
-    @Test
-    public void handleMapRequest__MultipleEIDs() throws Exception {
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
-        mapRequest.addEidRecord(new EidRecord((byte) 0, v6Address));
+    private Map<String, MappingServiceValue> prepareMapping(EidToLocatorRecord... records) {
+        if (records.length > 0) {
+            for (EidToLocatorRecord eidToLocatorRecord : records) {
+                MappingServiceValue value = new MappingServiceValue();
+                Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
+                result.put("value", value);
+                List<MappingServiceRLOC> rlocs = new ArrayList<MappingServiceRLOC>();
+                for (LocatorRecord locator : eidToLocatorRecord.getLocatorRecord()) {
+                    rlocs.add(new MappingServiceRLOC(locator, eidToLocatorRecord.getRecordTtl(), eidToLocatorRecord.getAction(), eidToLocatorRecord
+                            .isAuthoritative()));
+                }
+                value.setRlocs(rlocs);
 
-        EidToLocatorRecord record1 = new EidToLocatorRecord().setPrefix(v4Address);
-        record1.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
+                daoResults.put(
+                        MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getLispAddressContainer(),
+                                (short) eidToLocatorRecord.getMaskLength()), result);
+            }
+        }
+
+        ValueSaverAction<IMappingServiceKey> daoGetSaverAction = new ValueSaverAction<IMappingServiceKey>() {
+            @Override
+            protected boolean validate(IMappingServiceKey value) {
+                return true;
+            }
+
+            @Override
+            public Object invoke(Invocation invocation) throws Throwable {
+                return daoResults.get(lastValue);
+            }
+        };
 
-        EidToLocatorRecord record2 = new EidToLocatorRecord().setPrefix(v6Address);
-        record2.addLocator(new LocatorRecord().setLocator(new LispIpv6Address("0:0:0:0:0:0:0:1")));
-        // prepareMapping(record2);
-        prepareMapping(record1, record2);
+        allowing(lispDAO).get(with(daoGetSaverAction));
+        will(daoGetSaverAction);
 
-        MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
+        return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(v4Address)));
+    }
 
-        EidToLocatorRecord eidToLocators1 = mapReply.getEidToLocatorRecords().get(0);
-        assertEquals(1, eidToLocators1.getLocators().size());
-        assertLocator(new LispIpv4Address(0x04030201), eidToLocators1.getLocators().get(0));
+    private MapRequestBuilder getDefaultMapRequestBuilder() {
+        MapRequestBuilder mrBuilder = new MapRequestBuilder();
+        mrBuilder.setAuthoritative(false);
+        mrBuilder.setEidRecord(new ArrayList<EidRecord>());
+        mrBuilder.setItrRloc(new ArrayList<ItrRloc>());
+        mrBuilder.setMapDataPresent(true);
+        mrBuilder.setNonce((long) 0);
+        mrBuilder.setPitr(false);
+        mrBuilder.setProbe(false);
+        mrBuilder.setSmr(false);
+        mrBuilder.setSmrInvoked(true);
+        mrBuilder.setSourceEid(new SourceEidBuilder().setLispAddressContainer(
+                LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("127.0.0.1"))).build());
+        return mrBuilder;
+    }
 
-        EidToLocatorRecord eidToLocators2 = mapReply.getEidToLocatorRecords().get(1);
-        assertEquals(1, eidToLocators2.getLocators().size());
-        assertLocator(new LispIpv6Address("0:0:0:0:0:0:0:1"), eidToLocators2.getLocators().get(0));
+    private EidToLocatorRecordBuilder getDefaultEidToLocatorBuilder() {
+        EidToLocatorRecordBuilder builder = new EidToLocatorRecordBuilder();
+        builder.setAction(Action.NoAction);
+        builder.setAuthoritative(false);
+        builder.setLocatorRecord(new ArrayList<LocatorRecord>());
+        builder.setMapVersion((short) 0);
+        builder.setMaskLength((short) 32);
+        builder.setRecordTtl(60);
+        return builder;
     }
+
+    private LocatorRecordBuilder getDefaultLocatorBuilder() {
+        LocatorRecordBuilder builder = new LocatorRecordBuilder();
+        builder.setLocalLocator(false);
+        builder.setMulticastPriority((short) 0);
+        builder.setMulticastWeight((short) 0);
+        builder.setPriority((short) 0);
+        builder.setRlocProbed(false);
+        builder.setRouted(true);
+        builder.setWeight((short) 0);
+        return builder;
+    }
+
 }