Bug 809: Enhancements to the toaster example
[controller.git] / opendaylight / md-sal / topology-lldp-discovery / src / main / java / org / opendaylight / md / controller / topology / lldp / utils / LLDPDiscoveryUtils.java
index d5dee32e40ef74e49fb80fb9e9eba284917a6c2b..ce42283ebe85eb02bfa67eeb4e3e8a565fca22a3 100644 (file)
@@ -1,7 +1,13 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.md.controller.topology.lldp.utils;
 
 import java.nio.charset.Charset;
-import java.util.List;
 
 import org.opendaylight.controller.sal.packet.Ethernet;
 import org.opendaylight.controller.sal.packet.LLDP;
@@ -46,10 +52,6 @@ public class LLDPDiscoveryUtils {
             LLDP lldp = (LLDP) ethPkt.getPayload();
     
             try {
-                List<LLDPTLV> optionalTLVList = lldp.getOptionalTLVList();
-                if (optionalTLVList == null) {
-                    return null;
-                }
                 NodeId srcNodeId = null;
                 NodeConnectorId srcNodeConnectorId = null;
                 for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) {
@@ -61,12 +63,13 @@ public class LLDPDiscoveryUtils {
                         srcNodeId = new NodeId(srcNodeIdString);
                     }
                 }
-                
-                InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class)
-                        .child(Node.class,new NodeKey(srcNodeId))
-                        .child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId))
-                        .toInstance();
-                return new NodeConnectorRef(srcInstanceId);
+                if(srcNodeId != null && srcNodeConnectorId != null) {
+                    InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class)
+                            .child(Node.class,new NodeKey(srcNodeId))
+                            .child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId))
+                            .toInstance();
+                    return new NodeConnectorRef(srcInstanceId);
+                }
             } catch (Exception e) {
                 LOG.warn("Caught exception ", e);
             }