diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index c4f502236253db5c3463ab6ae66be4f66dd26b9e..5f9cbd81d9153ef73ecc302094e10a7f2e513a10 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -1446,6 +1446,7 @@ public class Controller implements IFloodlightProviderService, @Override public Map<Long, IOFSwitch> getSwitches() { + if (activeSwitches == null) return null; return Collections.unmodifiableMap(this.activeSwitches); } diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java index f172f63be26459ce241e0c4400a3e63885b5bed4..17ad46a7a067c827605d64df3a4acb9443349233 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/ILinkDiscovery.java @@ -13,13 +13,15 @@ public interface ILinkDiscovery { SWITCH_UPDATED("Switch Updated"), SWITCH_REMOVED("Switch Removed"), PORT_UP("Port Up"), - PORT_DOWN("Port Down"); - + PORT_DOWN("Port Down"), + TUNNEL_PORT_ADDED("Tunnel Port Added"), + TUNNEL_PORT_REMOVED("Tunnel Port Removed"); + private String value; UpdateOperation(String v) { value = v; } - + @Override public String toString() { return value; @@ -64,7 +66,7 @@ public interface ILinkDiscovery { this.srcType = stype; } - // For port up or port down. + // For port up or port down; and tunnel port added and removed. public LDUpdate(long sw, short port, UpdateOperation operation) { this.src = sw; this.srcPort = port; diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java index 9ded18add8aa7c949d03c7e0f32d39fa66c942cd..24dd4442584015900fa3adfc991f42851fcd52f8 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java @@ -188,7 +188,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, * to false -- Initialized in the init method as well. */ public final boolean AUTOPORTFAST_DEFAULT = false; - boolean autoPortFastFeature = AUTOPORTFAST_DEFAULT; + protected boolean autoPortFastFeature = AUTOPORTFAST_DEFAULT; /** * Map from link to the most recent time it was verified functioning @@ -349,7 +349,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, } while (updates.peek() != null); } - private boolean isLinkDiscoverySuppressed(long sw, short portNumber) { + protected boolean isLinkDiscoverySuppressed(long sw, short portNumber) { return this.suppressLinkDiscovery.contains(new NodePortTuple(sw, portNumber)); } @@ -518,6 +518,94 @@ public class LinkDiscoveryManager implements IOFMessageListener, sendDiscoveryMessage(sw, port, true, false); } + /** + * Check if incoming discovery messages are enabled or not. + * @param sw + * @param port + * @param isStandard + * @return + */ + protected boolean isIncomingDiscoveryAllowed(long sw, short port, + boolean isStandard) { + + if (isLinkDiscoverySuppressed(sw, port)) { + /* Do not process LLDPs from this port as suppressLLDP is set */ + return false; + } + + IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + if (iofSwitch == null) { + return false; + } + + if (port == OFPort.OFPP_LOCAL.getValue()) return false; + + OFPhysicalPort ofpPort = iofSwitch.getPort(port); + if (ofpPort == null) { + if (log.isTraceEnabled()) { + log.trace("Null physical port. sw={}, port={}", + HexString.toHexString(sw), port); + } + return false; + } + + return true; + } + + /** + * Check if outgoing discovery messages are enabled or not. + * @param sw + * @param port + * @param isStandard + * @param isReverse + * @return + */ + protected boolean isOutgoingDiscoveryAllowed(long sw, short port, + boolean isStandard, + boolean isReverse) { + + if (isLinkDiscoverySuppressed(sw, port)) { + /* Dont send LLDPs out of this port as suppressLLDP is set */ + return false; + } + + IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + if (iofSwitch == null) { + return false; + } + + if (port == OFPort.OFPP_LOCAL.getValue()) return false; + + OFPhysicalPort ofpPort = iofSwitch.getPort(port); + if (ofpPort == null) { + if (log.isTraceEnabled()) { + log.trace("Null physical port. sw={}, port={}", + HexString.toHexString(sw), port); + } + return false; + } + + // For fast ports, do not send forward LLDPs or BDDPs. + if (!isReverse && autoPortFastFeature && iofSwitch.isFastPort(port)) + return false; + return true; + } + + /** + * Get the actions for packet-out corresponding to a specific port. + * This is a placeholder for adding actions if any port-specific + * actions are desired. The default action is simply to output to + * the given port. + * @param port + * @return + */ + protected List<OFAction> getDiscoveryActions (short port){ + // set actions + List<OFAction> actions = new ArrayList<OFAction>(); + actions.add(new OFActionOutput(port, (short) 0)); + return actions; + } + /** * Send link discovery message out of a given switch port. The discovery * message may be a standard LLDP or a modified LLDP, where the dst mac @@ -540,34 +628,13 @@ public class LinkDiscoveryManager implements IOFMessageListener, void sendDiscoveryMessage(long sw, short port, boolean isStandard, boolean isReverse) { - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); - if (iofSwitch == null) { + // Takes care of all checks including null pointer checks. + if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse)) return; - } - - if (port == OFPort.OFPP_LOCAL.getValue()) return; + IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); OFPhysicalPort ofpPort = iofSwitch.getPort(port); - if (ofpPort == null) { - if (log.isTraceEnabled()) { - log.trace("Null physical port. sw={}, port={}", - HexString.toHexString(sw), port); - } - return; - } - - if (isLinkDiscoverySuppressed(sw, port)) { - /* Dont send LLDPs out of this port as suppressLLDPs set - * - */ - return; - } - - // For fast ports, do not send forward LLDPs or BDDPs. - if (!isReverse && autoPortFastFeature && iofSwitch.isFastPort(port)) - return; - if (log.isTraceEnabled()) { log.trace("Sending LLDP packet out of swich: {}, port: {}", HexString.toHexString(sw), port); @@ -664,9 +731,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, po.setBufferId(OFPacketOut.BUFFER_ID_NONE); po.setInPort(OFPort.OFPP_NONE); - // set actions - List<OFAction> actions = new ArrayList<OFAction>(); - actions.add(new OFActionOutput(port, (short) 0)); + List<OFAction> actions = getDiscoveryActions(port); po.setActions(actions); po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH); @@ -787,17 +852,9 @@ public class LinkDiscoveryManager implements IOFMessageListener, boolean isStandard, FloodlightContext cntx) { // If LLDP is suppressed on this port, ignore received packet as well IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); - if (iofSwitch == null) { - return Command.STOP; - } - if (isLinkDiscoverySuppressed(sw, pi.getInPort())) { - if (log.isTraceEnabled()) { - log.trace("Got a LLDP=[{}] from a supressed switchport sw = {}, port = {}. Not fowarding it.", - new Object[] {lldp.toString(), HexString.toHexString(sw), pi.getInPort()}); - } + if (!isIncomingDiscoveryAllowed(sw, pi.getInPort(), isStandard)) return Command.STOP; - } // If this is a malformed LLDP, or not from us, exit if (lldp.getPortId() == null || lldp.getPortId().getLength() != 3) { @@ -2227,4 +2284,4 @@ public class LinkDiscoveryManager implements IOFMessageListener, else log.info("Setting autoportfast feature to OFF"); } -} +} \ No newline at end of file diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java index 8b498af5c5d11f7b9edc6ab2b816cde076a1ff76..cd0cd36925bea52c881ab497b7f35a93a39b5168 100644 --- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java +++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java @@ -336,60 +336,6 @@ public abstract class ForwardingBase "packet out to a switch", recommendation=LogMessageDoc.CHECK_SWITCH) }) - public void pushPacket(IPacket packet, - IOFSwitch sw, - int bufferId, - short inPort, - short outPort, - FloodlightContext cntx, - boolean flush) { - - - if (log.isTraceEnabled()) { - log.trace("PacketOut srcSwitch={} inPort={} outPort={}", - new Object[] {sw, inPort, outPort}); - } - - OFPacketOut po = - (OFPacketOut) floodlightProvider.getOFMessageFactory() - .getMessage(OFType.PACKET_OUT); - - // set actions - List<OFAction> actions = new ArrayList<OFAction>(); - actions.add(new OFActionOutput(outPort, (short) 0xffff)); - - po.setActions(actions) - .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH); - short poLength = - (short) (po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH); - - // set buffer_id, in_port - po.setBufferId(bufferId); - po.setInPort(inPort); - - // set data - only if buffer_id == -1 - if (po.getBufferId() == OFPacketOut.BUFFER_ID_NONE) { - if (packet == null) { - log.error("BufferId is not set and packet data is null. " + - "Cannot send packetOut. " + - "srcSwitch={} inPort={} outPort={}", - new Object[] {sw, inPort, outPort}); - return; - } - byte[] packetData = packet.serialize(); - poLength += packetData.length; - po.setPacketData(packetData); - } - - po.setLength(poLength); - - try { - counterStore.updatePktOutFMCounterStoreLocal(sw, po); - messageDamper.write(sw, po, cntx, flush); - } catch (IOException e) { - log.error("Failure writing packet out", e); - } - } /** * Pushes a packet-out to a switch. The assumption here is that diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java index 4f8ad79aac14af53901b0debe3d7f165f9119428..490c50ecb7d6d971368bc50d319e075d679f7faf 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java @@ -5,11 +5,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -29,18 +29,15 @@ import net.floodlightcontroller.core.module.IFloodlightService; import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.staticflowentry.web.StaticFlowEntryWebRoutable; -import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService; import net.floodlightcontroller.storage.IResultSet; -import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.IStorageSourceListener; - +import net.floodlightcontroller.storage.IStorageSourceService; import net.floodlightcontroller.storage.StorageException; import org.openflow.protocol.OFFlowMod; import org.openflow.protocol.OFFlowRemoved; import org.openflow.protocol.OFMatch; import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPort; import org.openflow.protocol.OFType; import org.openflow.util.HexString; import org.openflow.util.U16; @@ -653,6 +650,16 @@ public class StaticFlowEntryPusher @Override public void deleteAllFlows() { + for (String entry : entry2dpid.keySet()) { + deleteFlow(entry); + } + + /* + FIXME: Since the OF spec 1.0 is not clear on how + to match on cookies. Once all switches come to a + common implementation we can possibly re-enable this + fix. + // Send a delete for each switch Set<String> swSet = new HashSet<String>(); for (String dpid : entry2dpid.values()) { @@ -673,11 +680,24 @@ public class StaticFlowEntryPusher // Reset our DB storageSource.deleteMatchingRowsAsync(TABLE_NAME, null); + */ } @Override public void deleteFlowsForSwitch(long dpid) { - sendDeleteByCookie(dpid); + String sDpid = HexString.toHexString(dpid); + + for (Entry<String, String> e : entry2dpid.entrySet()) { + if (e.getValue().equals(sDpid)) + deleteFlow(e.getKey()); + } + + /* + FIXME: Since the OF spec 1.0 is not clear on how + to match on cookies. Once all switches come to a + common implementation we can possibly re-enable this + fix. + //sendDeleteByCookie(dpid); String sDpid = HexString.toHexString(dpid); // Clear all internal flows for this switch @@ -692,6 +712,7 @@ public class StaticFlowEntryPusher } else { log.warn("Map of storage entries for switch {} was null", sDpid); } + */ } /** @@ -701,6 +722,11 @@ public class StaticFlowEntryPusher * disable having flow specific cookies. * @param dpid The DPID of the switch to clear all it's flows. */ + /* + FIXME: Since the OF spec 1.0 is not clear on how + to match on cookies. Once all switches come to a + common implementation we can possibly re-enable this + fix. private void sendDeleteByCookie(long dpid) { if (log.isDebugEnabled()) log.debug("Deleting all static flows on switch {}", HexString.toHexString(dpid)); @@ -729,6 +755,7 @@ public class StaticFlowEntryPusher return; } } + */ @Override public Map<String, Map<String, OFFlowMod>> getFlows() { diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java index 81a497cde444f0cab42a934a9c62eb61ed702291..5eacd5895d2c194062d26a0de3fbb7d247153de5 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java @@ -89,7 +89,7 @@ public class TopologyManager implements /** * set of tunnel links */ - protected Map<NodePortTuple, Set<Link>> tunnelLinks; + protected Set<NodePortTuple> tunnelPorts; protected ILinkDiscoveryService linkDiscovery; protected IThreadPoolService threadPool; @@ -492,10 +492,9 @@ public class TopologyManager implements @Override public Set<NodePortTuple> getTunnelPorts() { - return tunnelLinks.keySet(); + return tunnelPorts; } - @Override public Set<NodePortTuple> getBlockedPorts() { Set<NodePortTuple> bp; Set<NodePortTuple> blockedPorts = @@ -679,7 +678,7 @@ public class TopologyManager implements switchPortLinks = new HashMap<NodePortTuple, Set<Link>>(); directLinks = new HashMap<NodePortTuple, Set<Link>>(); portBroadcastDomainLinks = new HashMap<NodePortTuple, Set<Link>>(); - tunnelLinks = new HashMap<NodePortTuple, Set<Link>>(); + tunnelPorts = new HashSet<NodePortTuple>(); topologyAware = new ArrayList<ITopologyListener>(); ldUpdates = new LinkedBlockingQueue<LDUpdate>(); appliedUpdates = new ArrayList<LDUpdate>(); @@ -800,6 +799,27 @@ public class TopologyManager implements } } + /** + * Get the set of ports to eliminate for sending out BDDP. The method + * returns all the ports that are suppressed for link discovery on the + * switch. + * packets. + * @param sid + * @return + */ + protected Set<Short> getPortsToEliminateForBDDP(long sid) { + Set<NodePortTuple> suppressedNptList = linkDiscovery.getSuppressLLDPsInfo(); + if (suppressedNptList == null) return null; + + Set<Short> resultPorts = new HashSet<Short>(); + for(NodePortTuple npt: suppressedNptList) { + if (npt.getNodeId() == sid) { + resultPorts.add(npt.getPortId()); + } + } + + return resultPorts; + } /** * The BDDP packets are forwarded out of all the ports out of an @@ -848,6 +868,11 @@ public class TopologyManager implements } } + Set<Short> portsToEliminate = getPortsToEliminateForBDDP(sid); + if (portsToEliminate != null) { + ports.removeAll(portsToEliminate); + } + // remove the incoming switch port if (pinSwitch == sid) { ports.remove(pi.getInPort()); @@ -914,12 +939,26 @@ public class TopologyManager implements } else if (update.getOperation() == UpdateOperation.LINK_REMOVED){ removeLink(update.getSrc(), update.getSrcPort(), update.getDst(), update.getDstPort()); + } else if (update.getOperation() == UpdateOperation.TUNNEL_PORT_ADDED) { + addTunnelPort(update.getSrc(), update.getSrcPort()); + } else if (update.getOperation() == UpdateOperation.TUNNEL_PORT_REMOVED) { + removeTunnelPort(update.getSrc(), update.getSrcPort()); } // Add to the list of applied updates. appliedUpdates.add(update); } } + public void addTunnelPort(long sw, short port) { + NodePortTuple npt = new NodePortTuple(sw, port); + tunnelPorts.add(npt); + } + + public void removeTunnelPort(long sw, short port) { + NodePortTuple npt = new NodePortTuple(sw, port); + tunnelPorts.remove(npt); + } + /** * This function computes a new topology. */ @@ -962,7 +1001,7 @@ public class TopologyManager implements } // Remove all tunnel links. - for(NodePortTuple npt: tunnelLinks.keySet()) { + for(NodePortTuple npt: tunnelPorts) { if (switchPortLinks.get(npt) == null) continue; for(Link link: switchPortLinks.get(npt)) { removeLinkFromStructure(openflowLinks, link); @@ -973,7 +1012,7 @@ public class TopologyManager implements blockedPorts, openflowLinks, broadcastDomainPorts, - tunnelLinks.keySet()); + tunnelPorts); nt.compute(); // We set the instances with and without tunnels to be identical. // If needed, we may compute them differently. @@ -1146,8 +1185,6 @@ public class TopologyManager implements public void addOrUpdateLink(long srcId, short srcPort, long dstId, short dstPort, LinkType type) { - boolean flag1 = false, flag2 = false; - Link link = new Link(srcId, srcPort, dstId, dstPort); addPortToSwitch(srcId, srcPort); addPortToSwitch(dstId, dstPort); @@ -1156,17 +1193,9 @@ public class TopologyManager implements if (type.equals(LinkType.MULTIHOP_LINK)) { addLinkToStructure(portBroadcastDomainLinks, link); - flag1 = removeLinkFromStructure(tunnelLinks, link); - flag2 = removeLinkFromStructure(directLinks, link); - dtLinksUpdated = flag1 || flag2; - } else if (type.equals(LinkType.TUNNEL)) { - addLinkToStructure(tunnelLinks, link); - removeLinkFromStructure(portBroadcastDomainLinks, link); - removeLinkFromStructure(directLinks, link); - dtLinksUpdated = true; + dtLinksUpdated = removeLinkFromStructure(directLinks, link); } else if (type.equals(LinkType.DIRECT_LINK)) { addLinkToStructure(directLinks, link); - removeLinkFromStructure(tunnelLinks, link); removeLinkFromStructure(portBroadcastDomainLinks, link); dtLinksUpdated = true; } @@ -1174,14 +1203,8 @@ public class TopologyManager implements } public void removeLink(Link link) { - boolean flag1 = false, flag2 = false; - - flag1 = removeLinkFromStructure(directLinks, link); - flag2 = removeLinkFromStructure(tunnelLinks, link); - linksUpdated = true; - dtLinksUpdated = flag1 || flag2; - + dtLinksUpdated = removeLinkFromStructure(directLinks, link); removeLinkFromStructure(portBroadcastDomainLinks, link); removeLinkFromStructure(switchPortLinks, link); @@ -1219,9 +1242,9 @@ public class TopologyManager implements public void clear() { switchPorts.clear(); + tunnelPorts.clear(); switchPortLinks.clear(); portBroadcastDomainLinks.clear(); - tunnelLinks.clear(); directLinks.clear(); appliedUpdates.clear(); } diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java index aaeea904f0b9fff519e9a60fd7920c0400d528a9..59f3090457561b8e51eea89ce0006801eed43e73 100644 --- a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java +++ b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java @@ -108,6 +108,7 @@ public class TopologyInstanceTest { } TopologyInstance ti = topologyManager.getCurrentInstance(tunnelsEnabled); Set<NodePortTuple> computed = ti.getBroadcastNodePortsInCluster(npt.nodeId); + log.info("computed: {}", computed); if (computed != null) assertTrue(computed.equals(expected)); else if (computed == null) @@ -295,120 +296,6 @@ public class TopologyInstanceTest { verifyExpectedBroadcastPortsInClusters(expectedBroadcastPorts); } - @Test - public void testTunnelLinkDeletion() throws Exception { - - // +-------+ +-------+ - // | | | | - // | 1 1|-------------|1 2 | - // | 2 | | 2 | - // +-------+ +-------+ - // | | - // | | - // +-------+ | - // | 1 | | - // | 3 2|-----------------+ - // | 3 | - // +-------+ - // - // - // +-------+ - // | 1 | - // | 4 2|----------------+ - // | 3 | | - // +-------+ | - // | | - // | | - // +-------+ +-------+ - // | 1 | | 2 | - // | 5 2|-------------|1 6 | - // | | | | - // +-------+ +-------+ - { - int [][] linkArray = { - {1, 1, 2, 1, DIRECT_LINK}, - {2, 1, 1, 1, DIRECT_LINK}, - {1, 2, 3, 1, TUNNEL_LINK}, - {3, 1, 1, 2, TUNNEL_LINK}, - {2, 2, 3, 2, TUNNEL_LINK}, - {3, 2, 2, 2, TUNNEL_LINK}, - - {4, 2, 6, 2, DIRECT_LINK}, - {6, 2, 4, 2, DIRECT_LINK}, - {4, 3, 5, 1, TUNNEL_LINK}, - {5, 1, 4, 3, TUNNEL_LINK}, - {5, 2, 6, 1, TUNNEL_LINK}, - {6, 1, 5, 2, TUNNEL_LINK}, - - }; - - int [][] expectedClusters = { - {1, 2}, - {4, 6}, - }; - int [][][] expectedBroadcastPorts = { - {{1,1}, {2,1}}, - {{4,2}, {6,2}} - }; - - createTopologyFromLinks(linkArray); - topologyManager.createNewInstance(); - verifyClusters(expectedClusters, false); - verifyExpectedBroadcastPortsInClusters(expectedBroadcastPorts, false); - } - - // +-------+ +-------+ - // | | TUNNEL | | - // | 1 1|-------------|1 2 | - // | 2 | | 2 | - // +-------+ +-------+ - // | | - // | | - // +-------+ | - // | 1 | | - // | 3 2|-----------------+ - // | 3 | - // +-------+ - // | - // | TUNNEL - // | - // +-------+ - // | 1 | TUNNEL - // | 4 2|----------------+ - // | 3 | | - // +-------+ | - // | | - // | | - // +-------+ +-------+ - // | 1 | | 2 | - // | 5 2|-------------|1 6 | - // | | | | - // +-------+ +-------+ - - { - int [][] linkArray = { - {3, 3, 4, 1, TUNNEL_LINK}, - {4, 1, 3, 3, TUNNEL_LINK}, - - }; - int [][] expectedClusters = { - {1, 2}, - {4, 6}, - {3}, - {5}, - }; - int [][][] expectedBroadcastPorts = { - {{1,1}, {2,1}}, - {{4,2}, {6,2}} - }; - - createTopologyFromLinks(linkArray); - topologyManager.createNewInstance(); - verifyClusters(expectedClusters, false); - verifyExpectedBroadcastPortsInClusters(expectedBroadcastPorts, false); - } - } - @Test public void testLoopDetectionWithIslands() throws Exception { @@ -440,15 +327,15 @@ public class TopologyInstanceTest { // +-------+ +-------+ { int [][] linkArray = { - {1, 1, 2, 1, TUNNEL_LINK}, - {2, 1, 1, 1, TUNNEL_LINK}, + {1, 1, 2, 1, DIRECT_LINK}, + {2, 1, 1, 1, DIRECT_LINK}, {1, 2, 3, 1, DIRECT_LINK}, {3, 1, 1, 2, DIRECT_LINK}, {2, 2, 3, 2, DIRECT_LINK}, {3, 2, 2, 2, DIRECT_LINK}, - {4, 2, 6, 2, TUNNEL_LINK}, - {6, 2, 4, 2, TUNNEL_LINK}, + {4, 2, 6, 2, DIRECT_LINK}, + {6, 2, 4, 2, DIRECT_LINK}, {4, 3, 5, 1, DIRECT_LINK}, {5, 1, 4, 3, DIRECT_LINK}, {5, 2, 6, 1, DIRECT_LINK}, @@ -461,8 +348,8 @@ public class TopologyInstanceTest { {4, 5, 6} }; int [][][] expectedBroadcastPorts = { - {{1,2}, {3,1}, {2,2}, {3,2}}, - {{4,3}, {5,1}, {5,2}, {6,1}}, + {{1,1}, {2,1}, {1,2}, {3,1}}, + {{4,3}, {5,1}, {4,2}, {6,2}}, }; createTopologyFromLinks(linkArray); @@ -501,17 +388,17 @@ public class TopologyInstanceTest { { int [][] linkArray = { - {3, 3, 4, 1, TUNNEL_LINK}, - {4, 1, 3, 3, TUNNEL_LINK}, + {3, 3, 4, 1, DIRECT_LINK}, + {4, 1, 3, 3, DIRECT_LINK}, }; int [][] expectedClusters = { - {1, 2, 3}, - {4, 5, 6} + {1, 2, 3, 4, 5, 6} }; int [][][] expectedBroadcastPorts = { - {{1,2}, {3,1}, {2,2}, {3,2}}, - {{4,3}, {5,1}, {5,2}, {6,1}}, + {{1,1}, {2,1}, {1,2}, {3,1}, + {3,3}, {4,1}, {4,3}, {5,1}, + {4,2}, {6,2}}, }; createTopologyFromLinks(linkArray); diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java index 113cecbaea0492d36831d1221ad9c1e904c59891..913bf83a96fa0c6a8613572624da2a8ec1a55fec 100644 --- a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java +++ b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java @@ -50,78 +50,54 @@ public class TopologyManagerTest extends FloodlightTestCase { assertTrue(tm.getPortBroadcastDomainLinks().size()==2); assertTrue(tm.getTunnelPorts().size()==0); - tm.addOrUpdateLink((long)1, (short)3, (long)2, (short)3, ILinkDiscovery.LinkType.TUNNEL); - assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. - assertTrue(tm.getSwitchPorts().get((long)1).size()==3); - assertTrue(tm.getSwitchPorts().get((long)2).size()==3); - assertTrue(tm.getSwitchPortLinks().size()==6); - assertTrue(tm.getPortBroadcastDomainLinks().size()==2); - assertTrue(tm.getTunnelPorts().size()==2); - tm.removeLink((long)1, (short)2, (long)2, (short)2); - log.info("# of switchports. {}", tm.getSwitchPorts().get((long)1).size()); - assertTrue(tm.getSwitchPorts().get((long)1).size()==2); - assertTrue(tm.getSwitchPorts().get((long)2).size()==2); - assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. - assertTrue(tm.getSwitchPortLinks().size()==4); - assertTrue(tm.getPortBroadcastDomainLinks().size()==0); - assertTrue(tm.getTunnelPorts().size()==2); - - tm.removeLink((long)1, (short)1, (long)2, (short)1); - assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. assertTrue(tm.getSwitchPorts().get((long)1).size()==1); assertTrue(tm.getSwitchPorts().get((long)2).size()==1); + assertTrue(tm.getSwitchPorts().size() == 2); assertTrue(tm.getSwitchPortLinks().size()==2); assertTrue(tm.getPortBroadcastDomainLinks().size()==0); - assertTrue(tm.getTunnelPorts().size()==2); - tm.removeLink((long)1, (short)3, (long)2, (short)3); + tm.removeLink((long)1, (short)1, (long)2, (short)1); assertTrue(tm.getSwitchPorts().size() == 0); assertTrue(tm.getSwitchPortLinks().size()==0); assertTrue(tm.getPortBroadcastDomainLinks().size()==0); - assertTrue(tm.getTunnelPorts().size()==0); } @Test public void testBasic2() throws Exception { tm.addOrUpdateLink((long)1, (short)1, (long)2, (short)1, ILinkDiscovery.LinkType.DIRECT_LINK); tm.addOrUpdateLink((long)2, (short)2, (long)3, (short)1, ILinkDiscovery.LinkType.MULTIHOP_LINK); - tm.addOrUpdateLink((long)3, (short)2, (long)1, (short)2, ILinkDiscovery.LinkType.TUNNEL); assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. - assertTrue(tm.getSwitchPorts().get((long)1).size()==2); + assertTrue(tm.getSwitchPorts().get((long)1).size()==1); assertTrue(tm.getSwitchPorts().get((long)2).size()==2); - assertTrue(tm.getSwitchPorts().get((long)3).size()==2); - assertTrue(tm.getSwitchPortLinks().size()==6); + assertTrue(tm.getSwitchPorts().get((long)3).size()==1); + assertTrue(tm.getSwitchPortLinks().size()==4); assertTrue(tm.getPortBroadcastDomainLinks().size()==2); - assertTrue(tm.getTunnelPorts().size()==2); tm.removeLink((long)1, (short)1, (long)2, (short)1); - assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. - assertTrue(tm.getSwitchPorts().get((long)1).size()==1); + assertTrue(tm.getSwitchPorts().size() == 2); + assertTrue(tm.getSwitchPorts().get((long)1) == null); assertTrue(tm.getSwitchPorts().get((long)2).size()==1); - assertTrue(tm.getSwitchPorts().get((long)3).size()==2); - assertTrue(tm.getSwitchPortLinks().size()==4); + assertTrue(tm.getSwitchPorts().get((long)3).size()==1); + assertTrue(tm.getSwitchPortLinks().size()==2); assertTrue(tm.getPortBroadcastDomainLinks().size()==2); - assertTrue(tm.getTunnelPorts().size()==2); // nonexistent link // no null pointer exceptions. tm.removeLink((long)3, (short)1, (long)2, (short)2); - assertTrue(tm.getSwitchPorts().size() == 3); // for two nodes. - assertTrue(tm.getSwitchPorts().get((long)1).size()==1); + assertTrue(tm.getSwitchPorts().size() == 2); + assertTrue(tm.getSwitchPorts().get((long)1) == null); assertTrue(tm.getSwitchPorts().get((long)2).size()==1); - assertTrue(tm.getSwitchPorts().get((long)3).size()==2); - assertTrue(tm.getSwitchPortLinks().size()==4); + assertTrue(tm.getSwitchPorts().get((long)3).size()==1); + assertTrue(tm.getSwitchPortLinks().size()==2); assertTrue(tm.getPortBroadcastDomainLinks().size()==2); - assertTrue(tm.getTunnelPorts().size()==2); tm.removeLink((long)3, (short)2, (long)1, (short)2); - assertTrue(tm.getSwitchPorts().size() == 2); // for two nodes. + assertTrue(tm.getSwitchPorts().size() == 2); assertTrue(tm.getSwitchPorts().get((long)1)==null); assertTrue(tm.getSwitchPorts().get((long)2).size()==1); assertTrue(tm.getSwitchPorts().get((long)3).size()==1); assertTrue(tm.getSwitchPortLinks().size()==2); assertTrue(tm.getPortBroadcastDomainLinks().size()==2); - assertTrue(tm.getTunnelPorts().size()==0); tm.removeLink((long)2, (short)2, (long)3, (short)1); assertTrue(tm.getSwitchPorts().size() == 0); // for two nodes. @@ -137,6 +113,6 @@ public class TopologyManagerTest extends FloodlightTestCase { assert(tm.switchPorts.isEmpty()); assert(tm.switchPortLinks.isEmpty()); assert(tm.portBroadcastDomainLinks.isEmpty()); - assert(tm.tunnelLinks.isEmpty()); + assert(tm.tunnelPorts.isEmpty()); } }