Search in sources :

Example 66 with FlowRuleIntent

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()));
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) NetworkResource(org.onosproject.net.NetworkResource) List(java.util.List) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) WebTarget(javax.ws.rs.client.WebTarget) FlowEntry(org.onosproject.net.flow.FlowEntry) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 67 with FlowRuleIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 68 with FlowRuleIntent

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();
}
Also used : OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) TributarySlot(org.onosproject.net.TributarySlot) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRule(org.onosproject.net.flow.FlowRule) OduSignalId(org.onosproject.net.OduSignalId) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 69 with FlowRuleIntent

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();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 70 with FlowRuleIntent

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();
}
Also used : FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) TributarySlot(org.onosproject.net.TributarySlot) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRule(org.onosproject.net.flow.FlowRule) OduSignalId(org.onosproject.net.OduSignalId) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)111 Intent (org.onosproject.net.intent.Intent)103 FlowRule (org.onosproject.net.flow.FlowRule)91 Test (org.junit.Test)89 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)67 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)67 List (java.util.List)58 DeviceId (org.onosproject.net.DeviceId)58 Collection (java.util.Collection)57 Collectors (java.util.stream.Collectors)55 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)55 VlanId (org.onlab.packet.VlanId)54 Before (org.junit.Before)52 Collections (java.util.Collections)51 CoreService (org.onosproject.core.CoreService)50 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)50 EasyMock (org.easymock.EasyMock)49 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)49 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)49 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)49