X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FDiscoveryService.java;h=0cbaf67d9ed9452afc0927de7b9b487547663713;hb=06aa5ce746e29a3760688b2ef2817f50bec5ea7a;hp=eab87a4440b356d0f734061505897e3115d87d8e;hpb=d192c699590d441eb96a697b9e8ab7a028f18860;p=controller.git 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 eab87a4440..0cbaf67d9e 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 @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -72,33 +71,62 @@ public class DiscoveryService implements IInventoryShimExternalListener, private IPluginInInventoryService pluginInInventoryService = null; private IDataPacketMux iDataPacketMux = null; - private List readyListHi = null; // newly added ports go into this list and will be served first - private List readyListLo = null; // come here after served at least once - private List waitingList = null; // staging area during quiet period - private ConcurrentMap pendingMap = null;// wait for response back - private ConcurrentMap edgeMap = null; // openflow edges keyed by head connector - private ConcurrentMap agingMap = null; // aging entries keyed by edge port - private ConcurrentMap prodMap = null; // production edges keyed by edge port + private List readyListHi = null; // newly added ports go into + // this list and will be + // served first + private List readyListLo = null; // come here after served at + // least once + private List waitingList = null; // staging area during quiet + // period + private ConcurrentMap pendingMap = null;// wait for + // response + // back + private ConcurrentMap edgeMap = null; // openflow edges + // keyed by head + // connector + private ConcurrentMap agingMap = null; // aging + // entries + // keyed by + // edge port + private ConcurrentMap prodMap = null; // production + // edges keyed by + // edge port private Timer discoveryTimer; // discovery timer private DiscoveryTimerTask discoveryTimerTask; // timer task private long discoveryTimerTick = 1L * 1000; // per tick in msec private int discoveryTimerTickCount = 0; // main tick counter - private int discoveryBatchMaxPorts = 500; // max # of ports handled in one batch - private int discoveryBatchRestartTicks = 30; // periodically restart batching process - private int discoveryBatchPausePeriod = 2; // pause for few secs - private int discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; // pause after this point - private int discoveryRetry = 1; // number of retry after initial timeout - private int discoveryTimeoutTicks = 2; // timeout 2 sec + private int discoveryBatchMaxPorts = 500; // max # of ports handled in one + // batch + private int discoveryBatchRestartTicks = getDiscoveryInterval(); // periodically + // restart + // batching + // process + private int discoveryBatchPausePeriod = 5; // pause for few secs + private int discoveryBatchPauseTicks = discoveryBatchRestartTicks + - discoveryBatchPausePeriod; // pause after this point + private int discoveryRetry = getDiscoveryRetry(); // number of retries after + // initial timeout + private int discoveryTimeoutTicks = getDiscoveryTimeout(); // timeout in sec private int discoveryAgeoutTicks = 120; // age out 2 min - private int discoveryConsistencyCheckMultiple = 2; // multiple of discoveryBatchRestartTicks - private int discoveryConsistencyCheckTickCount = discoveryBatchPauseTicks; // CC tick counter - private int discoveryConsistencyCheckCallingTimes = 0; // # of times CC gets called - private int discoveryConsistencyCheckCorrected = 0; // # of cases CC corrected - private boolean discoveryConsistencyCheckEnabled = true;// enable or disable CC + private int discoveryConsistencyCheckMultiple = 2; // multiple of + // discoveryBatchRestartTicks + private int discoveryConsistencyCheckTickCount = discoveryBatchPauseTicks; // CC + // tick + // counter + private int discoveryConsistencyCheckCallingTimes = 0; // # of times CC gets + // called + private int discoveryConsistencyCheckCorrected = 0; // # of cases CC + // corrected + private boolean discoveryConsistencyCheckEnabled = true;// enable or disable + // CC private boolean discoveryAgingEnabled = true; // enable or disable aging - private boolean discoverySpoofingEnabled = true; // enable or disable spoofing neighbor of a production network - + private boolean discoverySnoopingEnabled = true; // global flag to enable or + // disable LLDP snooping + private List discoverySnoopingDisableList; // the list of + // ports that will + // not do LLDP + // snooping private BlockingQueue transmitQ; private Thread transmitThread; private Boolean throttling = false; // if true, no more batching. @@ -121,13 +149,11 @@ public class DiscoveryService implements IInventoryShimExternalListener, sendDiscoveryPacket(nodeConnector, outPkt); nodeConnector = null; } catch (InterruptedException e1) { - logger - .warn("DiscoveryTransmit interupted", e1 - .getMessage()); + logger.warn("DiscoveryTransmit interupted", e1.getMessage()); if (shuttingDown) return; } catch (Exception e2) { - logger.error("",e2); + logger.error("", e2); } } } @@ -158,7 +184,8 @@ public class DiscoveryService implements IInventoryShimExternalListener, .setLength((short) pidValue.length).setValue(pidValue); // Create LLDP Custom TLV - byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnector.toString()); + byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnector + .toString()); customTlv.setType((byte) LLDPTLV.TLVType.Custom.getValue()) .setLength((short) customValue.length).setValue(customValue); @@ -168,24 +195,25 @@ public class DiscoveryService implements IInventoryShimExternalListener, // Create discovery pkt LLDP discoveryPkt = new LLDP(); - discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv).setTtl( - ttlTlv).setOptionalTLVList(customList); + discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv) + .setTtl(ttlTlv).setOptionalTLVList(customList); RawPacket rawPkt = null; try { // Create ethernet pkt - byte[] sourceMac = getSouceMACFromNodeID(nodeId); + byte[] sourceMac = getSouceMACFromNodeID(nodeId); Ethernet ethPkt = new Ethernet(); - ethPkt.setSourceMACAddress(sourceMac).setDestinationMACAddress( - LLDP.LLDPMulticastMac).setEtherType( - EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt); + ethPkt.setSourceMACAddress(sourceMac) + .setDestinationMACAddress(LLDP.LLDPMulticastMac) + .setEtherType(EtherTypes.LLDP.shortValue()) + .setPayload(discoveryPkt); byte[] data = ethPkt.serialize(); rawPkt = new RawPacket(data); rawPkt.setOutgoingNodeConnector(nodeConnector); } catch (ConstructionException cex) { - logger.warn("RawPacket creation caught exception {}", cex - .getMessage()); + logger.warn("RawPacket creation caught exception {}", + cex.getMessage()); } catch (Exception e) { logger.error("Failed to serialize the LLDP packet: " + e); } @@ -209,12 +237,16 @@ public class DiscoveryService implements IInventoryShimExternalListener, ISwitch sw = controller.getSwitches().get(sid); if (sw == null) { - logger.debug("Can not send discovery packet out since switch {} is null", sid); + logger.debug( + "Can not send discovery packet out since switch {} is null", + sid); return; } if (!sw.isOperational()) { - logger.debug("Can not send discovery packet out since switch {} is not operational", sw); + logger.debug( + "Can not send discovery packet out since switch {} is not operational", + sw); return; } @@ -256,53 +288,64 @@ public class DiscoveryService implements IInventoryShimExternalListener, try { ethPkt.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte); } catch (Exception e) { - logger.warn("Failed to decode LLDP packet from " - + inPkt.getIncomingNodeConnector() + ": " + e); + logger.warn("Failed to decode LLDP packet from {}: {}", + inPkt.getIncomingNodeConnector(), e); return PacketResult.IGNORED; } if (ethPkt.getPayload() instanceof LLDP) { NodeConnector dst = inPkt.getIncomingNodeConnector(); - if (!processDiscoveryPacket(dst, ethPkt)) { - /* Spoof the discovery pkt if not generated from us */ - spoofDiscoveryPacket(dst, ethPkt); + if (isEnabled(dst)) { + if (!processDiscoveryPacket(dst, ethPkt)) { + /* Snoop the discovery pkt if not generated from us */ + snoopDiscoveryPacket(dst, ethPkt); + } + return PacketResult.CONSUME; } - return PacketResult.CONSUME; } return PacketResult.IGNORED; } /* - * Spoof incoming discovery frames generated by the production network neighbor switch + * Snoop incoming discovery frames generated by the production network + * neighbor switch */ - private void spoofDiscoveryPacket(NodeConnector dstNodeConnector, + private void snoopDiscoveryPacket(NodeConnector dstNodeConnector, Ethernet ethPkt) { - if (!this.discoverySpoofingEnabled) { + if (!this.discoverySnoopingEnabled + || discoverySnoopingDisableList.contains(dstNodeConnector)) { + logger.trace( + "Discarded received discovery packet on {} since snooping is turned off", + dstNodeConnector); return; } if ((dstNodeConnector == null) || (ethPkt == null)) { - logger.trace("Quit spoofing discovery packet: Null node connector or packet"); + logger.trace("Quit snooping discovery packet: Null node connector or packet"); return; } LLDP lldp = (LLDP) ethPkt.getPayload(); try { - String nodeId = LLDPTLV.getHexStringValue(lldp.getChassisId().getValue(), lldp.getChassisId().getLength()); - String portId = LLDPTLV.getStringValue(lldp.getPortId().getValue(), lldp.getPortId().getLength()); - byte[] systemNameBytes = null; - // get system name if present in the LLDP pkt - for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) { - if (lldptlv.getType() == LLDPTLV.TLVType.SystemName.getValue()) { - systemNameBytes = lldptlv.getValue(); - break; - } - } - String nodeName = (systemNameBytes == null) ? nodeId : new String(systemNameBytes); - Node srcNode = new Node(Node.NodeIDType.PRODUCTION, nodeName); - NodeConnector srcNodeConnector = NodeConnectorCreator - .createNodeConnector(NodeConnector.NodeConnectorIDType.PRODUCTION, - portId, srcNode); + String nodeId = LLDPTLV.getHexStringValue(lldp.getChassisId() + .getValue(), lldp.getChassisId().getLength()); + String portId = LLDPTLV.getStringValue(lldp.getPortId().getValue(), + lldp.getPortId().getLength()); + byte[] systemNameBytes = null; + // get system name if present in the LLDP pkt + for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) { + if (lldptlv.getType() == LLDPTLV.TLVType.SystemName.getValue()) { + systemNameBytes = lldptlv.getValue(); + break; + } + } + String nodeName = (systemNameBytes == null) ? nodeId : new String( + systemNameBytes); + Node srcNode = new Node(Node.NodeIDType.PRODUCTION, nodeName); + NodeConnector srcNodeConnector = NodeConnectorCreator + .createNodeConnector( + NodeConnector.NodeConnectorIDType.PRODUCTION, + portId, srcNode); Edge edge = null; Set props = null; @@ -317,13 +360,13 @@ public class DiscoveryService implements IInventoryShimExternalListener, /* * Handle discovery frames generated by our controller + * * @return true if it's a success */ private boolean processDiscoveryPacket(NodeConnector dstNodeConnector, Ethernet ethPkt) { if ((dstNodeConnector == null) || (ethPkt == null)) { - logger - .trace("Ignoring processing of discovery packet: Null node connector or packet"); + logger.trace("Ignoring processing of discovery packet: Null node connector or packet"); return false; } @@ -343,26 +386,26 @@ public class DiscoveryService implements IInventoryShimExternalListener, NodeConnector srcNodeConnector = null; for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) { if (lldptlv.getType() == LLDPTLV.TLVType.Custom.getValue()) { - String ncString = LLDPTLV.getCustomString(lldptlv.getValue(), lldptlv.getLength()); - srcNodeConnector = NodeConnector.fromString(ncString); - if (srcNodeConnector != null) { - srcNode = srcNodeConnector.getNode(); - /* Check if it's expected */ - if (isTracked(srcNodeConnector)) { - break; + String ncString = LLDPTLV.getCustomString(lldptlv.getValue(), + lldptlv.getLength()); + srcNodeConnector = NodeConnector.fromString(ncString); + if (srcNodeConnector != null) { + srcNode = srcNodeConnector.getNode(); + /* Check if it's expected */ + if (isTracked(srcNodeConnector)) { + break; } else { - srcNode = null; - srcNodeConnector = null; + srcNode = null; + srcNodeConnector = null; } } } } if ((srcNode == null) || (srcNodeConnector == null)) { - logger - .trace( - "Received non-controller generated discovery packet from {}", - dstNodeConnector); + logger.trace( + "Received non-controller generated discovery packet from {}", + dstNodeConnector); return false; } @@ -715,8 +758,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, } NodeConnector src = edge.getTailNodeConnector(); - if (!src.getType().equals( - NodeConnector.NodeConnectorIDType.PRODUCTION)) { + if (!src.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { pendingMap.remove(src); if (!waitingList.contains(src)) { waitingList.add(src); @@ -731,44 +773,47 @@ public class DiscoveryService implements IInventoryShimExternalListener, logger.trace("Add edge {}", edge); } - /** * Update Production Edge * - * @param edge The Production Edge - * @param props Properties associated with the edge + * @param edge + * The Production Edge + * @param props + * Properties associated with the edge */ private void updateProdEdge(Edge edge, Set props) { - NodeConnector edgePort = edge.getHeadNodeConnector(); - - /* Do not update in case there is an existing OpenFlow link */ - if (edgeMap.get(edgePort) != null) { - logger.trace("Discarded edge {} since there is an existing OF link {}", - edge, edgeMap.get(edgePort)); - return; - } - - /* Look for any existing Production Edge */ - Edge oldEdge = prodMap.get(edgePort); - if (oldEdge == null) { - /* Let's add a new one */ - addEdge(edge, props); - } else if (!edge.equals(oldEdge)) { - /* Remove the old one first */ - removeProdEdge(oldEdge.getHeadNodeConnector()); - /* Then add the new one */ - addEdge(edge, props); - } else { - /* o/w, just reset the aging timer */ + NodeConnector edgePort = edge.getHeadNodeConnector(); + + /* Do not update in case there is an existing OpenFlow link */ + if (edgeMap.get(edgePort) != null) { + logger.trace( + "Discarded edge {} since there is an existing OF link {}", + edge, edgeMap.get(edgePort)); + return; + } + + /* Look for any existing Production Edge */ + Edge oldEdge = prodMap.get(edgePort); + if (oldEdge == null) { + /* Let's add a new one */ + addEdge(edge, props); + } else if (!edge.equals(oldEdge)) { + /* Remove the old one first */ + removeProdEdge(oldEdge.getHeadNodeConnector()); + /* Then add the new one */ + addEdge(edge, props); + } else { + /* o/w, just reset the aging timer */ NodeConnector dst = edge.getHeadNodeConnector(); - agingMap.put(dst, 0); - } + agingMap.put(dst, 0); + } } /** * Remove Production Edge for a given edge port * - * @param edgePort The OF edge port + * @param edgePort + * The OF edge port */ private void removeProdEdge(NodeConnector edgePort) { agingMap.remove(edgePort); @@ -832,12 +877,11 @@ public class DiscoveryService implements IInventoryShimExternalListener, NodeConnector src = edge.getTailNodeConnector(), dst = edge .getHeadNodeConnector(); - if (!src.getType().equals( - NodeConnector.NodeConnectorIDType.PRODUCTION)) { + if (!src.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { if (type == UpdateType.ADDED) { - edgeMap.put(src, edge); + edgeMap.put(dst, edge); } else { - edgeMap.remove(src); + edgeMap.remove(dst); } } else { /* @@ -880,31 +924,34 @@ public class DiscoveryService implements IInventoryShimExternalListener, public String getHelp() { StringBuffer help = new StringBuffer(); help.append("---Topology Discovery---\n"); - help.append("\t prlh - Print readyListHi entries\n"); - help.append("\t prll - Print readyListLo entries\n"); - help.append("\t pwl - Print waitingList entries\n"); - help.append("\t ppl - Print pendingList entries\n"); - help.append("\t ptick - Print tick time in msec\n"); - help.append("\t pcc - Print CC info\n"); - help.append("\t psize - Print sizes of all the lists\n"); - help.append("\t ptm - Print timeout info\n"); - help.append("\t ecc - Enable CC\n"); - help.append("\t dcc - Disable CC\n"); - help.append("\t scc [multiple] - Set/show CC multiple and interval\n"); - help.append("\t sports [ports] - Set/show max ports per batch\n"); - help.append("\t spause [ticks] - Set/show pause period\n"); - help.append("\t sdi [ticks] - Set/show discovery interval in ticks\n"); - help.append("\t stm [ticks] - Set/show per timeout ticks\n"); - help.append("\t sretry [count] - Set/show num of retries\n"); - help.append("\t addsw - Add a switch\n"); - help.append("\t remsw - Remove a switch\n"); - help.append("\t page - Print aging info\n"); - help.append("\t sage - Set/Show aging time limit\n"); - help.append("\t eage - Enable aging\n"); - help.append("\t dage - Disable aging\n"); - help.append("\t pthrot - Print throttling\n"); - help.append("\t ethrot - Enable throttling\n"); - help.append("\t dthrot - Disable throttling\n"); + help.append("\t prlh - Print readyListHi entries\n"); + help.append("\t prll - Print readyListLo entries\n"); + help.append("\t pwl - Print waitingList entries\n"); + help.append("\t ppl - Print pendingList entries\n"); + help.append("\t ptick - Print tick time in msec\n"); + help.append("\t pcc - Print CC info\n"); + help.append("\t psize - Print sizes of all the lists\n"); + help.append("\t ptm - Print timeout info\n"); + help.append("\t ecc - Enable CC\n"); + help.append("\t dcc - Disable CC\n"); + help.append("\t scc [multiple] - Set/show CC multiple and interval\n"); + help.append("\t sports [ports] - Set/show max ports per batch\n"); + help.append("\t spause [ticks] - Set/show pause period\n"); + help.append("\t sdi [ticks] - Set/show discovery interval in ticks\n"); + help.append("\t stm [ticks] - Set/show per timeout ticks\n"); + help.append("\t sretry [count] - Set/show num of retries\n"); + help.append("\t addsw - Add a switch\n"); + help.append("\t remsw - Remove a switch\n"); + help.append("\t page - Print aging info\n"); + help.append("\t sage - Set/Show aging time limit\n"); + help.append("\t eage - Enable aging\n"); + help.append("\t dage - Disable aging\n"); + help.append("\t pthrot - Print throttling\n"); + help.append("\t ethrot - Enable throttling\n"); + help.append("\t dthrot - Disable throttling\n"); + help.append("\t psnp - Print LLDP snooping\n"); + help.append("\t esnp - Enable LLDP snooping\n"); + help.append("\t dsnp - Disable LLDP snooping\n"); return help.toString(); } @@ -968,7 +1015,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, public void _ptm(CommandInterpreter ci) { ci.println("Final timeout ticks " + getDiscoveryFinalTimeoutInterval()); ci.println("Per timeout ticks " + discoveryTimeoutTicks); - ci.println("Retry after initial timeout " + discoveryRetry); + ci.println("Number of retries after initial timeout " + discoveryRetry); } public void _psize(CommandInterpreter ci) { @@ -1068,40 +1115,76 @@ public class DiscoveryService implements IInventoryShimExternalListener, return; } - public void _pspf(CommandInterpreter ci) { - if (this.discoverySpoofingEnabled) { - ci.println("Discovery spoofing is enabled"); + public void _psnp(CommandInterpreter ci) { + if (this.discoverySnoopingEnabled) { + ci.println("Discovery snooping is globally enabled"); } else { - ci.println("Discovery spoofing is disabled"); + ci.println("Discovery snooping is globally disabled"); + } + + ci.println("\nDiscovery snooping is locally disabled on these ports"); + for (NodeConnector nodeConnector : discoverySnoopingDisableList) { + ci.println(nodeConnector); } return; } - public void _espf(CommandInterpreter ci) { - this.discoverySpoofingEnabled = true; - ci.println("Discovery spoofing is enabled"); + public void _esnp(CommandInterpreter ci) { + String val = ci.nextArgument(); + + if (val == null) { + ci.println("Usage: esnp "); + } else if (val.equalsIgnoreCase("all")) { + this.discoverySnoopingEnabled = true; + ci.println("Discovery snooping is globally enabled"); + } else { + NodeConnector nodeConnector = NodeConnector.fromString(val); + if (nodeConnector != null) { + discoverySnoopingDisableList.remove(nodeConnector); + ci.println("Discovery snooping is locally enabled on port " + + nodeConnector); + } else { + ci.println("Entered invalid NodeConnector " + val); + } + } return; } - public void _dspf(CommandInterpreter ci) { - this.discoverySpoofingEnabled = false; - ci.println("Discovery spoofing is disabled"); + public void _dsnp(CommandInterpreter ci) { + String val = ci.nextArgument(); + + if (val == null) { + ci.println("Usage: dsnp "); + } else if (val.equalsIgnoreCase("all")) { + this.discoverySnoopingEnabled = false; + ci.println("Discovery snooping is globally disabled"); + } else { + NodeConnector nodeConnector = NodeConnector.fromString(val); + if (nodeConnector != null) { + discoverySnoopingDisableList.add(nodeConnector); + ci.println("Discovery snooping is locally disabled on port " + + nodeConnector); + } else { + ci.println("Entered invalid NodeConnector " + val); + } + } return; } public void _spause(CommandInterpreter ci) { String val = ci.nextArgument(); String out = "Please enter pause period less than " - + discoveryBatchRestartTicks + ". Current pause period is " - + discoveryBatchPausePeriod + " pause tick is " - + discoveryBatchPauseTicks + "."; + + discoveryBatchRestartTicks + ". Current pause period is " + + discoveryBatchPausePeriod + " pause tick is " + + discoveryBatchPauseTicks + "."; if (val != null) { try { int pause = Integer.parseInt(val); if (pause < discoveryBatchRestartTicks) { - discoveryBatchPausePeriod = pause; - discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; + discoveryBatchPausePeriod = pause; + discoveryBatchPauseTicks = discoveryBatchRestartTicks + - discoveryBatchPausePeriod; return; } } catch (Exception e) { @@ -1114,19 +1197,20 @@ public class DiscoveryService implements IInventoryShimExternalListener, public void _sdi(CommandInterpreter ci) { String val = ci.nextArgument(); String out = "Please enter discovery interval greater than " - + discoveryBatchPausePeriod + ". Current value is " - + discoveryBatchRestartTicks + "."; + + discoveryBatchPausePeriod + ". Current value is " + + discoveryBatchRestartTicks + "."; if (val != null) { - try { - int restart = Integer.parseInt(val); - if (restart > discoveryBatchPausePeriod) { - discoveryBatchRestartTicks = restart; - discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; - return; - } - } catch (Exception e) { - } + try { + int restart = Integer.parseInt(val); + if (restart > discoveryBatchPausePeriod) { + discoveryBatchRestartTicks = restart; + discoveryBatchPauseTicks = discoveryBatchRestartTicks + - discoveryBatchPausePeriod; + return; + } + } catch (Exception e) { + } } ci.println(out); } @@ -1349,10 +1433,10 @@ public class DiscoveryService implements IInventoryShimExternalListener, portIdTlv.setType((byte) LLDPTLV.TLVType.PortID.getValue()); // Create LLDP TTL TLV - byte[] ttl = new byte[] { (byte) 120 }; + byte[] ttl = new byte[] { (byte) 0, (byte) 120 }; ttlTlv = new LLDPTLV(); - ttlTlv.setType((byte) LLDPTLV.TLVType.TTL.getValue()).setLength( - (short) ttl.length).setValue(ttl); + ttlTlv.setType((byte) LLDPTLV.TLVType.TTL.getValue()) + .setLength((short) ttl.length).setValue(ttl); customTlv = new LLDPTLV(); } @@ -1360,7 +1444,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init() { logger.trace("Init called"); @@ -1374,6 +1458,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, edgeMap = new ConcurrentHashMap(); agingMap = new ConcurrentHashMap(); prodMap = new ConcurrentHashMap(); + discoverySnoopingDisableList = new CopyOnWriteArrayList(); discoveryTimer = new Timer("DiscoveryService"); discoveryTimerTask = new DiscoveryTimerTask(); @@ -1389,7 +1474,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, * Function called by the dependency manager when at least one dependency * become unsatisfied or when the component is shutting down because for * example bundle is being stopped. - * + * */ void destroy() { transmitQ = null; @@ -1408,7 +1493,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, /** * Function called by dependency manager after "init ()" is called and after * the services provided by the class are registered in the service registry - * + * */ void start() { discoveryTimer.schedule(discoveryTimerTask, discoveryTimerTick, @@ -1417,8 +1502,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, } /** - * Function called after registering the - * service in OSGi service registry. + * Function called after registering the service in OSGi service registry. */ void started() { /* get a snapshot of all the existing switches */ @@ -1429,7 +1513,7 @@ public class DiscoveryService implements IInventoryShimExternalListener, * Function called by the dependency manager before the services exported by * the component are unregistered, this will be followed by a "destroy ()" * calls - * + * */ void stop() { shuttingDown = true; @@ -1463,16 +1547,76 @@ public class DiscoveryService implements IInventoryShimExternalListener, public void containerModeUpdated(UpdateType t) { // do nothing } - - private byte[] getSouceMACFromNodeID(String nodeId) { + + private byte[] getSouceMACFromNodeID(String nodeId) { byte[] cid = HexEncode.bytesFromHexString(nodeId); byte[] sourceMac = new byte[6]; int pos = cid.length - sourceMac.length; if (pos >= 0) { - System.arraycopy(cid, pos, sourceMac, 0, sourceMac.length); + System.arraycopy(cid, pos, sourceMac, 0, sourceMac.length); } - + return sourceMac; } + + /** + * This method returns the interval which determines how often the discovery + * packets will be sent. Default is 300 seconds. + * + * @return The discovery interval in second + */ + private int getDiscoveryInterval() { + String elapsedTime = System.getProperty("of.discoveryInterval"); + int rv = 300; + + try { + if (elapsedTime != null) { + rv = Integer.parseInt(elapsedTime); + } + } catch (Exception e) { + } + + return rv; + } + + /** + * This method returns the timeout value in waiting for response of a + * discovery query. Default is 60 seconds. + * + * @return The discovery timeout in second + */ + private int getDiscoveryTimeout() { + String elapsedTime = System.getProperty("of.discoveryTimeout"); + int rv = 60; + + try { + if (elapsedTime != null) { + rv = Integer.parseInt(elapsedTime); + } + } catch (Exception e) { + } + + return rv; + } + + /** + * This method returns the number of retries after the initial discovery + * packet is not received within the timeout period. Default is 2 times. + * + * @return The number of discovery retries + */ + private int getDiscoveryRetry() { + String retry = System.getProperty("of.discoveryRetry"); + int rv = 2; + + if (retry != null) { + try { + rv = Integer.parseInt(retry); + } catch (Exception e) { + } + } + + return rv; + } }