use of org.onosproject.net.intent.constraint.BandwidthConstraint in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testTwoBandwidthConstrainedIntentAllocation.
/**
* Tests that bandwidth resources don't get allocated twice if the intent
* is submitted twice.
*/
@Test
public void testTwoBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
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);
PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
// Resubmit the same intent
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, intentKey);
ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, intentKey);
ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, intentKey);
ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, intentKey);
ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, intentKey);
ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, intentKey);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.constraint.BandwidthConstraint in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testSuggestedPathBandwidthConstrainedIntentSuccess.
/**
* Tests that requests with suggested path
* and with sufficient available bandwidth succeed.
*/
@Test
public void testSuggestedPathBandwidthConstrainedIntentSuccess() {
final double bpsTotal = 1000.0;
final double bpsToReserve = 100.0;
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
String[] suggestedPathHops = { S1, S4, S5, S3 };
List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links();
final PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), suggestedPath, constraints);
String[][] hops = { { S1, S2, S3 }, suggestedPathHops };
final PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(hops, resourceService);
final List<Intent> compiledIntents = compiler.compile(intent, null);
assertThat(compiledIntents, Matchers.notNullValue());
assertThat(compiledIntents, hasSize(1));
assertThat("key is inherited", compiledIntents.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
use of org.onosproject.net.intent.constraint.BandwidthConstraint in project onos by opennetworkinglab.
the class SinglePointToMultiPointIntentCompilerTest 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)));
FilteredConnectPoint ingress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_1));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_2)), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_2)));
TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress, ipPrefixSelector, constraints);
SinglePointToMultiPointIntentCompiler 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.BandwidthConstraint in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest 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_S1, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw1P2 = Resources.continuous(DID_S1, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P1 = Resources.continuous(DID_S2, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P2 = Resources.continuous(DID_S2, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P1 = Resources.continuous(DID_S3, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P2 = Resources.continuous(DID_S3, PORT_2, Bandwidth.class).resource(bpsToReserve);
String[] hops = { HOST_ONE, S1, S2, S3, HOST_TWO };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
final HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO, constraints);
HostToHostIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceAllocation rAOne = new ResourceAllocation(resourceSw1P1, intentKey);
ResourceAllocation rATwo = new ResourceAllocation(resourceSw1P2, intentKey);
ResourceAllocation rAThree = new ResourceAllocation(resourceSw2P1, intentKey);
ResourceAllocation rAFour = new ResourceAllocation(resourceSw2P2, intentKey);
ResourceAllocation rAFive = new ResourceAllocation(resourceSw3P1, intentKey);
ResourceAllocation rASix = new ResourceAllocation(resourceSw3P2, intentKey);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.constraint.BandwidthConstraint in project onos by opennetworkinglab.
the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.
/**
* Tests the encoding of an intent with treatment, selector and constraints
* specified.
*/
@Test
public void intentWithTreatmentSelectorAndConstraints() {
ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
DeviceId did1 = did("device1");
DeviceId did2 = did("device2");
DeviceId did3 = did("device3");
Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
Aggregations