Thomas Vachuska
Committed by Gerrit Code Review

Fixed a potential NPE in link discovery.

Change-Id: I3bff307e54a1e3bdac1053dfea6e96ae3cd29f07
...@@ -40,6 +40,7 @@ import org.slf4j.Logger; ...@@ -40,6 +40,7 @@ import org.slf4j.Logger;
40 import java.nio.ByteBuffer; 40 import java.nio.ByteBuffer;
41 import java.util.Set; 41 import java.util.Set;
42 42
43 +import static com.google.common.base.Strings.isNullOrEmpty;
43 import static java.util.concurrent.TimeUnit.MILLISECONDS; 44 import static java.util.concurrent.TimeUnit.MILLISECONDS;
44 import static org.onosproject.net.PortNumber.portNumber; 45 import static org.onosproject.net.PortNumber.portNumber;
45 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; 46 import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
...@@ -165,20 +166,24 @@ public class LinkDiscovery implements TimerTask { ...@@ -165,20 +166,24 @@ public class LinkDiscovery implements TimerTask {
165 166
166 PortNumber srcPort = portNumber(onoslldp.getPort()); 167 PortNumber srcPort = portNumber(onoslldp.getPort());
167 PortNumber dstPort = packetContext.inPacket().receivedFrom().port(); 168 PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
168 - DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
169 - DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
170 169
171 - ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort); 170 + String idString = onoslldp.getDeviceString();
172 - ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort); 171 + if (!isNullOrEmpty(idString)) {
173 - 172 + DeviceId srcDeviceId = DeviceId.deviceId(idString);
174 - LinkDescription ld = new DefaultLinkDescription(src, dst, lt); 173 + DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
175 - try { 174 +
176 - context.providerService().linkDetected(ld); 175 + ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
177 - context.touchLink(LinkKey.linkKey(src, dst)); 176 + ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
178 - } catch (IllegalStateException e) { 177 +
178 + LinkDescription ld = new DefaultLinkDescription(src, dst, lt);
179 + try {
180 + context.providerService().linkDetected(ld);
181 + context.touchLink(LinkKey.linkKey(src, dst));
182 + } catch (IllegalStateException e) {
183 + return true;
184 + }
179 return true; 185 return true;
180 } 186 }
181 - return true;
182 } 187 }
183 return false; 188 return false;
184 } 189 }
......