use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testRelatedFlowsForIntents.
/**
* Tests the result of a rest api GET for related flows for single intent.
*/
@Test
public void testRelatedFlowsForIntents() {
List<FlowEntry> flowEntries = new ArrayList<>();
flowEntries.add(flow1);
flowEntries.add(flow2);
List<List<FlowEntry>> paths = new ArrayList<>();
paths.add(flowEntries);
List<FlowRule> flowRules = new ArrayList<>();
flowRules.add(flowRule1);
flowRules.add(flowRule2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, flowRules, new HashSet<NetworkResource>(), PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(3L);
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0", APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(0, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of("0x0", APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
expect(mockFlowService.getFlowEntries(deviceId1)).andReturn(flowEntries).anyTimes();
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/relatedflows/" + APP_ID.name() + "/0").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesRelatedFlowEntries(paths, APP_ID.name()));
// Test get using numeric value
final String responseNumeric = wt.path("intents/relatedflows/" + APP_ID.name() + "/0x0").request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesRelatedFlowEntries(paths, APP_ID.name()));
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentInstallables.
/**
* Tests the result of a rest api GET for intent installables.
*/
@Test
public void testIntentInstallables() {
Link link1 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint1).dst(connectPoint2).build();
Link link2 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint3).dst(connectPoint4).build();
Set<NetworkResource> resources = new HashSet<>();
resources.add(link1);
resources.add(link2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, new ArrayList<>(), resources, PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(MockIntent.nextId());
Long intentId = intent.id().id();
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId.toString(), APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(Long.toHexString(intentId), APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/installables/" + APP_ID.name() + "/" + intentId).request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
// Test get using numeric value
final String responseNumeric = wt.path("intents/installables/" + APP_ID.name() + "/" + Long.toHexString(intentId)).request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompilerTest method test1GbeMultiplexOverOdu2.
/**
* Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
* - only one TributarySlot is used
*/
@Test
public void test1GbeMultiplexOverOdu2() {
// Use driver with TributarySlotQuery Behaviour
sut.driverService = new MockDriverServiceWithTs();
ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P1.number());
ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P1.number());
ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
intent = OpticalCircuitIntent.builder().appId(APP_ID).key(KEY1).src(oduCltSrcCP).dst(oduCltDstCP).signalType(D1P1.signalType()).bidirectional(false).build();
sut.activate(null);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(device1.id())).findFirst().get();
// validate SRC selector
TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
selectorBuilder1.matchInPort(oduCltSrcCP.port());
selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
assertThat(rule1.selector(), is(selectorBuilder1.build()));
// validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
Set<TributarySlot> slots = new HashSet<>();
slots.add(TributarySlot.of(1));
OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(D1P2.signalType(), slots);
treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
treatmentBuilder1.setOutput(ochSrcCP.port());
assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(device2.id())).findFirst().get();
// validate DST selector (with OduSignalId, where the same TributarySlot is used)
TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
selectorBuilder2.matchInPort(ochDstCP.port());
selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
assertThat(rule2.selector(), is(selectorBuilder2.build()));
// validate DST treatment
assertThat(rule2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()));
rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", intent.priority(), rule.priority()));
sut.deactivate();
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompilerTest method test10GbeNoMuxOverOdu2.
/**
* Tests compile of OpticalCircuitIntent without allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
* - No TributarySlots are used
*/
@Test
public void test10GbeNoMuxOverOdu2() {
// Use driver without support for TributarySlotQuery Behaviour
sut.driverService = new MockDriverServiceNoTs();
ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
intent = OpticalCircuitIntent.builder().appId(APP_ID).key(KEY1).src(oduCltSrcCP).dst(oduCltDstCP).signalType(D1P3.signalType()).bidirectional(false).build();
sut.activate(null);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(device1.id())).findFirst().get();
// validate SRC selector
TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
selectorBuilder1.matchInPort(oduCltSrcCP.port());
assertThat(rule1.selector(), is(selectorBuilder1.build()));
// validate SRC treatment (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
treatmentBuilder1.setOutput(ochSrcCP.port());
assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(device2.id())).findFirst().get();
// validate DST selector (without OduSignalType and OduSignalId: i.e. No TributarySlots are used)
TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
selectorBuilder2.matchInPort(ochDstCP.port());
assertThat(rule2.selector(), is(selectorBuilder2.build()));
// validate DST treatment
assertThat(rule2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()));
rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", intent.priority(), rule.priority()));
sut.deactivate();
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class OpticalOduIntentCompilerTest method test1GbeMultiplexOverOdu2.
/**
* Tests compile of OpticalOduIntent with allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_1GBE), over OTU ports (with OTU2):
* - only one TributarySlot is used
*/
@Test
public void test1GbeMultiplexOverOdu2() {
intent = OpticalOduIntent.builder().appId(APP_ID).key(KEY1).src(d1p1).dst(d3p2).signalType(D1P1.signalType()).bidirectional(false).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
// 1st Device
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(device1.id())).findFirst().get();
// validate SRC selector
TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
selectorBuilder1.matchInPort(d1p1.port());
selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
assertThat(rule1.selector(), is(selectorBuilder1.build()));
// validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
Set<TributarySlot> slots = new HashSet<>();
slots.add(TributarySlot.of(1));
OduSignalId oduSignalId = OduSignalUtils.buildOduSignalId(OduSignalType.ODU2, slots);
treatmentBuilder1.add(Instructions.modL1OduSignalId(oduSignalId));
treatmentBuilder1.setOutput(d1p2.port());
assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
// 2nd Device
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(device2.id())).findFirst().get();
// validate SRC selector
TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
selectorBuilder2.matchInPort(d2p1.port());
selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
selectorBuilder2.add(Criteria.matchOduSignalId(oduSignalId));
assertThat(rule2.selector(), is(selectorBuilder2.build()));
// validate SRC treatment (with OduSignalId, where 1 TributarySlot is used)
TrafficTreatment.Builder treatmentBuilder2 = DefaultTrafficTreatment.builder();
treatmentBuilder2.add(Instructions.modL1OduSignalId(oduSignalId));
treatmentBuilder2.setOutput(d2p2.port());
assertThat(rule2.treatment(), is(treatmentBuilder2.build()));
// 3rd Device
FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(device3.id())).findFirst().get();
// validate DST selector (with OduSignalId, where the same TributarySlot is used)
TrafficSelector.Builder selectorBuilder3 = DefaultTrafficSelector.builder();
selectorBuilder3.matchInPort(d3p1.port());
selectorBuilder3.add(Criteria.matchOduSignalType(OduSignalType.ODU0));
selectorBuilder3.add(Criteria.matchOduSignalId(oduSignalId));
assertThat(rule3.selector(), is(selectorBuilder3.build()));
// validate DST treatment
assertThat(rule3.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d3p2.port()).build()));
rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", intent.priority(), rule.priority()));
sut.deactivate();
}
Aggregations