@Test public void testMultipleLinkPortDownReconciliation() throws Exception { log.debug("Starting multiple link port down reconciliation test"); switches = new HashMap<Long, IOFSwitch>(); switches.put(1L, sw1); switches.put(2L, sw2); switches.put(3L, sw3); switches.put(4L, sw4); mockFloodlightProvider.setSwitches(switches); Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>(); Link link = new Link(2L, (short) 3, 1L, (short) 1); Link link2 = new Link(3L, (short) 3, 1L, (short) 1); Link link3 = new Link(4L, (short) 3, 1L, (short) 1); LinkInfo linkinfo = null; links.put(link, linkinfo); links.put(link2, linkinfo); links.put(link3, linkinfo); expect(lds.getLinks()).andReturn(links).anyTimes(); replay(lds); pdr.reconcileFlows(lofmr); verify(sw1, sw2, sw3, sw4); assertTrue(wc2.hasCaptured()); assertTrue(wc3.hasCaptured()); assertTrue(wc4.hasCaptured()); List<OFMessage> msglist = wc2.getValues().get(0); for (OFMessage m : msglist) { if (m instanceof OFFlowMod) assertEquals(fm2, m); } msglist = wc3.getValues().get(0); for (OFMessage m : msglist) { if (m instanceof OFFlowMod) assertEquals(fm2, m); } msglist = wc4.getValues().get(0); for (OFMessage m : msglist) { if (m instanceof OFFlowMod) assertEquals(fm2, m); } }
@Override public net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { if (lds != null) { links = new HashMap<Link, LinkInfo>(); if (lds.getLinks() != null) links.putAll(lds.getLinks()); for (OFMatchReconcile ofmr : ofmRcList) { if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { IOFSwitch sw = floodlightProvider .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); Map<Short, List<OFMatch>> invalidBaseIngressAndMatches = new HashMap<Short, List<OFMatch>>(); List<OFFlowStatisticsReply> flows = getFlows(sw, ofmr.outPort); for (OFFlowStatisticsReply flow : flows) { OFMatch match = flow.getMatch(); if (invalidBaseIngressAndMatches.containsKey(match.getInputPort())) invalidBaseIngressAndMatches.get(match.getInputPort()) .add(match); else { List<OFMatch> matches = new ArrayList<OFMatch>(); matches.add(match); invalidBaseIngressAndMatches.put(match.getInputPort(), matches); } } if (!flows.isEmpty()) { log.debug("Removing flows on switch : " + sw.getId() + " with outport: " + ofmr.outPort); clearFlowMods(sw, ofmr.outPort); } Map<IOFSwitch, Map<Short, List<OFMatch>>> neighborSwitches = new HashMap<IOFSwitch, Map<Short, List<OFMatch>>>(); for (Link link : links.keySet()) { if (link.getDst() == sw.getId()) { for (Entry<Short, List<OFMatch>> invalidBaseIngressAndMatch : invalidBaseIngressAndMatches.entrySet()) { if (link.getDstPort() == invalidBaseIngressAndMatch.getKey()) { Map<Short, List<OFMatch>> invalidNeighborOutportAndMatch = new HashMap<Short, List<OFMatch>>(); invalidNeighborOutportAndMatch.put(link.getSrcPort(), invalidBaseIngressAndMatch.getValue()); neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } } } log.debug("We have " + neighborSwitches.size() + " neighboring switches to deal with!"); for (IOFSwitch neighborSwitch : neighborSwitches.keySet()) { log.debug("NeighborSwitch ID : " + neighborSwitch.getId()); if (neighborSwitches.get(neighborSwitch) != null) deleteInvalidFlows(neighborSwitch, neighborSwitches.get(neighborSwitch)); } } return Command.CONTINUE; } } else { log.error("Link Discovery Service Is Null"); } return Command.CONTINUE; }
PortDownReconciliation implements IFloodlightModule,
    ITopologyListener, IFlowReconcileListener { @Override public net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { if (lds != null) { links = new HashMap<Link, LinkInfo>(); if (lds.getLinks() != null) links.putAll(lds.getLinks()); for (OFMatchReconcile ofmr : ofmRcList) { if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { IOFSwitch sw = floodlightProvider .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); Map<Short, List<OFMatch>> invalidBaseIngressAndMatches = new HashMap<Short, List<OFMatch>>(); List<OFFlowStatisticsReply> flows = getFlows(sw, ofmr.outPort); for (OFFlowStatisticsReply flow : flows) { OFMatch match = flow.getMatch(); if (invalidBaseIngressAndMatches.containsKey(match.getInputPort())) invalidBaseIngressAndMatches.get(match.getInputPort()) .add(match); else { List<OFMatch> matches = new ArrayList<OFMatch>(); matches.add(match); invalidBaseIngressAndMatches.put(match.getInputPort(), matches); } } if (!flows.isEmpty()) { log.debug("Removing flows on switch : " + sw.getId() + " with outport: " + ofmr.outPort); clearFlowMods(sw, ofmr.outPort); } Map<IOFSwitch, Map<Short, List<OFMatch>>> neighborSwitches = new HashMap<IOFSwitch, Map<Short, List<OFMatch>>>(); for (Link link : links.keySet()) { if (link.getDst() == sw.getId()) { for (Entry<Short, List<OFMatch>> invalidBaseIngressAndMatch : invalidBaseIngressAndMatches.entrySet()) { if (link.getDstPort() == invalidBaseIngressAndMatch.getKey()) { Map<Short, List<OFMatch>> invalidNeighborOutportAndMatch = new HashMap<Short, List<OFMatch>>(); invalidNeighborOutportAndMatch.put(link.getSrcPort(), invalidBaseIngressAndMatch.getValue()); neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } } } log.debug("We have " + neighborSwitches.size() + " neighboring switches to deal with!"); for (IOFSwitch neighborSwitch : neighborSwitches.keySet()) { log.debug("NeighborSwitch ID : " + neighborSwitch.getId()); if (neighborSwitches.get(neighborSwitch) != null) deleteInvalidFlows(neighborSwitch, neighborSwitches.get(neighborSwitch)); } } return Command.CONTINUE; } } else { log.error("Link Discovery Service Is Null"); } return Command.CONTINUE; } }
PortDownReconciliation implements IFloodlightModule,
    ITopologyListener, IFlowReconcileListener { @Override public net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { if (lds != null) { links = new HashMap<Link, LinkInfo>(); if (lds.getLinks() != null) links.putAll(lds.getLinks()); for (OFMatchReconcile ofmr : ofmRcList) { if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { IOFSwitch sw = floodlightProvider .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); Map<Short, List<OFMatch>> invalidBaseIngressAndMatches = new HashMap<Short, List<OFMatch>>(); List<OFFlowStatisticsReply> flows = getFlows(sw, ofmr.outPort); for (OFFlowStatisticsReply flow : flows) { OFMatch match = flow.getMatch(); if (invalidBaseIngressAndMatches.containsKey(match.getInputPort())) invalidBaseIngressAndMatches.get(match.getInputPort()) .add(match); else { List<OFMatch> matches = new ArrayList<OFMatch>(); matches.add(match); invalidBaseIngressAndMatches.put(match.getInputPort(), matches); } } if (!flows.isEmpty()) { log.debug("Removing flows on switch : " + sw.getId() + " with outport: " + ofmr.outPort); clearFlowMods(sw, ofmr.outPort); } Map<IOFSwitch, Map<Short, List<OFMatch>>> neighborSwitches = new HashMap<IOFSwitch, Map<Short, List<OFMatch>>>(); for (Link link : links.keySet()) { if (link.getDst() == sw.getId()) { for (Entry<Short, List<OFMatch>> invalidBaseIngressAndMatch : invalidBaseIngressAndMatches.entrySet()) { if (link.getDstPort() == invalidBaseIngressAndMatch.getKey()) { Map<Short, List<OFMatch>> invalidNeighborOutportAndMatch = new HashMap<Short, List<OFMatch>>(); invalidNeighborOutportAndMatch.put(link.getSrcPort(), invalidBaseIngressAndMatch.getValue()); neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } } } log.debug("We have " + neighborSwitches.size() + " neighboring switches to deal with!"); for (IOFSwitch neighborSwitch : neighborSwitches.keySet()) { log.debug("NeighborSwitch ID : " + neighborSwitch.getId()); if (neighborSwitches.get(neighborSwitch) != null) deleteInvalidFlows(neighborSwitch, neighborSwitches.get(neighborSwitch)); } } return Command.CONTINUE; } } else { log.error("Link Discovery Service Is Null"); } return Command.CONTINUE; }  }
PortDownReconciliation implements IFloodlightModule,
    ITopologyListener, IFlowReconcileListener { @Override public net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { if (lds != null) { links = new HashMap<Link, LinkInfo>(); if (lds.getLinks() != null) links.putAll(lds.getLinks()); for (OFMatchReconcile ofmr : ofmRcList) { if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { IOFSwitch sw = floodlightProvider .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); Map<Short, List<OFMatch>> invalidBaseIngressAndMatches = new HashMap<Short, List<OFMatch>>(); List<OFFlowStatisticsReply> flows = getFlows(sw, ofmr.outPort); for (OFFlowStatisticsReply flow : flows) { OFMatch match = flow.getMatch(); if (invalidBaseIngressAndMatches.containsKey(match.getInputPort())) invalidBaseIngressAndMatches.get(match.getInputPort()) .add(match); else { List<OFMatch> matches = new ArrayList<OFMatch>(); matches.add(match); invalidBaseIngressAndMatches.put(match.getInputPort(), matches); } } if (!flows.isEmpty()) { log.debug("Removing flows on switch : " + sw.getId() + " with outport: " + ofmr.outPort); clearFlowMods(sw, ofmr.outPort); } Map<IOFSwitch, Map<Short, List<OFMatch>>> neighborSwitches = new HashMap<IOFSwitch, Map<Short, List<OFMatch>>>(); for (Link link : links.keySet()) { if (link.getDst() == sw.getId()) { for (Entry<Short, List<OFMatch>> invalidBaseIngressAndMatch : invalidBaseIngressAndMatches.entrySet()) { if (link.getDstPort() == invalidBaseIngressAndMatch.getKey()) { Map<Short, List<OFMatch>> invalidNeighborOutportAndMatch = new HashMap<Short, List<OFMatch>>(); invalidNeighborOutportAndMatch.put(link.getSrcPort(), invalidBaseIngressAndMatch.getValue()); neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } } } log.debug("We have " + neighborSwitches.size() + " neighboring switches to deal with!"); for (IOFSwitch neighborSwitch : neighborSwitches.keySet()) { log.debug("NeighborSwitch ID : " + neighborSwitch.getId()); if (neighborSwitches.get(neighborSwitch) != null) deleteInvalidFlows(neighborSwitch, neighborSwitches.get(neighborSwitch)); } } return Command.CONTINUE; } } else { log.error("Link Discovery Service Is Null"); } return Command.CONTINUE; }  @Override void topologyChanged(List<LDUpdate> appliedUpdates); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext context); @Override void startUp(FloodlightModuleContext context); @Override String getName(); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList); List<OFFlowStatisticsReply> getFlows(IOFSwitch sw, Short outPort); void clearFlowMods(IOFSwitch sw, Short outPort); void clearFlowMods(IOFSwitch sw, OFMatch match, Short outPort); void deleteInvalidFlows(IOFSwitch sw,
                               Map<Short, List<OFMatch>> invalidOutportAndMatch); }
PortDownReconciliation implements IFloodlightModule,
    ITopologyListener, IFlowReconcileListener { @Override public net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { if (lds != null) { links = new HashMap<Link, LinkInfo>(); if (lds.getLinks() != null) links.putAll(lds.getLinks()); for (OFMatchReconcile ofmr : ofmRcList) { if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { IOFSwitch sw = floodlightProvider .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); Map<Short, List<OFMatch>> invalidBaseIngressAndMatches = new HashMap<Short, List<OFMatch>>(); List<OFFlowStatisticsReply> flows = getFlows(sw, ofmr.outPort); for (OFFlowStatisticsReply flow : flows) { OFMatch match = flow.getMatch(); if (invalidBaseIngressAndMatches.containsKey(match.getInputPort())) invalidBaseIngressAndMatches.get(match.getInputPort()) .add(match); else { List<OFMatch> matches = new ArrayList<OFMatch>(); matches.add(match); invalidBaseIngressAndMatches.put(match.getInputPort(), matches); } } if (!flows.isEmpty()) { log.debug("Removing flows on switch : " + sw.getId() + " with outport: " + ofmr.outPort); clearFlowMods(sw, ofmr.outPort); } Map<IOFSwitch, Map<Short, List<OFMatch>>> neighborSwitches = new HashMap<IOFSwitch, Map<Short, List<OFMatch>>>(); for (Link link : links.keySet()) { if (link.getDst() == sw.getId()) { for (Entry<Short, List<OFMatch>> invalidBaseIngressAndMatch : invalidBaseIngressAndMatches.entrySet()) { if (link.getDstPort() == invalidBaseIngressAndMatch.getKey()) { Map<Short, List<OFMatch>> invalidNeighborOutportAndMatch = new HashMap<Short, List<OFMatch>>(); invalidNeighborOutportAndMatch.put(link.getSrcPort(), invalidBaseIngressAndMatch.getValue()); neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } } } log.debug("We have " + neighborSwitches.size() + " neighboring switches to deal with!"); for (IOFSwitch neighborSwitch : neighborSwitches.keySet()) { log.debug("NeighborSwitch ID : " + neighborSwitch.getId()); if (neighborSwitches.get(neighborSwitch) != null) deleteInvalidFlows(neighborSwitch, neighborSwitches.get(neighborSwitch)); } } return Command.CONTINUE; } } else { log.error("Link Discovery Service Is Null"); } return Command.CONTINUE; }  @Override void topologyChanged(List<LDUpdate> appliedUpdates); @Override Collection<Class<? extends IFloodlightService>> getModuleServices(); @Override Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls(); @Override Collection<Class<? extends IFloodlightService>> getModuleDependencies(); @Override void init(FloodlightModuleContext context); @Override void startUp(FloodlightModuleContext context); @Override String getName(); @Override boolean isCallbackOrderingPrereq(OFType type, String name); @Override boolean isCallbackOrderingPostreq(OFType type, String name); @Override net.floodlightcontroller.core.IListener.Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList); List<OFFlowStatisticsReply> getFlows(IOFSwitch sw, Short outPort); void clearFlowMods(IOFSwitch sw, Short outPort); void clearFlowMods(IOFSwitch sw, OFMatch match, Short outPort); void deleteInvalidFlows(IOFSwitch sw,
                               Map<Short, List<OFMatch>> invalidOutportAndMatch);  }