@Override public void startUp(FloodlightModuleContext context) { ScheduledExecutorService ses = threadPool.getScheduledExecutor(); newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker()); linkDiscovery.addListener(this); floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); floodlightProvider.addHAListener(this); addRestletRoutable(); }
/** Switch methods */ public Set<Short> getPorts(long sw) { Set<Short> ports = new HashSet<Short>(); IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); if (iofSwitch == null) return null; Collection<Short> ofpList = iofSwitch.getEnabledPortNumbers(); if (ofpList == null) return null; Set<Short> qPorts = linkDiscovery.getQuarantinedPorts(sw); if (qPorts != null) ofpList.removeAll(qPorts); ports.addAll(ofpList); return ports; }
@Override public void debug() { logger.debug("Nathan Debug called"); // 从IFloodlightProviderService中获得连接的所有Switch Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches(); Collection<Long> sw_keys = switches.keySet(); // sw_keys-所有switches的switch.getId() Iterator<Long> sw_key_iter = sw_keys.iterator(); while (sw_key_iter.hasNext()) { Long sw_id = sw_key_iter.next(); IOFSwitch sw = switches.get(sw_id); // 输出switch信息 logger.debug("Got Switch: {}", sw); // 此处测试各类OFStatistics boolean ofp_desc_stats = true; boolean ofp_flow_stat = true; // ofp_desc_stat if (ofp_desc_stats) { OFStatisticsRequest request = new OFStatisticsRequest(); request.setStatisticType(OFStatisticsType.DESC); try { logger.debug("request desc future"); Future<List<OFStatistics>> future = sw.getStatistics(request); List<OFStatistics> list = future.get(10, TimeUnit.SECONDS); for (int i = 0; i < list.size(); i++) { OFDescriptionStatistics desc = (OFDescriptionStatistics) list.get(i); logger.info("Got Desc: {}", desc); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } } // ofp_flow_stat if (ofp_flow_stat) { // flow request body OFFlowStatisticsRequest flow_request = new OFFlowStatisticsRequest(); OFMatch match = new OFMatch(); flow_request.setMatch(match); flow_request.setOutPort(OFPort.OFPP_NONE.getValue()); flow_request.setTableId((byte) 0xFF); // statistics request OFStatisticsRequest request = new OFStatisticsRequest(); request.setStatisticType(OFStatisticsType.FLOW); request.setStatistics(Collections.singletonList((OFStatistics) flow_request)); // 这步非常重要,需要显示的增加request的长度,否则将出现越界错误 int request_length = request.getLength() + flow_request.getLength(); request.setLengthU(request_length); try { logger.debug("request flow future"); Future<List<OFStatistics>> future = sw.getStatistics(request); List<OFStatistics> list = future.get(10, TimeUnit.SECONDS); for (int i = 0; i < list.size(); i++) { OFFlowStatisticsReply flow = (OFFlowStatisticsReply) list.get(i); logger.info("Got Flow: {}", flow); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } } } // obtain all attached devices from IDeviceService Collection<? extends IDevice> devices = deviceService.getAllDevices(); Iterator<? extends IDevice> dev_iter = devices.iterator(); while (dev_iter.hasNext()) { IDevice dev = dev_iter.next(); logger.info("Got Device: {}", dev); } // obtain all links between switches from ILinkDiscoveryService Map<Link, LinkInfo> link_map = linkService.getLinks(); Collection<Link> links = link_map.keySet(); // links contains all links, and it can be used as key to get its corresponding LinkInfo Iterator<Link> link_iter = links.iterator(); while (link_iter.hasNext()) { Link link = link_iter.next(); logger.info("Got Link: {}" + link); } }
/** Get a list of all active links in the network. */ private Collection<Link> getLinks() { return linkDiscProv.getLinks().keySet(); }