From 3ae51ccd6ebd8b07f55f79ebbeaa7efa44a856b0 Mon Sep 17 00:00:00 2001 From: Maurice Qureshi Date: Wed, 11 Dec 2013 18:30:15 -0800 Subject: [PATCH] Send SystemName TLV in LLDP message. Some applications may need System Name TLV, therefore include SystemName TLV in the LLDP message sent by Controller Change-Id: I7226444c46a87b2e1618d1ee47026ccd4e9c2bef Signed-off-by: Maurice Qureshi --- .../openflow/internal/DiscoveryService.java | 14 ++++++++++++-- .../controller/sal/packet/LLDP.java | 19 ++++++++++++++++++- .../controller/sal/packet/LLDPTLV.java | 12 ++++++++++++ .../sal/utils/NodeConnectorCreator.java | 6 +++++- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java index 012807eee9..811135252d 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java @@ -125,7 +125,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, IDataPa private Boolean throttling = false; // if true, no more batching. private volatile Boolean shuttingDown = false; - private LLDPTLV chassisIdTlv, portIdTlv, ttlTlv, customTlv; + private LLDPTLV chassisIdTlv, systemNameTlv, portIdTlv, ttlTlv, customTlv; private IPluginOutConnectionService connectionOutService; class DiscoveryTransmit implements Runnable { @@ -217,6 +217,11 @@ public class DiscoveryService implements IInventoryShimExternalListener, IDataPa chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()).setLength((short) cidValue.length) .setValue(cidValue); + // Create LLDP SystemName TLV + byte[] snValue = LLDPTLV.createSystemNameTLVValue(nodeConnector.getNode().toString()); + systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()).setLength((short) snValue.length) + .setValue(snValue); + // Create LLDP PortID TLV String portId = nodeConnector.getNodeConnectorIDString(); byte[] pidValue = LLDPTLV.createPortIDTLVValue(portId); @@ -233,7 +238,8 @@ public class DiscoveryService implements IInventoryShimExternalListener, IDataPa // Create discovery pkt LLDP discoveryPkt = new LLDP(); - discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv).setTtl(ttlTlv).setOptionalTLVList(customList); + discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv).setTtl(ttlTlv).setSystemNameId(systemNameTlv) + .setOptionalTLVList(customList); RawPacket rawPkt = null; try { @@ -1462,6 +1468,10 @@ public class DiscoveryService implements IInventoryShimExternalListener, IDataPa chassisIdTlv = new LLDPTLV(); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()); + // Create LLDP SystemName TLV + systemNameTlv = new LLDPTLV(); + systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()); + // Create LLDP PortID TLV portIdTlv = new LLDPTLV(); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()); diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java index 6a896c6c71..95edca943b 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java @@ -21,9 +21,10 @@ import org.opendaylight.controller.sal.utils.NetUtils; public class LLDP extends Packet { private static final String CHASSISID = "ChassisId"; + private static final String SYSTEMNAMEID = "SystemNameID"; private static final String PORTID = "PortId"; private static final String TTL = "TTL"; - private static final int LLDPDefaultTlvs = 3; + private static final int LLDPDefaultTlvs = 4; private static LLDPTLV emptyTLV = new LLDPTLV().setLength((short) 0) .setType((byte) 0); public static final byte[] LLDPMulticastMac = { 1, (byte) 0x80, @@ -101,6 +102,22 @@ public class LLDP extends Packet { return this; } + /** + * @return the SystemName TLV + */ + public LLDPTLV getSystemNameId() { + return getTLV(SYSTEMNAMEID); + } + + /** + * @param LLDPTLV + * - the chassisId to set + */ + public LLDP setSystemNameId(LLDPTLV systemNameId) { + tlvList.put(getType(SYSTEMNAMEID), systemNameId); + return this; + } + /** * @return LLDPTLV - the portId TLV */ diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java index bf67402259..27660221ce 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java @@ -187,6 +187,18 @@ public class LLDPTLV extends Packet { getfieldnumBits(VALUE)); // variable } + /** + * Creates the SystemName TLV value + * + * @param nodeId + * node identifier string + * @return the SystemName TLV value in byte array + */ + static public byte[] createSystemNameTLVValue(String nodeId) { + byte[] nid = nodeId.getBytes(); + return nid; + } + /** * Creates the ChassisID TLV value including the subtype and ChassisID * string diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NodeConnectorCreator.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NodeConnectorCreator.java index da4cd53883..9cd551664c 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NodeConnectorCreator.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NodeConnectorCreator.java @@ -73,7 +73,11 @@ public abstract class NodeConnectorCreator { public static NodeConnector createNodeConnector( String nodeConnectorType, Object portId, Node node) { try { - return new NodeConnector(nodeConnectorType, portId, node); + if (nodeConnectorType.equals(Node.NodeIDType.OPENFLOW) && (portId.getClass() == String.class)) { + return new NodeConnector(nodeConnectorType, Short.parseShort((String) portId), node); + } else { + return new NodeConnector(nodeConnectorType, portId, node); + } } catch (ConstructionException e1) { logger.error("",e1); return null; -- 2.36.6