Search in sources :

Example 11 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class VirtualNetworkIntentCreateCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    IntentService virtualNetworkIntentService = service.get(NetworkId.networkId(networkId), IntentService.class);
    ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
    ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    Intent intent = VirtualNetworkIntent.builder().networkId(NetworkId.networkId(networkId)).appId(appId()).key(key()).selector(selector).treatment(treatment).ingressPoint(ingress).egressPoint(egress).constraints(constraints).priority(priority()).build();
    virtualNetworkIntentService.submit(intent);
    print("Virtual intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Intent(org.onosproject.net.intent.Intent) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 12 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class FilteringObjectiveCodec method decode.

@Override
public FilteringObjective decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    CoreService coreService = context.getService(CoreService.class);
    final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    DefaultFilteringObjective.Builder baseBuilder = DefaultFilteringObjective.builder();
    final DefaultFilteringObjective.Builder builder = (DefaultFilteringObjective.Builder) och.decode(json, baseBuilder, context);
    // application id
    JsonNode appIdJson = json.get(APP_ID);
    String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
    builder.fromApp(coreService.registerApplication(appId));
    // decode type
    String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    switch(typeStr) {
        case "PERMIT":
            builder.permit();
            break;
        case "DENY":
            builder.deny();
            break;
        default:
            throw new IllegalArgumentException("The requested type " + typeStr + " is not defined for FilteringObjective.");
    }
    // decode key
    JsonNode keyJson = json.get(KEY);
    if (keyJson != null) {
        Criterion key = criterionCodec.decode((ObjectNode) keyJson, context);
        builder.withKey(key);
    }
    // decode conditions
    JsonNode conditionsJson = json.get(CONDITIONS);
    checkNotNull(conditionsJson);
    if (conditionsJson != null) {
        IntStream.range(0, conditionsJson.size()).forEach(i -> {
            ObjectNode conditionJson = get(conditionsJson, i);
            builder.addCondition(criterionCodec.decode(conditionJson, context));
        });
    }
    // decode meta
    JsonNode metaJson = json.get(META);
    if (metaJson != null) {
        TrafficTreatment trafficTreatment = trafficTreatmentCodec.decode((ObjectNode) metaJson, context);
        builder.withMeta(trafficTreatment);
    }
    // decode operation
    String opStr = nullIsIllegal(json.get(OPERATION), OPERATION + MISSING_MEMBER_MESSAGE).asText();
    FilteringObjective filteringObjective;
    switch(opStr) {
        case "ADD":
            filteringObjective = builder.add();
            break;
        case "REMOVE":
            filteringObjective = builder.remove();
            break;
        default:
            throw new IllegalArgumentException("The requested operation " + opStr + " is not defined for FilteringObjective.");
    }
    return filteringObjective;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 13 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class FlowRuleCodec method decode.

@Override
public FlowRule decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder();
    CoreService coreService = context.getService(CoreService.class);
    JsonNode appIdJson = json.get(APP_ID);
    String appId = appIdJson != null ? appIdJson.asText() : REST_APP_ID;
    resultBuilder.fromApp(coreService.registerApplication(appId));
    int priority = nullIsIllegal(json.get(PRIORITY), PRIORITY + MISSING_MEMBER_MESSAGE).asInt();
    resultBuilder.withPriority(priority);
    boolean isPermanent = nullIsIllegal(json.get(IS_PERMANENT), IS_PERMANENT + MISSING_MEMBER_MESSAGE).asBoolean();
    if (isPermanent) {
        resultBuilder.makePermanent();
    } else {
        resultBuilder.makeTemporary(nullIsIllegal(json.get(TIMEOUT), TIMEOUT + MISSING_MEMBER_MESSAGE + " if the flow is temporary").asInt());
    }
    JsonNode tableIdJson = json.get(TABLE_ID);
    if (tableIdJson != null) {
        String tableId = tableIdJson.asText();
        try {
            int tid = Integer.parseInt(tableId);
            resultBuilder.forTable(IndexTableId.of(tid));
        } catch (NumberFormatException e) {
            resultBuilder.forTable(PiTableId.of(tableId));
        }
    }
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
    resultBuilder.forDevice(deviceId);
    ObjectNode treatmentJson = get(json, TREATMENT);
    if (treatmentJson != null) {
        JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        resultBuilder.withTreatment(treatmentCodec.decode(treatmentJson, context));
    }
    ObjectNode selectorJson = get(json, SELECTOR);
    if (selectorJson != null) {
        JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        resultBuilder.withSelector(selectorCodec.decode(selectorJson, context));
    }
    return resultBuilder.build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Example 14 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class ForwardingObjectiveCodec method encode.

@Override
public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) {
    checkNotNull(forwardingObjective, NOT_NULL_MESSAGE);
    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);
    // encode common properties
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    ObjectNode result = och.encode(forwardingObjective, context);
    // encode id
    result.put(ID, forwardingObjective.id());
    // encode flag
    result.put(FLAG, forwardingObjective.flag().toString());
    // encode op
    result.put(OPERATION, forwardingObjective.op().toString());
    // encode selector
    ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(forwardingObjective.selector(), context);
    result.set(SELECTOR, trafficSelectorNode);
    // encode nextId
    if (forwardingObjective.nextId() != null) {
        result.put(NEXT_ID, forwardingObjective.nextId());
    }
    // encode treatment
    if (forwardingObjective.treatment() != null) {
        ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(forwardingObjective.treatment(), context);
        result.set(TREATMENT, trafficTreatmentNode);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 15 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class GroupBucketCodec method decode.

@Override
public GroupBucket decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // build traffic treatment
    ObjectNode treatmentJson = get(json, TREATMENT);
    TrafficTreatment trafficTreatment = null;
    if (treatmentJson != null) {
        JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        trafficTreatment = treatmentCodec.decode(treatmentJson, context);
    }
    // parse group type
    String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    GroupBucket groupBucket = null;
    switch(type) {
        case "SELECT":
            // parse weight
            int weightInt = nullIsIllegal(json.get(WEIGHT), WEIGHT + MISSING_MEMBER_MESSAGE).asInt();
            groupBucket = DefaultGroupBucket.createSelectGroupBucket(trafficTreatment, (short) weightInt);
            break;
        case "INDIRECT":
            groupBucket = DefaultGroupBucket.createIndirectGroupBucket(trafficTreatment);
            break;
        case "ALL":
            groupBucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment);
            break;
        case "FAILOVER":
            // parse watchPort
            PortNumber watchPort = PortNumber.portNumber(nullIsIllegal(json.get(WATCH_PORT), WATCH_PORT + MISSING_MEMBER_MESSAGE).asText());
            // parse watchGroup
            int groupIdInt = nullIsIllegal(json.get(WATCH_GROUP), WATCH_GROUP + MISSING_MEMBER_MESSAGE).asInt();
            GroupId watchGroup = new GroupId((short) groupIdInt);
            groupBucket = DefaultGroupBucket.createFailoverGroupBucket(trafficTreatment, watchPort, watchGroup);
            break;
        default:
            DefaultGroupBucket.createAllGroupBucket(trafficTreatment);
    }
    return groupBucket;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) GroupId(org.onosproject.core.GroupId)

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)395 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)369 TrafficSelector (org.onosproject.net.flow.TrafficSelector)257 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)236 FlowRule (org.onosproject.net.flow.FlowRule)93 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)86 PiAction (org.onosproject.net.pi.runtime.PiAction)79 Test (org.junit.Test)78 PortNumber (org.onosproject.net.PortNumber)70 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)56 Instruction (org.onosproject.net.flow.instructions.Instruction)52 DeviceId (org.onosproject.net.DeviceId)46 NextObjective (org.onosproject.net.flowobjective.NextObjective)45 ConnectPoint (org.onosproject.net.ConnectPoint)44 List (java.util.List)43 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)43 Ethernet (org.onlab.packet.Ethernet)40 Criterion (org.onosproject.net.flow.criteria.Criterion)39 GroupBucket (org.onosproject.net.group.GroupBucket)39 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)37