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());
}
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;
}
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();
}
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;
}
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;
}
Aggregations