Search in sources :

Example 6 with NetworkResource

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;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 7 with NetworkResource

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"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 8 with NetworkResource

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()));
}
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 9 with NetworkResource

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));
}
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) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 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)

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