use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testReversePathCompilation.
/**
* Tests a pair of devices in an 8 hop path, forward direction.
*/
@Test
public void testReversePathCompilation() {
PointToPointIntent intent = makeIntent(new ConnectPoint(DID_8, PORT_1), new ConnectPoint(DID_1, 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 reverseResultIntent = result.get(0);
assertThat(reverseResultIntent instanceof LinkCollectionIntent, is(true));
if (reverseResultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent reverseLinkCollectionIntent = (LinkCollectionIntent) reverseResultIntent;
FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_1));
assertThat(reverseLinkCollectionIntent.links(), hasSize(hops.length - 1));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S2, S1));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S3, S2));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S4, S3));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S5, S4));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S6, S5));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S7, S6));
assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S8, S7));
assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
assertThat("key is inherited", reverseResultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testKeyRGBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly using groups.
* An intent asks to allocate bandwidth using the intent key as a reference.
* Then, the intent is submitted with the same key and a group set.
* Previous allocations should be released and new resources should be
* allocated using the group.
*/
@Test
public void testKeyRGBandwidthConstrainedIntentAllocation() {
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();
ResourceGroup resourceGroup = ResourceGroup.of(100);
final PointToPointIntent newIntent = makeIntent(intentKey, new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
compiler.compile(newIntent, 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 testSuggestedPathNotAvailable.
/**
* Test that if a suggested path isn't available it applies another available path.
*/
@Test
public void testSuggestedPathNotAvailable() {
String[] suggestedPathHops = { S1, S3, S8 };
String[] shortestPath = { S1, S2, S8 };
List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links();
PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_8, PORT_2), suggestedPath);
String[][] path = { shortestPath };
PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(path);
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent resultLinkIntent = (LinkCollectionIntent) resultIntent;
FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_2));
// 5 links for the hops, plus one default link on ingress and egress
assertThat(resultLinkIntent.links(), hasSize(shortestPath.length - 1));
assertThat(resultLinkIntent.links(), linksHasPath(S1, S2));
assertThat(resultLinkIntent.links(), linksHasPath(S2, S8));
assertThat(resultLinkIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(resultLinkIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class PointToPointIntentCodec method decode.
@Override
public PointToPointIntent decode(ObjectNode json, CodecContext context) {
PointToPointIntent.Builder builder = PointToPointIntent.builder();
IntentCodec.intentAttributes(json, context, builder);
ConnectivityIntentCodec.intentAttributes(json, context, builder);
ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT), INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
ConnectPoint ingress = context.codec(ConnectPoint.class).decode(ingressJson, context);
builder.filteredIngressPoint(new FilteredConnectPoint(ingress));
ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT), EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
ConnectPoint egress = context.codec(ConnectPoint.class).decode(egressJson, context);
builder.filteredEgressPoint(new FilteredConnectPoint(egress));
return builder.build();
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class IntentCodecTest method decodePointToPointIntent.
/**
* Tests the point to point intent JSON codec.
*
* @throws IOException if JSON processing fails
*/
@Test
public void decodePointToPointIntent() throws IOException {
JsonCodec<Intent> intentCodec = context.codec(Intent.class);
assertThat(intentCodec, notNullValue());
Intent intent = getIntent("PointToPointIntent.json", intentCodec);
assertThat(intent, notNullValue());
assertThat(intent, instanceOf(PointToPointIntent.class));
PointToPointIntent pointIntent = (PointToPointIntent) intent;
assertThat(pointIntent.priority(), is(55));
assertThat(pointIntent.filteredIngressPoint().connectPoint().deviceId(), is(did("0000000000000001")));
assertThat(pointIntent.filteredIngressPoint().connectPoint().port(), is(PortNumber.portNumber(1)));
assertThat(pointIntent.filteredEgressPoint().connectPoint().deviceId(), is(did("0000000000000007")));
assertThat(pointIntent.filteredEgressPoint().connectPoint().port(), is(PortNumber.portNumber(2)));
assertThat(pointIntent.constraints(), hasSize(1));
assertThat(pointIntent.selector(), notNullValue());
assertThat(pointIntent.selector().criteria(), hasSize(1));
Criterion criterion1 = pointIntent.selector().criteria().iterator().next();
assertThat(criterion1, instanceOf(EthCriterion.class));
EthCriterion ethCriterion = (EthCriterion) criterion1;
assertThat(ethCriterion.mac().toString(), is("11:22:33:44:55:66"));
assertThat(ethCriterion.type().name(), is("ETH_DST"));
assertThat(pointIntent.treatment(), notNullValue());
assertThat(pointIntent.treatment().allInstructions(), hasSize(1));
Instruction instruction1 = pointIntent.treatment().allInstructions().iterator().next();
assertThat(instruction1, instanceOf(ModEtherInstruction.class));
ModEtherInstruction ethInstruction = (ModEtherInstruction) instruction1;
assertThat(ethInstruction.mac().toString(), is("22:33:44:55:66:77"));
assertThat(ethInstruction.type().toString(), is("L2MODIFICATION"));
assertThat(ethInstruction.subtype().toString(), is("ETH_SRC"));
}
Aggregations