use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createFlowRuleIntentsWithSameMatch.
/**
* Generates FlowRuleIntents for test. Flow rules in Intent should have same
* match as we created by createFlowRuleIntents method, but action will be
* different.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createFlowRuleIntentsWithSameMatch() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(CP1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, ImmutableList.of(flowRule), resources, PathIntent.ProtectionType.PRIMARY, RG1);
List<Intent> flowRuleIntents = Lists.newArrayList();
flowRuleIntents.add(intent);
return flowRuleIntents;
}
use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventLinkDownMatch.
/**
* Tests an event for a link down where the link matches existing intents.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventLinkDownMatch() throws Exception {
final Link link = link("src", 1, "dst", 2);
final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
reasons.add(linkEvent);
final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
final Key key = Key.of(0x333L, APP_ID);
Collection<NetworkResource> resources = ImmutableSet.of(link);
tracker.addTrackedResources(key, resources);
listener.event(event);
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 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.NetworkResource in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsSingle.
/**
* Tests the result of a rest api GET for a single intent.
*/
@Test
public void testIntentsSingle() {
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);
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();
replay(mockIntentService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/" + APP_ID.name() + "/0").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesIntent(intent, true));
// Test get using numeric value
final String responseNumeric = wt.path("intents/" + APP_ID.name() + "/0x0").request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric, matchesIntent(intent, true));
}
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));
}
Aggregations