use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testSameSwitchDifferentPortsIntentCompilation.
/**
* Tests the compilation of an intent which designates two different ports
* on the same switch.
*/
@Test
public void testSameSwitchDifferentPortsIntentCompilation() {
FilteredConnectPoint src = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
FilteredConnectPoint dst = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_2));
PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_1, PORT_2));
String[] hops = { S1 };
PointToPointIntentCompiler compiler = makeCompiler(hops);
List<Intent> compiled = compiler.compile(intent, null);
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
assertThat(compiled, hasSize(1));
assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class)));
LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0);
Set<Link> links = linkCollectionIntent.links();
assertThat(links, hasSize(0));
assertThat(linkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(src)));
assertThat(linkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(dst)));
}
use of org.onosproject.net.intent.PointToPointIntent 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.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testForwardPathCompilation.
/**
* Tests a pair of devices in an 8 hop path, forward direction.
*/
@Test
public void testForwardPathCompilation() {
PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_8, PORT_1));
String[] hops = { S1, S2, S3, S4, S5, S6, S7, S8 };
PointToPointIntentCompiler compiler = makeCompiler(hops);
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent forwardResultIntent = result.get(0);
assertThat(forwardResultIntent instanceof LinkCollectionIntent, is(true));
if (forwardResultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent forwardIntent = (LinkCollectionIntent) forwardResultIntent;
FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_1));
// 7 links for the hops, plus one default lnk on ingress and egress
assertThat(forwardIntent.links(), hasSize(hops.length - 1));
assertThat(forwardIntent.links(), linksHasPath(S1, S2));
assertThat(forwardIntent.links(), linksHasPath(S2, S3));
assertThat(forwardIntent.links(), linksHasPath(S3, S4));
assertThat(forwardIntent.links(), linksHasPath(S4, S5));
assertThat(forwardIntent.links(), linksHasPath(S5, S6));
assertThat(forwardIntent.links(), linksHasPath(S6, S7));
assertThat(forwardIntent.links(), linksHasPath(S7, S8));
assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
assertThat("key is inherited", forwardResultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.PointToPointIntent 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"));
}
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly. An intent with a
* key only is submitted.
*/
@Test
public void testBandwidthConstrainedIntentAllocation() {
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);
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);
}
Aggregations