Search in sources :

Example 11 with NetworkResource

use of org.onosproject.net.NetworkResource 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 12 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class IntentsResourceTest method testIntentsArrayWithoutDetail.

/**
 * Tests the result of the rest api GET when intents are defined and the detail flag is false.
 */
@Test
public void testIntentsArrayWithoutDetail() {
    replay(mockIntentService);
    final PointToPointIntent intent1 = PointToPointIntent.builder().appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
    final HashSet<NetworkResource> resources = new HashSet<>();
    resources.add(new MockResource(1));
    resources.add(new MockResource(2));
    resources.add(new MockResource(3));
    final HostToHostIntent intent2 = HostToHostIntent.builder().appId(APP_ID).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
    intents.add(intent1);
    intents.add(intent2);
    final WebTarget wt = target();
    final String response = wt.path("intents").queryParam("detail", false).request().get(String.class);
    assertThat(response, containsString("{\"intents\":["));
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("intents"));
    final JsonArray jsonIntents = result.get("intents").asArray();
    assertThat(jsonIntents, notNullValue());
    assertThat(jsonIntents, hasIntent(intent1, false));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonArray(com.eclipsesource.json.JsonArray) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventHostAvailableMatch.

/**
 * Tests an event for a host becoming available that matches an intent.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventHostAvailableMatch() throws Exception {
    final Device host = device("host1");
    final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, host);
    reasons.add(deviceEvent);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(host.id());
    tracker.addTrackedResources(key, resources);
    deviceListener.event(deviceEvent);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(true));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 14 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventHostUnavailableMatch.

/**
 * Tests an event for a host becoming unavailable that matches an intent.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventHostUnavailableMatch() throws Exception {
    final Device host = device("host1");
    final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, host);
    reasons.add(deviceEvent);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(host.id());
    tracker.addTrackedResources(key, resources);
    deviceListener.event(deviceEvent);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 15 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class FlowObjectiveIntentInstallerTest method createAnotherFlowObjectiveIntents.

/**
 * Creates flow objective Intents with different selector.
 *
 * @return the flow objective Intents
 */
private List<Intent> createAnotherFlowObjectiveIntents() {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).matchInPort(CP1.port()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
    FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).addCondition(selector.getCriterion(Criterion.Type.VLAN_VID)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
    NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
    List<Objective> objectives = ImmutableList.of(filt, next, fwd);
    List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
    List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
    Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
    return ImmutableList.of(intent);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) NetworkResource(org.onosproject.net.NetworkResource) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Aggregations

NetworkResource (org.onosproject.net.NetworkResource)21 Intent (org.onosproject.net.intent.Intent)14 Test (org.junit.Test)11 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)11 PathIntent (org.onosproject.net.intent.PathIntent)11 WebTarget (javax.ws.rs.client.WebTarget)8 HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)8 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 JsonObject (com.eclipsesource.json.JsonObject)7 HashSet (java.util.HashSet)7 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)7 TrafficSelector (org.onosproject.net.flow.TrafficSelector)7 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)7 FlowRule (org.onosproject.net.flow.FlowRule)6 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)6 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 JsonArray (com.eclipsesource.json.JsonArray)3 ConnectPoint (org.onosproject.net.ConnectPoint)3