Saurav Das
Committed by Gerrit Code Review

Fixing a couple of NPEs

Change-Id: I19b5a2787b26e67e05640f6c64a13b58f2dc089a
......@@ -24,7 +24,6 @@ import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.packet.DefaultOutboundPacket;
......@@ -88,10 +87,7 @@ public class ArpHandler {
ARP arp = (ARP) ethernet.getPayload();
ConnectPoint connectPoint = pkt.receivedFrom();
PortNumber inPort = connectPoint.port();
DeviceId deviceId = connectPoint.deviceId();
byte[] senderMacAddressByte = arp.getSenderHardwareAddress();
Ip4Address hostIpAddress = Ip4Address.valueOf(arp.getSenderProtocolAddress());
if (arp.getOpCode() == ARP.OP_REQUEST) {
handleArpRequest(deviceId, connectPoint, ethernet);
} else {
......@@ -254,15 +250,23 @@ public class ArpHandler {
((ARP) packet.getPayload()).getTargetProtocolAddress()
);
srManager.deviceConfiguration.getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> {
if (subnet.contains(targetProtocolAddress)) {
ports.stream()
.filter(port -> port != inPort.port())
.forEach(port -> {
removeVlanAndForward(packet, new ConnectPoint(inPort.deviceId(), port));
});
}
});
try {
srManager.deviceConfiguration
.getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> {
if (subnet.contains(targetProtocolAddress)) {
ports.stream()
.filter(port -> port != inPort.port())
.forEach(port -> {
removeVlanAndForward(packet,
new ConnectPoint(inPort.deviceId(), port));
});
}
});
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage()
+ " Cannot flood in subnet as device config not available"
+ " for device: " + inPort.deviceId());
}
}
/**
......
......@@ -564,6 +564,8 @@ public class DefaultRoutingHandler {
public void purgeEcmpGraph(DeviceId deviceId) {
currentEcmpSpgMap.remove(deviceId);
updatedEcmpSpgMap.remove(deviceId);
if (updatedEcmpSpgMap != null) {
updatedEcmpSpgMap.remove(deviceId);
}
}
}
......
......@@ -264,12 +264,16 @@ public class DeviceConfiguration implements DeviceProperties {
}
@Override
public Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId) {
Map<Ip4Prefix, List<PortNumber>> subnetPortMap = new HashMap<>();
public Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId)
throws DeviceConfigNotFoundException {
SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
if (srinfo == null) {
String message = "getSubnetPortsMap fails for device: " + deviceId + ".";
throw new DeviceConfigNotFoundException(message);
}
// Construct subnet-port mapping from port-subnet mapping
SetMultimap<PortNumber, Ip4Prefix> portSubnetMap =
this.deviceConfigMap.get(deviceId).subnets;
SetMultimap<PortNumber, Ip4Prefix> portSubnetMap = srinfo.subnets;
Map<Ip4Prefix, List<PortNumber>> subnetPortMap = new HashMap<>();
portSubnetMap.entries().forEach(entry -> {
PortNumber port = entry.getKey();
......
......@@ -93,8 +93,10 @@ public interface DeviceProperties {
*
* @param deviceId device identifier
* @return a map that contains all subnet-to-ports mapping of given device
* @throws DeviceConfigNotFoundException
*/
Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId);
Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId)
throws DeviceConfigNotFoundException;
/**
* Returns the VLAN cross-connect configuration.
......
......@@ -677,8 +677,14 @@ public class DefaultGroupHandler {
* Creates broadcast groups for all ports in the same configured subnet.
*/
public void createGroupsFromSubnetConfig() {
Map<Ip4Prefix, List<PortNumber>> subnetPortMap =
this.deviceConfig.getSubnetPortsMap(this.deviceId);
Map<Ip4Prefix, List<PortNumber>> subnetPortMap;
try {
subnetPortMap = this.deviceConfig.getSubnetPortsMap(this.deviceId);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage()
+ " Not creating broadcast groups for device: " + deviceId);
return;
}
// Construct a broadcast group for each subnet
subnetPortMap.forEach((subnet, ports) -> {
SubnetNextObjectiveStoreKey key =
......