Java Code Examples for org.onosproject.net.flow.FlowRule#treatment()

The following examples show how to use org.onosproject.net.flow.FlowRule#treatment() . 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: 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 2
Source File: FlowRuleCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode encode(FlowRule flowRule, CodecContext context) {
    checkNotNull(flowRule, "Flow rule cannot be null");

    CoreService service = context.getService(CoreService.class);
    ApplicationId appId = service.getAppId(flowRule.appId());
    String strAppId = (appId == null) ? "<none>" : appId.name();

    final ObjectNode result = context.mapper().createObjectNode()
            .put(ID, Long.toString(flowRule.id().value()))
            .put(APP_ID, strAppId)
            .put(PRIORITY, flowRule.priority())
            .put(TIMEOUT, flowRule.timeout())
            .put(IS_PERMANENT, flowRule.isPermanent())
            .put(DEVICE_ID, flowRule.deviceId().toString())
            .put(TABLE_ID, flowRule.tableId())
            .put(TABLE_NAME, flowRule.table().toString());

    if (flowRule.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec =
                context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(flowRule.treatment(), context));
    }

    if (flowRule.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec =
                context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(flowRule.selector(), context));
    }

    return result;
}
 
Example 3
Source File: FlowModBuilderVer13.java    From onos with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor for a flow mod builder for OpenFlow 1.3.
 *
 * @param flowRule the flow rule to transform into a flow mod
 * @param factory the OpenFlow factory to use to build the flow mod
 * @param xid the transaction ID
 * @param driverService the device driver service
 */
protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional<Long> xid,
                              Optional<DriverService> driverService) {
    super(flowRule, factory, xid, driverService);

    this.treatment = flowRule.treatment();
}
 
Example 4
Source File: FlowModBuilderVer10.java    From onos with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor for a flow mod builder for OpenFlow 1.0.
 *
 * @param flowRule the flow rule to transform into a flow mod
 * @param factory the OpenFlow factory to use to build the flow mod
 * @param xid the transaction ID
 * @param driverService the device driver service
 */
protected FlowModBuilderVer10(FlowRule flowRule,
                              OFFactory factory, Optional<Long> xid,
                              Optional<DriverService> driverService) {
    super(flowRule, factory, xid, driverService);

    this.treatment = flowRule.treatment();
}