Esempio n. 1
0
  @Override
  public void emit(OutboundPacket packet) {
    DeviceId devId = packet.sendThrough();
    String scheme = devId.toString().split(":")[0];

    if (!scheme.equals(this.id().scheme())) {
      throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
    }

    Dpid dpid = Dpid.dpid(devId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
      log.warn("Device {} isn't available?", devId);
      return;
    }

    // Ethernet eth = new Ethernet();
    // eth.deserialize(packet.data().array(), 0, packet.data().array().length);
    OFPortDesc p = null;
    for (Instruction inst : packet.treatment().allInstructions()) {
      if (inst.type().equals(Instruction.Type.OUTPUT)) {
        p = portDesc(((OutputInstruction) inst).port());
        OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo());
        sw.sendMsg(po);
      }
    }
  }
 private PortNumber getOutput(FlowRule rule) {
   for (Instruction i : rule.treatment().allInstructions()) {
     if (i.type() == Instruction.Type.OUTPUT) {
       Instructions.OutputInstruction out = (Instructions.OutputInstruction) i;
       return out.port();
     }
   }
   return null;
 }
Esempio n. 3
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;
  }
 private void sendPacket(Ethernet eth) {
   List<Instruction> ins = treatmentBuilder().build().instructions();
   OFPort p = null;
   // TODO: support arbitrary list of treatments must be supported in ofPacketContext
   for (Instruction i : ins) {
     if (i.type() == Type.OUTPUT) {
       p = buildPort(((OutputInstruction) i).port());
       break; // for now...
     }
   }
   if (eth == null) {
     ofPktCtx.build(p);
   } else {
     ofPktCtx.build(eth, p);
   }
   ofPktCtx.send();
 }
  @Override
  public boolean matchesSafely(JsonNode jsonInstruction, Description description) {

    // check type
    final JsonNode jsonTypeNode = jsonInstruction.get("type");
    final String jsonType = jsonTypeNode.textValue();
    final String type = instruction.type().name();
    if (!jsonType.equals(type)) {
      description.appendText("type was " + type);
      return false;
    }

    if (instruction instanceof ModMplsHeaderInstruction) {
      return matchModMplsHeaderInstruction(jsonInstruction, description);
    } else if (instruction instanceof OutputInstruction) {
      return matchOutputInstruction(jsonInstruction, description);
    } else if (instruction instanceof GroupInstruction) {
      return matchGroupInstruction(jsonInstruction, description);
    } else if (instruction instanceof MeterInstruction) {
      return matchMeterInstruction(jsonInstruction, description);
    } else if (instruction instanceof SetQueueInstruction) {
      return matchSetQueueInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModOchSignalInstruction) {
      return matchModOchSingalInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModEtherInstruction) {
      return matchModEtherInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModVlanIdInstruction) {
      return matchModVlanIdInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModVlanPcpInstruction) {
      return matchModVlanPcpInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModIPInstruction) {
      return matchModIpInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModIPv6FlowLabelInstruction) {
      return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModMplsLabelInstruction) {
      return matchModMplsLabelInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModOduSignalIdInstruction) {
      return matchModOduSingalIdInstruction(jsonInstruction, description);
    } else if (instruction instanceof NoActionInstruction) {
      return true;
    }

    return false;
  }
 @Override
 public void describeTo(Description description) {
   description.appendText(instruction.toString());
 }