Fix bug where SDN-IP installs more intents than needed

Ported from onos-1.2 branch.

Change-Id: Ic085d5033105e0c688369a71de077c7541d26dbf
(cherry picked from commit 1258f86b564be76771c5cd6e1f807c4bc529168a)
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
index ccab7dc..f9ee791 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java
@@ -26,6 +26,7 @@
 import org.onosproject.net.flow.DefaultTrafficTreatment;
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.host.InterfaceIpAddress;
 import org.onosproject.net.intent.PointToPointIntent;
 import org.onosproject.routing.config.BgpPeer;
 import org.onosproject.routing.config.BgpSpeaker;
@@ -148,9 +149,14 @@
 
         IpAddress bgpdAddress = null;
         for (InterfaceAddress interfaceAddress : interfaceAddresses) {
-            if (interfaceAddress.connectPoint().equals(
-                    peerInterface.connectPoint())) {
-                bgpdAddress = interfaceAddress.ipAddress();
+            if (interfaceAddress.connectPoint().equals(peerInterface.connectPoint())) {
+                for (InterfaceIpAddress interfaceIpAddress : peerInterface.ipAddresses()) {
+                    // Only add intents where the peer and ONOS's addresses are
+                    // in the same subnet
+                    if (interfaceIpAddress.subnetAddress().contains(bgpPeer.ipAddress())) {
+                        bgpdAddress = interfaceAddress.ipAddress();
+                    }
+                }
                 break;
             }
         }