+/*
+ * 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;
public class LLDPDiscoveryUtils {
static Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryUtils.class);
-
+
public static final Long LLDP_INTERVAL = (long) (1000*5); // Send LLDP every five seconds
public static final Long LLDP_EXPIRATION_TIME = LLDP_INTERVAL*3; // Let up to three intervals pass before we decide we are expired.
-
+
public static String macToString(byte[] mac) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
return b.toString();
}
-
+
public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload) {
Ethernet ethPkt = new Ethernet();
try {
if (ethPkt.getPayload() instanceof LLDP) {
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()) {
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);
}