Пример #1
0
  /**
   * Converse of addRule. Since we know all the rules ever stored in this flowmap we simply retrieve
   * the rule using the id provided and remove each of its fields from the underlying structures.
   *
   * @param id - the id of the rule to remove
   * @throws FlowEntryNotFound - if this id is unknown. Could indicate that rule has already been
   *     removed.
   * @return
   */
  public void removeRule(int id) throws FlowEntryNotFound {
    ruleCount--;

    if (!rules.containsKey(id)) throw new FlowEntryNotFound(id);

    FlowEntry rule = rules.get(id);

    BitSet flowRuleSet = getFlowRuleSet(rule);

    remove(port, rule.getRuleMatch().getInputPort(), flowRuleSet);
    remove(dpids, rule.dpid, flowRuleSet);
    remove(vlan, (int) rule.getRuleMatch().getDataLayerVirtualLan(), flowRuleSet);
    remove(vlan, rule.getRuleMatch().getDataLayerVirtualLanPriorityCodePoint() << 16, flowRuleSet);
    remove(dl_type, rule.getRuleMatch().getDataLayerType(), flowRuleSet);

    remove(nw, (short) rule.getRuleMatch().getNetworkProtocol(), flowRuleSet);
    remove(nw, (short) (rule.getRuleMatch().getNetworkTypeOfService() << 8), flowRuleSet);

    remove(tp, (int) rule.getRuleMatch().getTransportSource(), flowRuleSet);
    remove(tp, rule.getRuleMatch().getTransportDestination() << 16, flowRuleSet);

    remove(dl_src, FVMatch.toLong(rule.getRuleMatch().getDataLayerSource()), flowRuleSet);
    remove(dl_dst, FVMatch.toLong(rule.getRuleMatch().getDataLayerDestination()), flowRuleSet);

    remove(prioSet, rule.getPriority(), flowRuleSet);

    vlan_ignore.clear(rule.getId());
    rules.remove(rule.getId());
    allRules.andNot(flowRuleSet);
  }
Пример #2
0
  /**
   * Adds a rule to the flowmap. It does so by exploding the rule into its fields and storing each
   * field into its independent structure.
   *
   * @param rule - the rule which will be added to the flowmap
   * @return
   */
  public void addRule(FlowEntry rule) {
    ruleCount++;
    allRules.set(rule.getId());
    BitSet flowRuleSet = getFlowRuleSet(rule);

    add(dpids, rule.dpid, flowRuleSet);

    add(
        port,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_IN_PORT) != 0
            ? ANY_IN_PORT
            : rule.getRuleMatch().getInputPort(),
        flowRuleSet);

    short vid = rule.getRuleMatch().getDataLayerVirtualLan();
    int vpcp = rule.getRuleMatch().getDataLayerVirtualLanPriorityCodePoint();

    /*
     * Openflowj sets unspecified fields to zero.
     */
    if (vid != 0 || vpcp != 0) {
      vlan_ignore.set(rule.getId());
    }

    add(
        vlan,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_DL_VLAN) != 0
            ? (int) ANY_VLAN_ID
            : (int) rule.getRuleMatch().getDataLayerVirtualLan(),
        flowRuleSet);

    add(
        vlan,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_DL_VLAN_PCP) != 0
            ? ANY_VLAN_PCP << 16
            : rule.getRuleMatch().getDataLayerVirtualLanPriorityCodePoint() << 16,
        flowRuleSet);

    add(
        dl_type,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_DL_TYPE) != 0
            ? ANY_ETHER
            : rule.getRuleMatch().getDataLayerType(),
        flowRuleSet);

    add(
        nw,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_NW_PROTO) != 0
            ? ANY_NW_PROTO_TOS
            : (short) rule.getRuleMatch().getNetworkProtocol(),
        flowRuleSet);

    add(
        nw,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_NW_TOS) != 0
            ? (short) (ANY_NW_PROTO_TOS << 8)
            : (short) (rule.getRuleMatch().getNetworkTypeOfService() << 8),
        flowRuleSet);

    add(
        tp,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_TP_SRC) != 0
            ? ANY_TP
            : (int) rule.getRuleMatch().getTransportSource(),
        flowRuleSet);

    add(
        tp,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_TP_DST) != 0
            ? ANY_TP << 16
            : rule.getRuleMatch().getTransportDestination() << 16,
        flowRuleSet);

    add(
        dl_src,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_DL_SRC) != 0
            ? ANY_MAC
            : FVMatch.toLong(rule.getRuleMatch().getDataLayerSource()),
        flowRuleSet);
    add(
        dl_dst,
        (rule.getRuleMatch().getWildcards() & FVMatch.OFPFW_DL_DST) != 0
            ? ANY_MAC
            : FVMatch.toLong(rule.getRuleMatch().getDataLayerDestination()),
        flowRuleSet);

    add(prioSet, rule.getPriority(), flowRuleSet);
    FVLog.log(LogLevel.DEBUG, null, "prioSet:", prioSet);
    rules.put(rule.getId(), rule);
    getPrioSetRange();
  }