store map register information and use it in the map reply TELSDN-67: #close 61/1961/3
authorDavid Goldberg <david.goldberg@contextream.com>
Tue, 15 Oct 2013 14:09:36 +0000 (16:09 +0200)
committerDavid Goldberg <david.goldberg@contextream.com>
Mon, 21 Oct 2013 08:35:32 +0000 (10:35 +0200)
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
Change-Id: I17c80d2e321d5b4300e0d320d9b0b56141c553ab
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingServiceRLOC.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolverTest.java

index 935a593c6615c56672c8dae720d64f1cbb1cd481..34badb529478e7db20755883deedfa45fe8a0584 100644 (file)
@@ -1,37 +1,66 @@
 package org.opendaylight.lispflowmapping.interfaces.dao;
 
 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
 
 public class MappingServiceRLOC {
-    
+
     private LocatorRecord record;
     private int ttl;
-    
-    public MappingServiceRLOC(LocatorRecord record, int ttl) {
+    private MapReplyAction action;
+    private boolean authoritative;
+
+    public MappingServiceRLOC(LocatorRecord record, int ttl, MapReplyAction action, boolean authoritative) {
         super();
         this.record = record;
         this.ttl = ttl;
+        this.action = action;
+        this.authoritative = authoritative;
     }
+
     public LocatorRecord getRecord() {
         return record;
     }
+
     public void setRecord(LocatorRecord record) {
         this.record = record;
     }
+
     public int getTtl() {
         return ttl;
     }
+
     public void setTtl(int ttl) {
         this.ttl = ttl;
     }
+
+    public MapReplyAction getAction() {
+        return action;
+    }
+
+    public void setAction(MapReplyAction action) {
+        this.action = action;
+    }
+
+    public boolean isAuthoritative() {
+        return authoritative;
+    }
+
+    public void setAuthoritative(boolean authoritative) {
+        this.authoritative = authoritative;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
+        result = prime * result + ((action == null) ? 0 : action.hashCode());
+        result = prime * result + (authoritative ? 1231 : 1237);
         result = prime * result + ((record == null) ? 0 : record.hashCode());
         result = prime * result + ttl;
         return result;
     }
+
     @Override
     public boolean equals(Object obj) {
         if (this == obj)
@@ -41,6 +70,10 @@ public class MappingServiceRLOC {
         if (getClass() != obj.getClass())
             return false;
         MappingServiceRLOC other = (MappingServiceRLOC) obj;
+        if (action != other.action)
+            return false;
+        if (authoritative != other.authoritative)
+            return false;
         if (record == null) {
             if (other.record != null)
                 return false;
@@ -50,7 +83,7 @@ public class MappingServiceRLOC {
             return false;
         return true;
     }
-    
+
     @Override
     public String toString() {
         return record.getLocator().toString();
index 02a8160956e96bd0341acd1b15502f0021afd0cb..884bba215e1f8fe44446f764e6d781f8cfd65157 100644 (file)
@@ -18,11 +18,9 @@ import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolver;
 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.IMaskable;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -101,8 +99,10 @@ public class MapResolver implements IMapResolver {
             return;
         }
         try {
-            LispAddress locator = locatorObject.getRecord().getLocator();
-            eidToLocators.addLocator(new LocatorRecord().setLocator(locator).setRouted(true));
+            eidToLocators.addLocator(locatorObject.getRecord().clone().setRouted(true));
+            eidToLocators.setAction(locatorObject.getAction());
+            eidToLocators.setAuthoritative(locatorObject.isAuthoritative());
+            eidToLocators.setRecordTtl(locatorObject.getTtl());
         } catch (ClassCastException cce) {
         }
     }
index b6a7c571a689f1ca92a2417126f807e78cb14d99..0eaef825a904261dbcbddeaab2ed3dec2a9426b4 100644 (file)
@@ -68,7 +68,7 @@ public class MapServer implements IMapServer {
             MappingEntry<MappingServiceValue> entry = new MappingEntry<MappingServiceValue>("value", value);
             List<MappingServiceRLOC> rlocs = new ArrayList<MappingServiceRLOC>();
             for (LocatorRecord locatorRecord : eidRecord.getLocators()) {
-                rlocs.add(new MappingServiceRLOC(locatorRecord, eidRecord.getRecordTtl()));
+                rlocs.add(new MappingServiceRLOC(locatorRecord, eidRecord.getRecordTtl(), eidRecord.getAction(), eidRecord.isAuthoritative()));
             }
             value.setRlocs(rlocs);
             IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eidRecord.getPrefix(), eidRecord.getMaskLength());
index 779dbd81714993f1754e8efd667ababcb6cf2898..2af2a8efd49e8c5304522f5ff36bface928ff1bd 100644 (file)
@@ -23,6 +23,7 @@ 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.MapReplyAction;
 import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
@@ -126,58 +127,36 @@ public class MapResolverTest extends BaseTestCase {
         mapRequest.addEidRecord(new EidRecord((byte) 0, new LispIpv4Address("1.2.3.4")));
 
         EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
-        record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
+        LocatorRecord locator = new LocatorRecord().setLocator(new LispIpv4Address(0x04030201));
+        locator.setLocalLocator(false);
+        locator.setRouted(true);
+        locator.setMulticastPriority((byte) 5);
+        locator.setMulticastWeight((byte) 17);
+        locator.setPriority((byte) 16);
+        record.addLocator(locator);
         prepareMapping(record);
 
         MapReply mapReply = testedMapResolver.handleMapRequest(mapRequest);
 
         EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
         assertEquals(1, eidToLocators.getLocators().size());
+        LocatorRecord resultLocator = mapReply.getEidToLocatorRecords().get(0).getLocators().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());
 
         assertLocator(new LispIpv4Address(0x04030201), eidToLocators.getLocators().get(0));
     }
 
-    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);
-
-                daoResults.put(
-                        MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getPrefix(), (byte) 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);
-            }
-        };
-
-        allowing(lispDAO).get(with(daoGetSaverAction));
-        will(daoGetSaverAction);
-
-        return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(v4Address));
-    }
-
     @Test
     public void handleMapRequest__VerifyBasicFields() throws Exception {
         mapRequest.addEidRecord(new EidRecord((byte) 0, v4Address));
 
         EidToLocatorRecord record = new EidToLocatorRecord().setPrefix(v4Address);
+        record.setAction(MapReplyAction.NativelyForward);
+        record.setAuthoritative(true);
         record.addLocator(new LocatorRecord().setLocator(new LispIpv4Address(0x04030201)));
         prepareMapping(record);
 
@@ -187,6 +166,9 @@ public class MapResolverTest extends BaseTestCase {
         EidToLocatorRecord eidToLocators = mapReply.getEidToLocatorRecords().get(0);
         assertEquals((byte) 0, eidToLocators.getMaskLength());
         assertEquals(v4Address, eidToLocators.getPrefix());
+        assertEquals(record.isAuthoritative(), eidToLocators.isAuthoritative());
+        assertEquals(record.getAction(), eidToLocators.getAction());
+        assertEquals(record.getRecordTtl(), eidToLocators.getRecordTtl());
     }
 
     @Test
@@ -305,4 +287,41 @@ public class MapResolverTest extends BaseTestCase {
         assertEquals(1, eidToLocators2.getLocators().size());
         assertLocator(new LispIpv6Address("0:0:0:0:0:0:0:1"), eidToLocators2.getLocators().get(0));
     }
+
+    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(), eidToLocatorRecord.getAction(), eidToLocatorRecord
+                            .isAuthoritative()));
+                }
+                value.setRlocs(rlocs);
+
+                daoResults.put(
+                        MappingServiceKeyUtil.generateMappingServiceKey(eidToLocatorRecord.getPrefix(), (byte) 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);
+            }
+        };
+
+        allowing(lispDAO).get(with(daoGetSaverAction));
+        will(daoGetSaverAction);
+
+        return daoResults.get(MappingServiceKeyUtil.generateMappingServiceKey(v4Address));
+    }
 }