Merge branch 'release-1.0.X' into develop
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / lisp / MapResolver.java
index 2ce297b2837334445e09d00165a0d93666104ac8..3f12d4c97da767ed024b4a866aa5d759297e4c09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Contextream, 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,
@@ -12,12 +12,13 @@ import java.util.ArrayList;
 import java.util.Map;
 
 import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil;
+import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper;
 import org.opendaylight.lispflowmapping.implementation.util.MaskUtil;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOC;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
-import org.opendaylight.lispflowmapping.interfaces.lisp.IMapReplyHandler;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler;
 import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolverAsync;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest;
 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord;
@@ -49,9 +50,22 @@ public class MapResolver implements IMapResolverAsync {
         this.shouldIterateMask = iterateMask;
     }
 
-    public void handleMapRequest(MapRequest request, IMapReplyHandler callback) {
+    public void handleMapRequest(MapRequest request, IMapRequestResultHandler callback) {
         if (dao == null) {
             logger.warn("handleMapRequest called while dao is uninitialized");
+            return;
+        }
+        if (request.isPitr()) {
+            if (request.getEidRecord().size() > 0) {
+                EidRecord eid = request.getEidRecord().get(0);
+                Map<String, ?> locators = getLocators(eid);
+                MappingServiceValue value = (MappingServiceValue) locators.get("value");
+                if (value.getRlocs() != null && value.getRlocs().size() > 0) {
+                    callback.handleNonProxyMapRequest(request,
+                            LispNotificationHelper.getInetAddressFromContainer(value.getRlocs().get(0).getRecord().getLispAddressContainer()));
+                }
+            }
+
         } else {
             MapReplyBuilder builder = new MapReplyBuilder();
             builder.setEchoNonceEnabled(false);
@@ -68,11 +82,7 @@ public class MapResolver implements IMapResolverAsync {
                 recordBuilder.setMaskLength(eid.getMask());
                 recordBuilder.setLispAddressContainer(eid.getLispAddressContainer());
                 recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
-                IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
-                Map<String, ?> locators = dao.get(key);
-                if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
-                    locators = findMaskLocators(key);
-                }
+                Map<String, ?> locators = getLocators(eid);
                 if (locators != null) {
                     MappingServiceValue value = (MappingServiceValue) locators.get("value");
 
@@ -81,12 +91,7 @@ public class MapResolver implements IMapResolverAsync {
                     } else {
                         recordBuilder
                                 .setAction(org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord.Action.NativelyForward);
-
-                        if (didContainRLOCs(value)) {
-                            recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
-                        } else {
-                            recordBuilder.setRecordTtl(TTL_NO_RLOC_KNOWN);
-                        }
+                        recordBuilder.setRecordTtl(TTL_RLOC_TIMED_OUT);
                     }
                 } else {
                     recordBuilder
@@ -99,8 +104,13 @@ public class MapResolver implements IMapResolverAsync {
         }
     }
 
-    private boolean didContainRLOCs(MappingServiceValue value) {
-        return value.getKey() == null;
+    private Map<String, ?> getLocators(EidRecord eid) {
+        IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask());
+        Map<String, ?> locators = dao.get(key);
+        if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) {
+            locators = findMaskLocators(key);
+        }
+        return locators;
     }
 
     private Map<String, ?> findMaskLocators(IMappingServiceKey key) {