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"));
}
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"));
}
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);
}
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));
}
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));
}
Aggregations