Jonathan Hart

Fix for SDN-IP installing wrong point-to-point intents.

Fixes ONOS-2514.

Ported from onos-1.2 branch.

Change-Id: I0d3d6012daa8dd2a45707a58cf6e745314f6dc24
(cherry picked from commit 0c763e9b)
...@@ -98,6 +98,14 @@ public interface RoutingConfigurationService { ...@@ -98,6 +98,14 @@ public interface RoutingConfigurationService {
98 Interface getInterface(ConnectPoint connectPoint); 98 Interface getInterface(ConnectPoint connectPoint);
99 99
100 /** 100 /**
101 + * Retrieves the interface associated with the given IP address.
102 + *
103 + * @param ip IP address of the interface
104 + * @return the interface
105 + */
106 + Interface getInterface(IpAddress ip);
107 +
108 + /**
101 * Retrieves the interface that matches the given IP address. Matching 109 * Retrieves the interface that matches the given IP address. Matching
102 * means that the IP address is in one of the interface's assigned subnets. 110 * means that the IP address is in one of the interface's assigned subnets.
103 * 111 *
......
...@@ -63,6 +63,20 @@ public class HostToInterfaceAdaptor { ...@@ -63,6 +63,20 @@ public class HostToInterfaceAdaptor {
63 return null; 63 return null;
64 } 64 }
65 65
66 + public Interface getInterface(IpAddress ip) {
67 + Set<PortAddresses> portAddresses = hostService.getAddressBindings();
68 +
69 + for (PortAddresses portAddress : portAddresses) {
70 + for (InterfaceIpAddress portIp : portAddress.ipAddresses()) {
71 + if (portIp.ipAddress().equals(ip)) {
72 + return new Interface(portAddress);
73 + }
74 + }
75 + }
76 +
77 + return null;
78 + }
79 +
66 public Interface getMatchingInterface(IpAddress ipAddress) { 80 public Interface getMatchingInterface(IpAddress ipAddress) {
67 checkNotNull(ipAddress); 81 checkNotNull(ipAddress);
68 82
......
...@@ -187,6 +187,11 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -187,6 +187,11 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
187 } 187 }
188 188
189 @Override 189 @Override
190 + public Interface getInterface(IpAddress ip) {
191 + return hostAdaptor.getInterface(ip);
192 + }
193 +
194 + @Override
190 public Interface getMatchingInterface(IpAddress ipAddress) { 195 public Interface getMatchingInterface(IpAddress ipAddress) {
191 return hostAdaptor.getMatchingInterface(ipAddress); 196 return hostAdaptor.getMatchingInterface(ipAddress);
192 } 197 }
......
...@@ -173,7 +173,8 @@ public class HostToInterfaceAdaptorTest { ...@@ -173,7 +173,8 @@ public class HostToInterfaceAdaptorTest {
173 */ 173 */
174 @Test(expected = NullPointerException.class) 174 @Test(expected = NullPointerException.class)
175 public void testGetInterfaceNull() { 175 public void testGetInterfaceNull() {
176 - adaptor.getInterface(null); 176 + ConnectPoint c = null;
177 + adaptor.getInterface(c);
177 } 178 }
178 179
179 /** 180 /**
......
...@@ -139,24 +139,22 @@ public class PeerConnectivityManager { ...@@ -139,24 +139,22 @@ public class PeerConnectivityManager {
139 List<InterfaceAddress> interfaceAddresses = 139 List<InterfaceAddress> interfaceAddresses =
140 bgpSpeaker.interfaceAddresses(); 140 bgpSpeaker.interfaceAddresses();
141 141
142 - Interface peerInterface = configService.getInterface( 142 + IpAddress bgpdAddress = null;
143 - bgpPeer.connectPoint()); 143 + for (InterfaceAddress interfaceAddress : interfaceAddresses) {
144 - 144 + Interface peerInterface = configService.getInterface(interfaceAddress.ipAddress());
145 if (peerInterface == null) { 145 if (peerInterface == null) {
146 - log.error("No interface found for peer {}", bgpPeer.ipAddress()); 146 + continue;
147 - return intents;
148 } 147 }
149 148
150 - IpAddress bgpdAddress = null;
151 - for (InterfaceAddress interfaceAddress : interfaceAddresses) {
152 - if (interfaceAddress.connectPoint().equals(peerInterface.connectPoint())) {
153 for (InterfaceIpAddress interfaceIpAddress : peerInterface.ipAddresses()) { 149 for (InterfaceIpAddress interfaceIpAddress : peerInterface.ipAddresses()) {
154 // Only add intents where the peer and ONOS's addresses are 150 // Only add intents where the peer and ONOS's addresses are
155 // in the same subnet 151 // in the same subnet
156 if (interfaceIpAddress.subnetAddress().contains(bgpPeer.ipAddress())) { 152 if (interfaceIpAddress.subnetAddress().contains(bgpPeer.ipAddress())) {
157 bgpdAddress = interfaceAddress.ipAddress(); 153 bgpdAddress = interfaceAddress.ipAddress();
154 + break;
158 } 155 }
159 } 156 }
157 + if (bgpdAddress != null) {
160 break; 158 break;
161 } 159 }
162 } 160 }
...@@ -167,7 +165,7 @@ public class PeerConnectivityManager { ...@@ -167,7 +165,7 @@ public class PeerConnectivityManager {
167 } 165 }
168 166
169 IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); 167 IpAddress bgpdPeerAddress = bgpPeer.ipAddress();
170 - ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint(); 168 + ConnectPoint bgpdPeerConnectPoint = bgpPeer.connectPoint();
171 169
172 if (bgpdAddress.version() != bgpdPeerAddress.version()) { 170 if (bgpdAddress.version() != bgpdPeerAddress.version()) {
173 return intents; 171 return intents;
......