Java Code Examples for org.onosproject.net.flow.TrafficTreatment#allInstructions()

The following examples show how to use org.onosproject.net.flow.TrafficTreatment#allInstructions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Utility function to get the mod tunnel id instruction
 * if present.
 *
 * @param treatment the treatment to analyze
 * @return the mod tunnel id instruction if present,
 * otherwise null
 */
static ModTunnelIdInstruction getModTunnelIdInstruction(TrafficTreatment treatment) {
    if (treatment == null) {
        return null;
    }
    L2ModificationInstruction l2ModificationInstruction;
    for (Instruction instruction : treatment.allInstructions()) {
        if (instruction.type() == L2MODIFICATION) {
            l2ModificationInstruction = (L2ModificationInstruction) instruction;
            if (l2ModificationInstruction.subtype() == L2SubType.TUNNEL_ID) {
                return (ModTunnelIdInstruction) l2ModificationInstruction;
            }
        }
    }
    return null;
}
 
Example 2
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * As per the OFDPA 2.0 TTP, packets are sent out of ports by using
 * a chain of groups. The simple Next Objective passed in by the application
 * is broken up into a group chain. The following chains can be modified
 * depending on the parameters in the Next Objective.
 * 1. L2 Interface group (no chaining)
 * 2. L3 Unicast group -> L2 Interface group
 *
 * @param nextObj  the nextObjective of type SIMPLE
 */
private void modifySimpleNextObjective(NextObjective nextObj, NextGroup nextGroup) {
    TrafficTreatment treatment = nextObj.next().iterator().next();
    // determine if plain L2 or L3->L2 chain
    boolean plainL2 = true;
    for (Instruction ins : treatment.allInstructions()) {
        if (ins.type() == Instruction.Type.L2MODIFICATION) {
            L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
            if (l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_DST ||
                    l2ins.subtype() == L2ModificationInstruction.L2SubType.ETH_SRC ||
                    l2ins.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
                plainL2 = false;
            }
        }
    }
    if (plainL2) {
        modifyBucketInL2Group(nextObj, nextGroup);
    } else {
        modifyBucketInL3Group(nextObj, nextGroup);
    }
    return;
}
 
Example 3
Source File: Bmv2PreGroupTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves output instructions out of the instruction set of the given traffic treatment.
 *
 * @param trafficTreatment
 * @return set of output instructions
 */
private static Set<Instructions.OutputInstruction> getOutputInstructions(TrafficTreatment trafficTreatment) {
    if (trafficTreatment == null ||
            trafficTreatment.allInstructions() == null) {
        return Sets.newHashSet();
    }
    Set<Instructions.OutputInstruction> resultList = Sets.newHashSet();
    trafficTreatment.allInstructions().forEach(instruction -> {
        if (instruction instanceof Instructions.OutputInstruction) {
            resultList.add((Instructions.OutputInstruction) instruction);
        }
    });
    return resultList;
}
 
Example 4
Source File: HPPipelineV3500.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;

    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V3500 Driver - unsupported criteria {}", criterion.type());

            unsupportedFeatures = true;
        }
    }

    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V3500 Driver - unsupported instruction {}", instruction.type());

            unsupportedFeatures = true;
        }

        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V3500 Driver - unsupported L2MODIFICATION instruction {}",
                        ((L2ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }

        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V3500 Driver - unsupported L3MODIFICATION instruction {}",
                        ((L3ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }
    }

    return unsupportedFeatures;
}
 
Example 5
Source File: HPPipelineV3.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;

    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V3 Driver - unsupported criteria {}", criterion.type());

            unsupportedFeatures = true;
        }
    }

    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V3 Driver - unsupported instruction {}", instruction.type());

            unsupportedFeatures = true;
        }

        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V3 Driver - unsupported L2MODIFICATION instruction {}",
                        ((L2ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }

        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V3 Driver - unsupported L3MODIFICATION instruction {}",
                        ((L3ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }
    }

    return unsupportedFeatures;
}
 
Example 6
Source File: HPPipelineV2.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;

    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V2 Driver - unsupported criteria {}", criterion.type());

            unsupportedFeatures = true;
        }
    }

    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V2 Driver - unsupported instruction {}", instruction.type());

            unsupportedFeatures = true;
        }

        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V2 Driver - unsupported L2MODIFICATION instruction {}",
                        ((L2ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }

        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V2 Driver - unsupported L3MODIFICATION instruction {}",
                        ((L3ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }
    }

    return unsupportedFeatures;
}
 
Example 7
Source File: HPPipelineV1.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean checkUnSupportedFeatures(TrafficSelector selector, TrafficTreatment treatment) {
    boolean unsupportedFeatures = false;

    for (Criterion criterion : selector.criteria()) {
        if (this.unsupportedCriteria.contains(criterion.type())) {
            log.warn("HP V1 Driver - unsupported criteria {}", criterion.type());

            unsupportedFeatures = true;
        }
    }

    for (Instruction instruction : treatment.allInstructions()) {
        if (this.unsupportedInstructions.contains(instruction.type())) {
            log.warn("HP V1 Driver - unsupported instruction {}", instruction.type());

            unsupportedFeatures = true;
        }

        if (instruction.type() == Instruction.Type.L2MODIFICATION) {
            if (this.unsupportedL2mod.contains(((L2ModificationInstruction) instruction).subtype())) {
                log.warn("HP V1 Driver - unsupported L2MODIFICATION instruction {}",
                        ((L2ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }

        if (instruction.type() == Instruction.Type.L3MODIFICATION) {
            if (this.unsupportedL3mod.contains(((L3ModificationInstruction) instruction).subtype())) {
                log.warn("HP V1 Driver - unsupported L3MODIFICATION instruction {}",
                        ((L3ModificationInstruction) instruction).subtype());

                unsupportedFeatures = true;
            }
        }
    }

    return unsupportedFeatures;
}
 
Example 8
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(ForwardingObjective fwd) {
    log.debug("Installing forwarding objective {}", fwd);
    if (checkForMulticast(fwd)) {
        processMulticastRule(fwd);
        return;
    }

    TrafficTreatment treatment = fwd.treatment();

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

    Optional<Instruction> vlanInstruction = 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 (!vlanInstruction.isPresent()) {
        installNoModificationRules(fwd);
    } else {
        L2ModificationInstruction vlanIns =
                (L2ModificationInstruction) vlanInstruction.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);

}
 
Example 9
Source File: OfdpaGroupHandlerUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the outport in a traffic treatment.
 *
 * @param tt the treatment
 * @return the PortNumber for the outport or null
 */
static PortNumber readOutPortFromTreatment(TrafficTreatment tt) {
    for (Instruction ins : tt.allInstructions()) {
        if (ins.type() == Instruction.Type.OUTPUT) {
            return ((Instructions.OutputInstruction) ins).port();
        }
    }
    return null;
}
 
Example 10
Source File: PiFlowRuleTranslatorImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a PI action out of the given treatment, optionally using the given
 * interpreter.
 */
private static PiTableAction buildAction(TrafficTreatment treatment, PiPipelineInterpreter interpreter,
                                         PiTableId tableId)
        throws PiTranslationException {

    PiTableAction piTableAction = null;

    // If treatment has only one instruction of type PiInstruction, use that.
    for (Instruction inst : treatment.allInstructions()) {
        if (inst.type() == Instruction.Type.PROTOCOL_INDEPENDENT) {
            if (treatment.allInstructions().size() == 1) {
                piTableAction = ((PiInstruction) inst).action();
            } else {
                throw new PiTranslationException(format(
                        "Unable to translate treatment, found multiple instructions " +
                                "of which one is protocol-independent: %s", treatment));
            }
        }
    }

    if (piTableAction == null && interpreter != null) {
        // No PiInstruction, use interpreter to build action.
        try {
            piTableAction = interpreter.mapTreatment(treatment, tableId);
        } catch (PiPipelineInterpreter.PiInterpreterException e) {
            throw new PiTranslationException(
                    "Interpreter was unable to translate treatment. " + e.getMessage());
        }
    }

    return piTableAction;
}
 
Example 11
Source File: OplinkPowerConfigUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Find matching flow on device.
 *
 * @param portNum the port number
 * @param och channel signal
 * @return flow entry
 */
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
    final DriverHandler handler = behaviour.handler();
    FlowRuleService service = handler.get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());

    // Return first matching flow
    for (FlowEntry entry : flowEntries) {
        TrafficSelector selector = entry.selector();
        OchSignalCriterion entrySigid =
                (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
        // Check channel
        if (entrySigid != null && och.equals(entrySigid.lambda())) {
            // Check input port
            PortCriterion entryPort =
                    (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
            if (entryPort != null && portNum.equals(entryPort.port())) {
                return entry;
            }

            // Check output port
            TrafficTreatment treatment = entry.treatment();
            for (Instruction instruction : treatment.allInstructions()) {
                if (instruction.type() == Instruction.Type.OUTPUT &&
                    ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
                    return entry;
                }
            }
        }
    }
    log.warn("No matching flow found");
    return null;
}
 
Example 12
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Reads eth dst from treatment.
 *
 * @param treatment the given actions
 * @return the eth dst if found. null otherwise
 */
static MacAddress readEthDstFromTreatment(TrafficTreatment treatment) {
    if (treatment == null) {
        return null;
    }
    for (Instruction i : treatment.allInstructions()) {
        if (i instanceof ModEtherInstruction) {
            ModEtherInstruction modEtherInstruction = (ModEtherInstruction) i;
            if (modEtherInstruction.subtype() == L2SubType.ETH_DST) {
                return modEtherInstruction.mac();
            }
        }
    }
    return null;
}
 
Example 13
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function to get the output instruction
 * if present.
 *
 * @param treatment the treatment to analyze
 * @return the output instruction if present,
 * otherwise null
 */
static Instructions.OutputInstruction getOutputInstruction(TrafficTreatment treatment) {
    if (treatment == null) {
        return null;
    }
    for (Instruction instruction : treatment.allInstructions()) {
        if (instruction.type() == Instruction.Type.OUTPUT) {
            return (Instructions.OutputInstruction) instruction;
        }
    }
    return null;
}
 
Example 14
Source File: PicaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() != 1) {
                log.error("Next Objectives of type Simple should only have a "
                        + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
               fail(nextObjective, ObjectiveError.BADPARAMS);
               return;
            }
            TrafficTreatment treatment = treatments.iterator().next();
            TrafficTreatment.Builder filteredTreatment = DefaultTrafficTreatment.builder();
            VlanId modVlanId;
            for (Instruction ins : treatment.allInstructions()) {
                if (ins.type() == Instruction.Type.L2MODIFICATION) {
                    L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                    switch (l2ins.subtype()) {
                        case ETH_DST:
                            filteredTreatment.setEthDst(
                                    ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case ETH_SRC:
                            filteredTreatment.setEthSrc(
                                    ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                            break;
                        case VLAN_ID:
                            modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                            filteredTreatment.setVlanId(modVlanId);
                            break;
                        default:
                            break;
                    }
                } else if (ins.type() == Instruction.Type.OUTPUT) {
                    //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
                    filteredTreatment.add(ins);
                } else {
                    // Ignore the vlan_pcp action since it's does matter much.
                    log.warn("Driver does not handle this type of TrafficTreatment"
                            + " instruction in nextObjectives:  {}", ins.type());
                }
            }
            // store for future use
            flowObjectiveStore.putNextGroup(nextObjective.id(),
                                            new PicaGroup(filteredTreatment.build()));
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}
 
Example 15
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void next(NextObjective nextObjective) {
    switch (nextObjective.type()) {
        case SIMPLE:
            Collection<TrafficTreatment> treatments = nextObjective.next();
            if (treatments.size() == 1) {
                TrafficTreatment treatment = treatments.iterator().next();

                // Since we do not support strip_vlan in PORT_VLAN table, we use mod_vlan
                // to modify the packet to desired vlan.
                // Note: if we use push_vlan here, the switch will add a second VLAN tag to the outgoing
                // packet, which is not what we want.
                TrafficTreatment.Builder treatmentWithoutPushVlan = DefaultTrafficTreatment.builder();
                VlanId modVlanId;
                for (Instruction ins : treatment.allInstructions()) {
                    if (ins.type() == Instruction.Type.L2MODIFICATION) {
                        L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                        switch (l2ins.subtype()) {
                            case ETH_DST:
                                treatmentWithoutPushVlan.setEthDst(
                                        ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                                break;
                            case ETH_SRC:
                                treatmentWithoutPushVlan.setEthSrc(
                                        ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
                                break;
                            case VLAN_ID:
                                modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                                treatmentWithoutPushVlan.setVlanId(modVlanId);
                                break;
                            default:
                                break;
                        }
                    } else if (ins.type() == Instruction.Type.OUTPUT) {
                        //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
                        treatmentWithoutPushVlan.add(ins);
                    } else {
                        // Ignore the vlan_pcp action since it's does matter much.
                        log.warn("Driver does not handle this type of TrafficTreatment"
                                + " instruction in nextObjectives:  {}", ins.type());
                    }
                }

                GroupBucket bucket =
                        DefaultGroupBucket.createIndirectGroupBucket(treatmentWithoutPushVlan.build());
                final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
                GroupDescription groupDescription
                        = new DefaultGroupDescription(deviceId,
                        GroupDescription.Type.INDIRECT,
                        new GroupBuckets(Collections
                                .singletonList(bucket)),
                        key,
                        null, // let group service determine group id
                        nextObjective.appId());
                groupService.addGroup(groupDescription);
                pendingGroups.put(key, nextObjective);
            }
            break;
        case HASHED:
        case BROADCAST:
        case FAILOVER:
            fail(nextObjective, ObjectiveError.UNSUPPORTED);
            log.warn("Unsupported next objective type {}", nextObjective.type());
            break;
        default:
            fail(nextObjective, ObjectiveError.UNKNOWN);
            log.warn("Unknown next objective type {}", nextObjective.type());
    }

}
 
Example 16
Source File: NokiaOltPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void forward(ForwardingObjective fwd) {

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

    if (checkForEAPOL(fwd)) {
        log.warn("Discarding EAPOL flow which is not supported on this pipeline");
        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()) {
        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);
    } else {
        TrafficSelector selector = fwd.selector();

        if (fwd.treatment() != null) {
            // Deal with SPECIFIC and VERSATILE in the same manner.
            FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
                    .forDevice(deviceId)
                    .withSelector(selector)
                    .fromApp(fwd.appId())
                    .withPriority(fwd.priority())
                    .withTreatment(fwd.treatment());

            if (fwd.permanent()) {
                ruleBuilder.makePermanent();
            } else {
                ruleBuilder.makeTemporary(fwd.timeout());
            }
            installObjective(ruleBuilder, fwd);

        } else {
            log.error("No treatment error: {}", fwd);
            fail(fwd, ObjectiveError.UNSUPPORTED);
        }
    }

}
 
Example 17
Source File: Ofdpa2GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private GroupInfo prepareL3UnicastGroup(NextObjective nextObj, NextGroup next) {

       ImmutableList.Builder<GroupInfo> groupInfoBuilder = ImmutableList.builder();
       TrafficTreatment treatment = nextObj.next().iterator().next();

       VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
       if (assignedVlan == null) {
            log.warn("VLAN ID required by next obj is missing. Abort.");
            return null;
       }

       List<GroupInfo> l2GroupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
       GroupDescription l2InterfaceGroupDesc = l2GroupInfos.get(0).innerMostGroupDesc();
       GroupKey l2groupkey = l2InterfaceGroupDesc.appCookie();

       TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
       VlanId vlanid = null;
       MacAddress srcMac;
       MacAddress dstMac;
       for (Instruction ins : treatment.allInstructions()) {
            if (ins.type() == Instruction.Type.L2MODIFICATION) {
                L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
                switch (l2ins.subtype()) {
                    case ETH_DST:
                        dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
                        outerTtb.setEthDst(dstMac);
                        break;
                    case ETH_SRC:
                        srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
                        outerTtb.setEthSrc(srcMac);
                        break;
                    case VLAN_ID:
                        vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                            outerTtb.setVlanId(vlanid);
                        break;
                    default:
                        break;
                }
            } else {
                log.debug("Driver does not handle this type of TrafficTreatment"
                        + " instruction in l2l3chain:  {} - {}", ins.type(), ins);
            }
       }

       GroupId l2groupId = new GroupId(l2InterfaceGroupDesc.givenGroupId());
       outerTtb.group(l2groupId);

       // we need the top level group's key to point the flow to it
       List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
       GroupKey l3groupkey = gkeys.get(0).peekFirst();
       GroupId grpId = groupService.getGroup(deviceId, l3groupkey).id();
       int l3groupId = grpId.id();

       // create the l3unicast group description to wait for the
       // l2 interface group to be processed
       GroupBucket l3UnicastGroupBucket =  DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());

       GroupDescription l3UnicastGroupDescription = new DefaultGroupDescription(deviceId,
                                                        GroupDescription.Type.INDIRECT,
                                                        new GroupBuckets(Collections.singletonList(
                                                        l3UnicastGroupBucket)), l3groupkey,
                                                        l3groupId, nextObj.appId());

      // store l2groupkey with the groupChainElem for the outer-group that depends on it
      GroupChainElem gce = new GroupChainElem(l3UnicastGroupDescription, 1, false, deviceId);
      updatePendingGroups(l2groupkey, gce);

      log.debug("Trying L3-Interface: device:{} gid:{} gkey:{} nextid:{}",
                        deviceId, Integer.toHexString(l3groupId), l3groupkey, nextObj.id());

      groupInfoBuilder.add(new GroupInfo(l2InterfaceGroupDesc,
                    l3UnicastGroupDescription));

      return groupInfoBuilder.build().iterator().next();
    }
 
Example 18
Source File: Ofdpa3GroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method for dividing the l2/l3 instructions from the mpls
 * instructions.
 *
 * @param treatment the treatment to analyze
 * @param l2L3Treatment the l2/l3 treatment builder
 * @param mplsTreatment the mpls treatment builder
 */
private void createL2L3AndMplsTreatments(TrafficTreatment treatment,
                                         TrafficTreatment.Builder l2L3Treatment,
                                         TrafficTreatment.Builder mplsTreatment) {

    for (Instruction ins : treatment.allInstructions()) {

        if (ins.type() == Instruction.Type.L2MODIFICATION) {
            L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
            switch (l2ins.subtype()) {
                // These instructions have to go in the l2/l3 treatment.
                case ETH_DST:
                case ETH_SRC:
                case VLAN_ID:
                case VLAN_POP:
                    l2L3Treatment.add(ins);
                    break;
                // These instructions have to go in the mpls treatment.
                case MPLS_BOS:
                case DEC_MPLS_TTL:
                case MPLS_LABEL:
                case MPLS_PUSH:
                    mplsTreatment.add(ins);
                    break;
                default:
                log.warn("Driver does not handle TrafficTreatment"
                        + " L2Mod {} for pw next-obj", l2ins.subtype());
                    break;
            }
        } else if (ins.type() == Instruction.Type.OUTPUT) {
            // The output goes in the l2/l3 treatment.
            l2L3Treatment.add(ins);
        } else if (ins.type() == Instruction.Type.L3MODIFICATION) {
             // We support partially the l3 instructions.
            L3ModificationInstruction l3ins = (L3ModificationInstruction) ins;
            switch (l3ins.subtype()) {
                case TTL_OUT:
                    mplsTreatment.add(ins);
                    break;
                default:
                log.warn("Driver does not handle TrafficTreatment"
                        + " L3Mod for pw next-obj", l3ins.subtype());
            }

        } else {
            log.warn("Driver does not handle this type of TrafficTreatment"
                    + " instruction for pw next-obj: {} - {}",
                     ins.type(), ins);
        }
    }
}
 
Example 19
Source File: Ofdpa3Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method for dividing the tunnel instructions from the mpls
 * instructions.
 *
 * @param treatment the treatment to analyze
 * @param mplsTreatment the mpls treatment builder
 */
private void createMplsTreatment(TrafficTreatment treatment,
                                 TrafficTreatment.Builder mplsTreatment) {

    for (Instruction ins : treatment.allInstructions()) {

        if (ins.type() == Instruction.Type.L2MODIFICATION) {
            L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
            switch (l2ins.subtype()) {
                // These instructions have to go in the mpls
                // treatment.
                case TUNNEL_ID:
                    break;
                case DEC_MPLS_TTL:
                case MPLS_POP:
                    mplsTreatment.add(ins);
                    break;
                default:
                    log.warn("Driver does not handle this type of TrafficTreatment"
                                     + " instruction in nextObjectives: {} - {}",
                             ins.type(), ins);
                    break;
            }
        } else if (ins.type() == Instruction.Type.OUTPUT) {
            break;
        } else if (ins.type() == Instruction.Type.L3MODIFICATION) {
            // We support partially the l3 instructions.
            L3ModificationInstruction l3ins = (L3ModificationInstruction) ins;
            switch (l3ins.subtype()) {
                case TTL_IN:
                    mplsTreatment.add(ins);
                    break;
                default:
                    log.warn("Driver does not handle this type of TrafficTreatment"
                                     + " instruction in nextObjectives: {} - {}",
                             ins.type(), ins);
            }

        } else {
            log.warn("Driver does not handle this type of TrafficTreatment"
                             + " instruction in nextObjectives: {} - {}",
                     ins.type(), ins);
        }
    }
}
 
Example 20
Source File: GroupModBuilder.java    From onos with Apache License 2.0 4 votes vote down vote up
private List<OFAction> buildActions(TrafficTreatment treatment) {
    if (treatment == null) {
        return Collections.emptyList();
    }

    List<OFAction> actions = new LinkedList<>();
    for (Instruction i : treatment.allInstructions()) {
        switch (i.type()) {
            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:
                Instructions.OutputInstruction out =
                        (Instructions.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:
                Instructions.GroupInstruction grp =
                        (Instructions.GroupInstruction) i;
                OFActionGroup.Builder actgrp = factory.actions().buildGroup()
                        .setGroup(OFGroup.of(grp.groupId().id()));
                actions.add(actgrp.build());
                break;
            case EXTENSION:
                Instructions.ExtensionInstructionWrapper wrapper =
                (Instructions.ExtensionInstructionWrapper) i;
                actions.add(buildExtensionAction(
                        wrapper.extensionInstruction(), wrapper.deviceId()));
                break;
            default:
                log.warn("Instruction type {} not yet implemented.", i.type());
        }
    }

    return actions;
}