/** * Handles a flow removed message from a switch. If the flow was removed * and we did not explicitly delete it we re-install it. If we explicitly * removed the flow we stop the processing of the flow removed message. * @param sw The switch that sent the flow removed message. * @param msg The flow removed message. * @param cntx The associated context. * @return Whether to continue processing this message. */ public Command handleFlowRemoved(IOFSwitch sw, OFFlowRemoved msg, FloodlightContext cntx) { long cookie = msg.getCookie(); /** * This is just to sanity check our assumption that static flows * never expire. */ if (AppCookie.extractApp(cookie) == STATIC_FLOW_APP_ID) { if (msg.getReason() != OFFlowRemoved.OFFlowRemovedReason.OFPRR_DELETE) log.error("Got a FlowRemove message for a infinite " + "timeout flow: {} from switch {}", msg, sw); // Stop the processing chain since we sent the delete. return Command.STOP; } return Command.CONTINUE; }
/** * Check if we have sampled this mac in the last second. * Since we check every packetInRatePerMacThreshold packets, * the presence of the mac in the macCache means the rate is * above the threshold in a statistical sense. * * Take care not to block topology probing packets. Also don't * push blocking flow mod if we have already done so within the * last 5 seconds. * * @param pin * @return */ private void checkPerSourceMacRate(OFPacketIn pin) { byte[] data = pin.getPacketData(); byte[] mac = Arrays.copyOfRange(data, 6, 12); MACAddress srcMac = MACAddress.valueOf(mac); short ethType = (short) (((data[12] & 0xff) << 8) + (data[13] & 0xff)); if (ethType != Ethernet.TYPE_LLDP && ethType != Ethernet.TYPE_BSN && macCache.update(srcMac.toLong())) { // Check if we already pushed a flow in the last 5 seconds if (macBlockedCache.update(srcMac.toLong())) { return; } // write out drop flow per srcMac int port = pin.getInPort(); SwitchPort swPort = new SwitchPort(getId(), port); ForwardingBase.blockHost(floodlightProvider, swPort, srcMac.toLong(), (short) 5, AppCookie.makeCookie(OFSWITCH_APP_ID, 0)); floodlightProvider.addSwitchEvent(this.datapathId, "SWITCH_PORT_BLOCKED_TEMPORARILY " + "OFPort " + port + " mac " + srcMac, false); log.info("Excessive packet in from {} on {}, block host for 5 sec", srcMac.toString(), swPort); } }
/** * Works in a similar way as checkPerSourceMacRate(). * * TODO Don't block ports with links? * * @param pin * @return */ private void checkPerPortRate(OFPacketIn pin) { Short port = pin.getInPort(); if (portCache.update(port)) { // Check if we already pushed a flow in the last 5 seconds if (portBlockedCache.update(port)) { return; } // write out drop flow per port SwitchPort swPort = new SwitchPort(getId(), port); ForwardingBase.blockHost(floodlightProvider, swPort, -1L, (short) 5, AppCookie.makeCookie(OFSWITCH_APP_ID, 1)); floodlightProvider.addSwitchEvent(this.datapathId, "SWITCH_PORT_BLOCKED_TEMPORARILY " + "OFPort " + port, false); log.info("Excessive packet in from {}, block port for 5 sec", swPort); } }
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); Match m = createMatchFromPacket(sw, inPort, cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); log.info("Droppingggg"); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(m) .setActions(actions) // empty list .setPriority(FLOWMOD_DEFAULT_PRIORITY); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
/** * Handles a flow removed message from a switch. If the flow was removed * and we did not explicitly delete it we re-install it. If we explicitly * removed the flow we stop the processing of the flow removed message. * @param sw The switch that sent the flow removed message. * @param msg The flow removed message. * @param cntx The associated context. * @return Whether to continue processing this message. */ public Command handleFlowRemoved(IOFSwitch sw, OFFlowRemoved msg, FloodlightContext cntx) { U64 cookie = msg.getCookie(); /** * This is just to sanity check our assumption that static flows * never expire. */ if (AppCookie.extractApp(cookie) == STATIC_FLOW_APP_ID) { if (OFFlowRemovedReason.DELETE.equals(msg.getReason())) log.error("Got a FlowRemove message for a infinite " + "timeout flow: {} from switch {}", msg, sw); // Stop the processing chain since we sent the delete. return Command.STOP; } return Command.CONTINUE; }
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); Match m = createMatchFromPacket(sw, inPort, cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); log.info("Droppingggg"); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(m) .setPriority(FLOWMOD_DEFAULT_PRIORITY); FlowModUtils.setActions(fmb, actions, sw); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
/** * Writes a FlowMod to a switch that inserts a drop flow. * @param sw The switch to write the FlowMod to. * @param pi The corresponding OFPacketIn. Used to create the OFMatch structure. * @param cntx The FloodlightContext that gets passed to the switch. */ protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { if (log.isTraceEnabled()) { log.trace("doDropFlow pi={} srcSwitch={}", new Object[] { pi, sw }); } if (sw == null) { log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi); return; } // Create flow-mod based on packet-in and src-switch OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowModify(); List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop U64 cookie = AppCookie.makeCookie(APP_ID, 0); fmb.setCookie(cookie) .setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(pi.getMatch()) .setActions(actions); if (log.isTraceEnabled()) { log.trace("write drop flow-mod srcSwitch={} match={} " + "pi={} flow-mod={}", new Object[] {sw, pi.getMatch(), pi, fmb.build()}); } sw.write(fmb.build()); return; }
/** * This function generates a random hash for the bottom half of the cookie * * @param fm * @param userCookie * @param name * @return A cookie that encodes the application ID and a hash */ public static U64 computeEntryCookie(int userCookie, String name) { // flow-specific hash is next 20 bits LOOK! who knows if this int prime = 211; int flowHash = 2311; for (int i=0; i < name.length(); i++) { flowHash = flowHash * prime + (int)name.charAt(i); } return AppCookie.makeCookie(StaticFlowEntryPusher.STATIC_FLOW_APP_ID, flowHash); }
@LogMessageDoc(level="ERROR", message="Failure writing drop flow mod", explanation="An I/O error occured while trying to write a " + "drop flow mod to a switch", recommendation=LogMessageDoc.CHECK_SWITCH) protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); Match m = createMatchFromPacket(sw, inPort, cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(m) .setActions(actions) // empty list .setPriority(FLOWMOD_DEFAULT_PRIORITY); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
@LogMessageDoc(level="ERROR", message="Failure writing drop flow mod", explanation="An I/O error occured while trying to write a " + "drop flow mod to a switch", recommendation=LogMessageDoc.CHECK_SWITCH) protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { // initialize match structure and populate it using the packet OFMatch match = new OFMatch(); match.loadFromPacket(pi.getPacketData(), pi.getInPort()); if (decision.getWildcards() != null) { match.setWildcards(decision.getWildcards()); } // Create flow-mod based on packet-in and src-switch OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory() .getMessage(OFType.FLOW_MOD); List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to // drop long cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); fm.setCookie(cookie) .setHardTimeout((short) 0) .setIdleTimeout((short) 5) .setBufferId(OFPacketOut.BUFFER_ID_NONE) .setMatch(match) .setActions(actions) .setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, match, fm }); } messageDamper.write(sw, fm, cntx); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
/** * Writes a FlowMod to a switch that inserts a drop flow. * @param sw The switch to write the FlowMod to. * @param pi The corresponding OFPacketIn. Used to create the OFMatch structure. * @param cntx The FloodlightContext that gets passed to the switch. */ protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { if (log.isTraceEnabled()) { log.trace("doDropFlow pi={} srcSwitch={}", new Object[] { pi, sw }); } if (sw == null) { log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi); return; } // Create flow-mod based on packet-in and src-switch OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD); OFMatch match = new OFMatch(); match.loadFromPacket(pi.getPacketData(), pi.getInPort()); List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop long cookie = AppCookie.makeCookie(APP_ID, 0); fm.setCookie(cookie) .setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT) .setBufferId(OFPacketOut.BUFFER_ID_NONE) .setMatch(match) .setActions(actions) .setLengthU(OFFlowMod.MINIMUM_LENGTH); // fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM); try { if (log.isTraceEnabled()) { log.trace("write drop flow-mod srcSwitch={} match={} " + "pi={} flow-mod={}", new Object[] {sw, match, pi, fm}); } sw.write(fm, cntx); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } return; }
/** * This function generates a random hash for the bottom half of the cookie * * @param fm * @param userCookie * @param name * @return A cookie that encodes the application ID and a hash */ public static long computeEntryCookie(OFFlowMod fm, int userCookie, String name) { // flow-specific hash is next 20 bits LOOK! who knows if this int prime = 211; int flowHash = 2311; for (int i=0; i < name.length(); i++) flowHash = flowHash * prime + (int)name.charAt(i); return AppCookie.makeCookie(StaticFlowEntryPusher.STATIC_FLOW_APP_ID, flowHash); }
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { OFPort inPort = (pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)); Match m = createMatchFromPacket(sw, inPort, cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); // this will be a drop-flow; a flow that will not output to any ports List<OFAction> actions = new ArrayList<OFAction>(); // set no action to drop U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); //log.info("Droppingggg"); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(m) .setPriority(FLOWMOD_DEFAULT_PRIORITY); FlowModUtils.setActions(fmb, actions, sw); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.info("SXT_DBG:******Send flowmod(drop) message successful !******"); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
protected void doFlowMod(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx,IPv6Address eid,IPv6Address rloc) { log.info("SXT_DBG: ******start doFLowMod******"); Match m = createMatchFromPacket0(sw, eid,rloc,cntx); OFFlowMod.Builder fmb = sw.getOFFactory().buildFlowAdd(); List<OFAction> actions = new ArrayList<OFAction>(); U64 cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0);//********* OFPort outPort = OFPort.of(0);//Defaulted NetMagicPro outPort is zero //log.info("doflowmod"); fmb.setCookie(cookie) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setBufferId(OFBufferId.NO_BUFFER) .setOutPort(outPort) .setMatch(m) .setPriority(FLOWMOD_DEFAULT_PRIORITY); FlowModUtils.setActions(fmb, actions, sw); try { if (log.isDebugEnabled()) { log.debug("write flow-mod sw={} match={} flow-mod={}", new Object[] { sw, m, fmb.build() }); } boolean dampened = messageDamper.write(sw, fmb.build()); log.info("SXT_DBG:******Send flowmod(add) message successful*****"); log.debug("OFMessage dampened: {}", dampened); } catch (IOException e) { log.error("Failure writing flow mod", e); } }