Esempio n. 1
0
  @LogMessageDocs({
    @LogMessageDoc(
        level = "ERROR",
        message = "Failure writing deny flow mod",
        explanation = "An I/O error occurred while writing a " + "deny flow mod to a switch",
        recommendation = LogMessageDoc.CHECK_SWITCH)
  })
  public static boolean blockHost(
      IFloodlightProviderService floodlightProvider,
      SwitchPort sw_tup,
      long host_mac,
      short hardTimeout,
      long cookie) {

    if (sw_tup == null) {
      return false;
    }

    IOFSwitch sw = floodlightProvider.getSwitches().get(sw_tup.getSwitchDPID());
    if (sw == null) return false;
    int inputPort = sw_tup.getPort();
    log.debug(
        "blockHost sw={} port={} mac={}", new Object[] {sw, sw_tup.getPort(), new Long(host_mac)});

    // Create flow-mod based on packet-in and src-switch
    OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    OFMatch match = new OFMatch();
    List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to
    // drop
    match
        .setDataLayerSource(Ethernet.toByteArray(host_mac))
        .setInputPort((short) inputPort)
        .setWildcards(OFMatch.OFPFW_ALL & ~OFMatch.OFPFW_DL_SRC & ~OFMatch.OFPFW_IN_PORT);
    fm.setCookie(cookie)
        .setHardTimeout(hardTimeout)
        .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
        .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
        .setBufferId(OFPacketOut.BUFFER_ID_NONE)
        .setMatch(match)
        .setActions(actions)
        .setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH);

    try {
      log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] {sw, match, fm});
      // TODO: can't use the message damper sine this method is static
      sw.write(fm, null);
    } catch (IOException e) {
      log.error("Failure writing deny flow mod", e);
      return false;
    }
    return true;
  }