Bug 3292: Invalid Range exception in setDpnId
[vpnservice.git] / nexthopmgr / nexthopmgr-impl / src / main / java / org / opendaylight / vpnservice / nexthopmgr / OdlInterfaceChangeListener.java
index 43a5fc509fea72e2628d3b2a7cabd65bde616216..bdfd046b00c052f91dabf8113e6fbcdc029c3831 100644 (file)
@@ -8,22 +8,21 @@
 package org.opendaylight.vpnservice.nexthopmgr;
 
 
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-
+import java.math.BigInteger;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.BaseIds;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.L3tunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL3tunnel;
-import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
-import org.opendaylight.vpnservice.nexthopmgr.AbstractDataChangeListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.L3tunnel;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -76,16 +75,9 @@ public class OdlInterfaceChangeListener extends AbstractDataChangeListener<Inter
         if (intrf.getType().equals(L3tunnel.class)) {
             IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
             IpAddress gatewayIp = intfData.getGatewayIp();
-            String gwIp = (gatewayIp == null) ? null : gatewayIp.toString();
-            String remoteIp = null;
-            if (gwIp != null) {
-                remoteIp = gwIp;
-            } else {
-                IpAddress remIp = intfData.getRemoteIp();
-                remoteIp = (remIp == null) ? null : remIp.toString();
-            }
+            IpAddress remoteIp = (gatewayIp == null) ? intfData.getRemoteIp() : gatewayIp;
             NodeConnectorId ofPort = intrf.getAugmentation(BaseIds.class).getOfPortId();
-            nexthopManager.createRemoteNextHop(intrf.getName(), ofPort.toString(), remoteIp);
+            nexthopManager.createRemoteNextHop(intrf.getName(), ofPort.toString(), remoteIp.getIpv4Address().getValue());
         }
     }
 
@@ -99,14 +91,11 @@ public class OdlInterfaceChangeListener extends AbstractDataChangeListener<Inter
             Interface intrf) {
         LOG.trace("Removing interface : key: " + identifier + ", value=" + intrf );
         if (intrf.getType().equals(L3tunnel.class)) {
-            long dpnId = interfaceManager.getDpnForInterface(intrf.getName());
+            BigInteger dpnId = interfaceManager.getDpnForInterface(intrf.getName());
             IfL3tunnel intfData = intrf.getAugmentation(IfL3tunnel.class);
-            String gwIp = intfData.getGatewayIp().toString();
-            String remoteIp = intfData.getRemoteIp().toString();
-            if (gwIp != null) {
-                remoteIp = gwIp;
-            }
-            nexthopManager.removeRemoteNextHop(dpnId, remoteIp);
+            IpAddress gatewayIp = intfData.getGatewayIp();
+            IpAddress remoteIp = (gatewayIp == null) ? intfData.getRemoteIp() : gatewayIp;
+            nexthopManager.removeRemoteNextHop(dpnId, intrf.getName(), remoteIp.getIpv4Address().getValue());
         }
     }