private OFAction buildL2Modification(Instruction i) {
    L2ModificationInstruction l2m = (L2ModificationInstruction) i;
    ModEtherInstruction eth;
    OFOxm<?> oxm = null;
    switch (l2m.subtype()) {
      case ETH_DST:
        eth = (ModEtherInstruction) l2m;
        oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
        break;
      case ETH_SRC:
        eth = (ModEtherInstruction) l2m;
        oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
        break;
      case VLAN_ID:
        ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
        oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
        break;
      case VLAN_PCP:
        ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
        oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
        break;
      case MPLS_PUSH:
        PushHeaderInstructions pushHeaderInstructions = (PushHeaderInstructions) l2m;
        return factory()
            .actions()
            .pushMpls(EthType.of(pushHeaderInstructions.ethernetType().toShort()));
      case MPLS_POP:
        PushHeaderInstructions popHeaderInstructions = (PushHeaderInstructions) l2m;
        return factory()
            .actions()
            .popMpls(EthType.of(popHeaderInstructions.ethernetType().toShort()));
      case MPLS_LABEL:
        ModMplsLabelInstruction mplsLabel = (ModMplsLabelInstruction) l2m;
        oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label().longValue()));
        break;
      case DEC_MPLS_TTL:
        return factory().actions().decMplsTtl();
      case VLAN_POP:
        return factory().actions().popVlan();
      case VLAN_PUSH:
        PushHeaderInstructions pushVlanInstruction = (PushHeaderInstructions) l2m;
        return factory()
            .actions()
            .pushVlan(EthType.of(pushVlanInstruction.ethernetType().toShort()));
      default:
        log.warn("Unimplemented action type {}.", l2m.subtype());
        break;
    }

    if (oxm != null) {
      return factory().actions().buildSetField().setField(oxm).build();
    }
    return null;
  }
Пример #2
0
  @Override
  public void forward(ForwardingObjective fwd) {

    if (checkForMulticast(fwd)) {
      processMulticastRule(fwd);
      return;
    }

    TrafficTreatment treatment = fwd.treatment();

    List<Instruction> instructions = treatment.allInstructions();

    Optional<Instruction> vlanIntruction =
        instructions
            .stream()
            .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
            .filter(
                i ->
                    ((L2ModificationInstruction) i).subtype()
                            == L2ModificationInstruction.L2SubType.VLAN_PUSH
                        || ((L2ModificationInstruction) i).subtype()
                            == L2ModificationInstruction.L2SubType.VLAN_POP)
            .findAny();

    if (!vlanIntruction.isPresent()) {
      fail(fwd, ObjectiveError.BADPARAMS);
      return;
    }

    L2ModificationInstruction vlanIns = (L2ModificationInstruction) vlanIntruction.get();

    if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
      installUpstreamRules(fwd);
    } else if (vlanIns.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP) {
      installDownstreamRules(fwd);
    } else {
      log.error("Unknown OLT operation: {}", fwd);
      fail(fwd, ObjectiveError.UNSUPPORTED);
      return;
    }

    pass(fwd);
  }