Jonathan Hart
Committed by Gerrit Code Review

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

Fixes ONOS-2514.

Change-Id: I0d3d6012daa8dd2a45707a58cf6e745314f6dc24
......@@ -90,6 +90,14 @@ public interface RoutingConfigurationService {
Interface getInterface(ConnectPoint connectPoint);
/**
* Retrieves the interface associated with the given IP address.
*
* @param ip IP address of the interface
* @return the interface
*/
Interface getInterface(IpAddress ip);
/**
* Retrieves the interface that matches the given IP address. Matching
* means that the IP address is in one of the interface's assigned subnets.
*
......
......@@ -63,6 +63,20 @@ public class HostToInterfaceAdaptor {
return null;
}
public Interface getInterface(IpAddress ip) {
Set<PortAddresses> portAddresses = hostService.getAddressBindings();
for (PortAddresses portAddress : portAddresses) {
for (InterfaceIpAddress portIp : portAddress.ipAddresses()) {
if (portIp.ipAddress().equals(ip)) {
return new Interface(portAddress);
}
}
}
return null;
}
public Interface getMatchingInterface(IpAddress ipAddress) {
checkNotNull(ipAddress);
......
......@@ -159,6 +159,11 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
}
@Override
public Interface getInterface(IpAddress ip) {
return hostAdaptor.getInterface(ip);
}
@Override
public Interface getMatchingInterface(IpAddress ipAddress) {
return hostAdaptor.getMatchingInterface(ipAddress);
}
......
......@@ -173,7 +173,8 @@ public class HostToInterfaceAdaptorTest {
*/
@Test(expected = NullPointerException.class)
public void testGetInterfaceNull() {
adaptor.getInterface(null);
ConnectPoint c = null;
adaptor.getInterface(c);
}
/**
......
......@@ -139,24 +139,22 @@ public class PeerConnectivityManager {
List<InterfaceAddress> interfaceAddresses =
bgpSpeaker.interfaceAddresses();
Interface peerInterface = configService.getInterface(
bgpPeer.connectPoint());
if (peerInterface == null) {
log.error("No interface found for peer {}", bgpPeer.ipAddress());
return intents;
}
IpAddress bgpdAddress = null;
for (InterfaceAddress interfaceAddress : interfaceAddresses) {
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();
}
Interface peerInterface = configService.getInterface(interfaceAddress.ipAddress());
if (peerInterface == null) {
continue;
}
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;
}
}
if (bgpdAddress != null) {
break;
}
}
......@@ -167,7 +165,7 @@ public class PeerConnectivityManager {
}
IpAddress bgpdPeerAddress = bgpPeer.ipAddress();
ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint();
ConnectPoint bgpdPeerConnectPoint = bgpPeer.connectPoint();
if (bgpdAddress.version() != bgpdPeerAddress.version()) {
return intents;
......