/**
   * 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);
  }
Beispiel #2
0
 /**
  * Lame: linear search to delete something in a sorted set ... but it's sorted by priority, not ID
  */
 @Override
 public void removeRule(int id) throws FlowEntryNotFound {
   for (FlowEntry flowEntry : this.getRules())
     if (flowEntry.getId() == id) {
       this.rules.remove(flowEntry);
       return;
     }
   throw new FlowEntryNotFound(id);
 }
 /**
  * Get a bitset corresponding to a rule.
  *
  * @param rule - the rule.
  * @return the bitset corresponding to this rule.
  */
 private BitSet getFlowRuleSet(FlowEntry rule) {
   BitSet flowRuleSet = new BitSet();
   flowRuleSet.set(rule.getId());
   return flowRuleSet;
 }
  private FlowIntersect getIntersect(FlowEntry fe, HashMap<Integer, FlowIntersect> inters) {
    FlowIntersect inter = inters.get(fe.getId());
    if (inter == null) inter = new FlowIntersect(fe);

    return inter;
  }
  /**
   * 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();
  }