Search in sources :

Example 16 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 17 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 18 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)

Example 19 with NetworkResource

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

the class IntentsResourceTest method testRemove.

/**
 * Tests removing an intent with DELETE.
 */
@Test
public void testRemove() {
    final HashSet<NetworkResource> resources = new HashSet<>();
    resources.add(new MockResource(1));
    resources.add(new MockResource(2));
    resources.add(new MockResource(3));
    final Intent intent = new MockIntent(3L, resources);
    final ApplicationId appId = new DefaultApplicationId(2, "app");
    IntentService fakeManager = new FakeIntentManager();
    expect(mockCoreService.getAppId("app")).andReturn(appId).once();
    replay(mockCoreService);
    mockIntentService.withdraw(anyObject());
    expectLastCall().andDelegateTo(fakeManager).once();
    expect(mockIntentService.getIntent(Key.of(2, appId))).andReturn(intent).once();
    expect(mockIntentService.getIntent(Key.of("0x2", appId))).andReturn(null).once();
    mockIntentService.addListener(anyObject());
    expectLastCall().andDelegateTo(fakeManager).once();
    mockIntentService.removeListener(anyObject());
    expectLastCall().andDelegateTo(fakeManager).once();
    replay(mockIntentService);
    WebTarget wt = target();
    Response response = wt.path("intents/app/0x2").request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).delete();
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) Response(javax.ws.rs.core.Response) IntentService(org.onosproject.net.intent.IntentService) FakeIntentManager(org.onosproject.net.intent.FakeIntentManager) 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) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with NetworkResource

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

the class IntentsResourceTest method testIntentsArrayWithDetail.

/**
 * Tests the result of the rest api GET when intents are defined and the detail flag is true.
 */
@Test
public void testIntentsArrayWithDetail() {
    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", true).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, true));
}
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)

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