use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class ConnectivityIntentCodec method intentAttributes.
/**
* Extracts connectivity intent specific attributes from a JSON object
* and adds them to a builder.
*
* @param json root JSON object
* @param context code context
* @param builder builder to use for storing the attributes. Constraints,
* selector and treatment are modified by this call.
*/
public static void intentAttributes(ObjectNode json, CodecContext context, ConnectivityIntent.Builder builder) {
JsonNode constraintsJson = json.get(CONSTRAINTS);
if (constraintsJson != null) {
JsonCodec<Constraint> constraintsCodec = context.codec(Constraint.class);
ArrayList<Constraint> constraints = new ArrayList<>(constraintsJson.size());
IntStream.range(0, constraintsJson.size()).forEach(i -> constraints.add(constraintsCodec.decode(get(constraintsJson, i), context)));
builder.constraints(constraints);
}
ObjectNode selectorJson = get(json, SELECTOR);
if (selectorJson != null) {
JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
TrafficSelector selector = selectorCodec.decode(selectorJson, context);
builder.selector(selector);
}
ObjectNode treatmentJson = get(json, TREATMENT);
if (treatmentJson != null) {
JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
TrafficTreatment treatment = treatmentCodec.decode(treatmentJson, context);
builder.treatment(treatment);
}
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class ConnectivityIntentCodec method encode.
@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
checkNotNull(intent, "Connectivity intent cannot be null");
final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
final ObjectNode result = intentCodec.encode(intent, context);
if (intent.selector() != null) {
final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
}
if (intent.treatment() != null) {
final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
}
result.put(IntentCodec.PRIORITY, intent.priority());
if (intent.constraints() != null) {
final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
if (intent.constraints() != null) {
final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
for (final Constraint constraint : intent.constraints()) {
final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
jsonConstraints.add(constraintNode);
}
}
}
return result;
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly.
*/
@Test
public void testBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
final double bpsToReserve = 100.0;
ContinuousResource resourceSw1P1 = Resources.continuous(DID_1, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw1P2 = Resources.continuous(DID_1, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P1 = Resources.continuous(DID_2, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P2 = Resources.continuous(DID_2, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P1 = Resources.continuous(DID_3, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P2 = Resources.continuous(DID_3, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P3 = Resources.continuous(DID_3, PORT_3, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw4P1 = Resources.continuous(DID_4, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw4P2 = Resources.continuous(DID_4, PORT_2, Bandwidth.class).resource(bpsToReserve);
String[] hops = { DID_3.toString() };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_1)));
TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, ipPrefixSelector, constraints);
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceAllocation rA1 = new ResourceAllocation(resourceSw1P1, intentKey);
ResourceAllocation rA2 = new ResourceAllocation(resourceSw1P2, intentKey);
ResourceAllocation rA3 = new ResourceAllocation(resourceSw2P1, intentKey);
ResourceAllocation rA4 = new ResourceAllocation(resourceSw2P2, intentKey);
ResourceAllocation rA5 = new ResourceAllocation(resourceSw3P1, intentKey);
ResourceAllocation rA6 = new ResourceAllocation(resourceSw3P2, intentKey);
ResourceAllocation rA7 = new ResourceAllocation(resourceSw3P3, intentKey);
ResourceAllocation rA8 = new ResourceAllocation(resourceSw4P1, intentKey);
ResourceAllocation rA9 = new ResourceAllocation(resourceSw4P2, intentKey);
Set<ResourceAllocation> expectedResourceAllocations = ImmutableSet.of(rA1, rA2, rA3, rA4, rA5, rA6, rA7, rA8, rA9);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
assertThat(resourceAllocations, hasSize(9));
assertEquals(expectedResourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testRGBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly using the resource
* group. An intent with a resource group is submitted.
*/
@Test
public void testRGBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
ResourceGroup resourceGroup = ResourceGroup.of(100);
String[] hops = { S1, S2, S3 };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup);
ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup);
ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup);
ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup);
ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup);
ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testBandwidthConstrainedIntentFailure.
/**
* Tests that requests with insufficient available bandwidth fail.
*/
@Test
public void testBandwidthConstrainedIntentFailure() {
final double bpsTotal = 10.0;
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
try {
final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints);
String[] hops = { S1, S2, S3 };
final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
fail("Point to Point compilation with insufficient bandwidth does " + "not throw exception.");
} catch (PathNotFoundException noPath) {
assertThat(noPath.getMessage(), containsString("No path"));
}
}
Aggregations