Beispiel #1
0
  private List<OFAction> buildActions(List<Instruction> treatments) {
    if (treatment == null) {
      return Collections.emptyList();
    }

    boolean tableFound = false;
    List<OFAction> actions = new LinkedList<>();
    for (Instruction i : treatments) {
      switch (i.type()) {
        case DROP:
        case NOACTION:
          return Collections.emptyList();
        case L0MODIFICATION:
          actions.add(buildL0Modification(i));
          break;
        case L2MODIFICATION:
          actions.add(buildL2Modification(i));
          break;
        case L3MODIFICATION:
          actions.add(buildL3Modification(i));
          break;
        case L4MODIFICATION:
          actions.add(buildL4Modification(i));
          break;
        case OUTPUT:
          OutputInstruction out = (OutputInstruction) i;
          OFActionOutput.Builder action =
              factory().actions().buildOutput().setPort(OFPort.of((int) out.port().toLong()));
          if (out.port().equals(PortNumber.CONTROLLER)) {
            action.setMaxLen(OFPCML_NO_BUFFER);
          }
          actions.add(action.build());
          break;
        case GROUP:
          GroupInstruction group = (GroupInstruction) i;
          OFActionGroup.Builder groupBuilder =
              factory().actions().buildGroup().setGroup(OFGroup.of(group.groupId().id()));
          actions.add(groupBuilder.build());
          break;
        case TABLE:
          // FIXME: should not occur here.
          tableFound = true;
          break;
        default:
          log.warn("Instruction type {} not yet implemented.", i.type());
      }
    }
    if (tableFound && actions.isEmpty()) {
      // handles the case where there are no actions, but there is
      // a goto instruction for the next table
      return Collections.emptyList();
    }
    return actions;
  }
  /**
   * Matches the contents of a group instruction.
   *
   * @param instructionJson JSON instruction to match
   * @param description Description object used for recording errors
   * @return true if contents match, false otherwise
   */
  private boolean matchGroupInstruction(JsonNode instructionJson, Description description) {
    final String jsonType = instructionJson.get("type").textValue();
    GroupInstruction instructionToMatch = (GroupInstruction) instruction;
    if (!instructionToMatch.type().name().equals(jsonType)) {
      description.appendText("type was " + jsonType);
      return false;
    }

    final int jsonGroupId = instructionJson.get("groupId").intValue();
    if (instructionToMatch.groupId().id() != jsonGroupId) {
      description.appendText("groupId was " + jsonGroupId);
      return false;
    }

    return true;
  }