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

The following examples show how to use org.onosproject.net.flow.TrafficTreatment#immediate() . 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
/**
 * Determines if the filtering objective will be used for a pseudowire.
 *
 * @param filteringObjective the filtering objective
 * @return True if objective was created for a pseudowire, false otherwise.
 */
static boolean isPseudowire(FilteringObjective filteringObjective) {
    if (filteringObjective.meta() != null) {
        TrafficTreatment treatment = filteringObjective.meta();
        for (Instruction instr : treatment.immediate()) {
            if (instr.type().equals(Instruction.Type.L2MODIFICATION)) {

                L2ModificationInstruction l2Instr = (L2ModificationInstruction) instr;
                if (l2Instr.subtype().equals(L2SubType.TUNNEL_ID)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: FlowViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public String format(Object value) {
    FlowEntry flow = (FlowEntry) value;
    TrafficTreatment treatment = flow.treatment();
    List<Instruction> imm = treatment.immediate();
    List<Instruction> def = treatment.deferred();
    if (imm.isEmpty() &&
            def.isEmpty() &&
            treatment.metered() == null &&
            treatment.tableTransition() == null &&
            treatment.writeMetadata() == null) {
        return MSG_NO_TREATMENT;
    }

    StringBuilder sb = new StringBuilder();

    if (!shortFormat) {
        sb.append(TREATMENT_INSTRUCTIONS).append(COLON).append(SPACE);
    }

    formatInstructs(sb, imm, IMM);
    formatInstructs(sb, def, DEF);

    treatment.meters().forEach(meterInstruction ->
            addLabVal(sb, METERED, meterInstruction)
    );
    addLabVal(sb, TRANSITION, treatment.tableTransition());
    addLabVal(sb, METADATA, treatment.writeMetadata());

    sb.append(CLEARED).append(COLON)
            .append(treatment.clearedDeferred());

    return sb.toString();
}
 
Example 3
Source File: OpenRoadmFlowRule.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. Build an OpenRoadm flow rule from the passed rule.
 *
 *  @param rule ONOS flow rule that we have to process
 *  @param linePorts List of ports that are line ports (degrees) used
 *   to know the Type of this connection.
 *
 * We store and construct attributes like interface names to support
 * this OpenROADM connection.
 */
public OpenRoadmFlowRule(FlowRule rule, List<PortNumber> linePorts) {
    super(rule);

    TrafficSelector trafficSelector = rule.selector();
    PortCriterion pc = (PortCriterion) trafficSelector.getCriterion(IN_PORT);
    checkArgument(pc != null, "Missing IN_PORT Criterion");
    inPortNumber = pc.port();

    // Generally, Sigtype and ochSignal could be null. This would mean e.g. a
    // port switching connection.
    OchSignalCriterion osc = (OchSignalCriterion) trafficSelector.getCriterion(OCH_SIGID);
    // checkArgument(osc != null, "Missing OCH_SIGID Criterion");
    if (osc != null) {
        ochSignal = osc.lambda();
    }

    TrafficTreatment trafficTreatment = rule.treatment();
    List<Instruction> instructions = trafficTreatment.immediate();

    outPortNumber = instructions.stream()
                      .filter(i -> i.type() == Instruction.Type.OUTPUT)
                      .map(i -> ((OutputInstruction) i).port())
                      .findFirst()
                      .orElse(null);
    checkArgument(outPortNumber != null, "Missing OUTPUT Instruction");

    if (linePorts.contains(inPortNumber) && linePorts.contains(outPortNumber)) {
        type = Type.EXPRESS_LINK;
    }
    if (!linePorts.contains(inPortNumber) && linePorts.contains(outPortNumber)) {
        type = Type.ADD_LINK;
    }
    if (linePorts.contains(inPortNumber) && !linePorts.contains(outPortNumber)) {
        type = Type.DROP_LINK;
    }
    if (!linePorts.contains(inPortNumber) && !linePorts.contains(outPortNumber)) {
        type = Type.LOCAL;
    }
}
 
Example 4
Source File: TrafficTreatmentCodecTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests decoding of a traffic treatment JSON object.
 */
@Test
public void testTrafficTreatmentDecode() throws IOException {
    TrafficTreatment treatment = getTreatment("TrafficTreatment.json");

    List<Instruction> insts = treatment.immediate();
    assertThat(insts.size(), is(2));

    ImmutableSet<String> types = ImmutableSet.of("OUTPUT", "L2MODIFICATION");
    assertThat(types.contains(insts.get(0).type().name()), is(true));
    assertThat(types.contains(insts.get(1).type().name()), is(true));
}