@Override @LogMessageDoc( level = "ERROR", message = "Failed to clear all flows on switch {switch}", explanation = "An I/O error occured while trying to clear " + "flows on the switch.", recommendation = LogMessageDoc.CHECK_SWITCH) public void clearAllFlowMods() { // Delete all pre-existing flows OFMatch match = new OFMatch().setWildcards(OFMatch.OFPFW_ALL); OFMessage fm = ((OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD)) .setMatch(match) .setCommand(OFFlowMod.OFPFC_DELETE) .setOutPort(OFPort.OFPP_NONE) .setLength(U16.t(OFFlowMod.MINIMUM_LENGTH)); fm.setXid(getNextTransactionId()); OFMessage barrierMsg = (OFBarrierRequest) floodlightProvider.getOFMessageFactory().getMessage(OFType.BARRIER_REQUEST); barrierMsg.setXid(getNextTransactionId()); try { List<OFMessage> msglist = new ArrayList<OFMessage>(1); msglist.add(fm); write(msglist); msglist = new ArrayList<OFMessage>(1); msglist.add(barrierMsg); write(msglist); } catch (Exception e) { log.error("Failed to clear all flows on switch " + this, e); } }
@Override public Future<OFFeaturesReply> querySwitchFeaturesReply() throws IOException { OFMessage request = floodlightProvider.getOFMessageFactory().getMessage(OFType.FEATURES_REQUEST); request.setXid(getNextTransactionId()); OFFeaturesReplyFuture future = new OFFeaturesReplyFuture(threadPool, this, request.getXid()); this.featuresFutureMap.put(request.getXid(), future); List<OFMessage> msglist = new ArrayList<OFMessage>(1); msglist.add(request); this.write(msglist); return future; }
/** Called periodically to retrieve all port statistics of all switches */ @Override public synchronized void run() { // get a list of all the switches found Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches(); Collection<IOFSwitch> swList = switches.values(); Iterator<IOFSwitch> it = swList.iterator(); try { fw = new FileWriter("netstatslog.txt", true); bw = new BufferedWriter(fw); // for each switch, retrieve the statistics while (it.hasNext()) { IOFSwitch sw = it.next(); List<OFStatistics> stats = new ArrayList<OFStatistics>(); // make a statistics request OFStatisticsRequest req = new OFStatisticsRequest(); req.setStatisticType(OFStatisticsType.PORT); req.setXid(sw.getNextTransactionId()); // fill it with a specific request OFPortStatisticsRequest specReq = new OFPortStatisticsRequest(); specReq.setPortNumber(OFPort.OFPP_NONE.getValue()); stats.add((OFStatistics) specReq); req.setStatistics(stats); req.setLengthU(req.getLengthU() + specReq.getLength()); // attempt to retrieve the statistics Future<List<OFStatistics>> future = null; List<OFStatistics> values = null; try { future = sw.getStatistics(req); values = future.get(); } catch (Exception e) { System.err.println("Exception while retrieving statistics for switch: " + sw + " " + e); } // process the statistics if (!values.isEmpty()) { OFPortStatisticsReply reply = (OFPortStatisticsReply) values.get(0); // determine the new load long newload = 0; if (currentLoad.containsKey(sw.getId())) { // we've seen the switch before newload = reply.getTransmitBytes(); loadHistory.put(sw.getId(), reply.getTransmitBytes()); } else { // this is the first time we see the switch newload = reply.getTransmitBytes(); loadHistory.put(sw.getId(), newload); } // System.out.println("Capa: " + sw.getCapabilities() * 1024); // System.out.println("Load: " + newload); currentLoad.put(sw.getId(), (sw.getCapabilities() * 1024) - newload); bw.write("\n id: " + sw.getId() + " ;load: " + ((sw.getCapabilities() * 1024) - newload)); // System.out.println("Load for switch: " + currentLoad.get(sw.getId())); } } bw.write("\n******************"); bw.close(); } catch (Exception e) { // Catch exception if any System.err.println("Error: " + e.getMessage()); } }