Search in sources :

Example 16 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class TopologyViewMessageHandler method findIntentByPayload.

private Intent findIntentByPayload(ObjectNode payload) {
    Intent intent;
    Key key;
    int appId = Integer.parseInt(string(payload, APP_ID));
    String appName = string(payload, APP_NAME);
    ApplicationId applicId = new DefaultApplicationId(appId, appName);
    String stringKey = string(payload, KEY);
    try {
        // FIXME: If apps use different string key, but they contains
        // same numeric value (e.g. "020", "0x10", "16", "#10")
        // and one intent using long key (e.g. 16L)
        // this function might return wrong intent.
        long longKey = Long.decode(stringKey);
        key = Key.of(longKey, applicId);
        intent = services.intent().getIntent(key);
        if (intent == null) {
            // Intent might using string key, not long key
            key = Key.of(stringKey, applicId);
            intent = services.intent().getIntent(key);
        }
    } catch (NumberFormatException ex) {
        // string key
        key = Key.of(stringKey, applicId);
        intent = services.intent().getIntent(key);
    }
    log.debug("Attempting to select intent by key={}", key);
    return intent;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint.fromString(org.onosproject.net.ConnectPoint.fromString) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Example 17 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class IntentsResourceTest method testBadRemove.

/**
 * Tests removal of a non existent intent with DELETE.
 */
@Test
public void testBadRemove() {
    final ApplicationId appId = new DefaultApplicationId(2, "app");
    expect(mockCoreService.getAppId("app")).andReturn(appId).once();
    replay(mockCoreService);
    expect(mockIntentService.getIntent(Key.of(2, appId))).andReturn(null).once();
    expect(mockIntentService.getIntent(Key.of("0x2", appId))).andReturn(null).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 : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 18 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId 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 19 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class IntentsResourceTest method testPost.

/**
 * Tests creating an intent with POST.
 */
@Test
public void testPost() {
    ApplicationId testId = new DefaultApplicationId(2, "myApp");
    expect(mockCoreService.getAppId("myApp")).andReturn(testId);
    replay(mockCoreService);
    mockIntentService.submit(anyObject());
    expectLastCall();
    replay(mockIntentService);
    InputStream jsonStream = IntentsResourceTest.class.getResourceAsStream("post-intent.json");
    WebTarget wt = target();
    Response response = wt.path("intents").request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/intents/myApp/"));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Test(org.junit.Test)

Example 20 with DefaultApplicationId

use of org.onosproject.core.DefaultApplicationId in project onos by opennetworkinglab.

the class FlowAnalyzerTest method genFlow.

public FlowRule genFlow(String d, long inPort, long outPort) {
    DeviceId device = DeviceId.deviceId(d);
    TrafficSelector ts = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(inPort)).build();
    TrafficTreatment tt = DefaultTrafficTreatment.builder().add(Instructions.createOutput(PortNumber.portNumber(outPort))).build();
    return DefaultFlowRule.builder().forDevice(device).withSelector(ts).withTreatment(tt).withPriority(1).fromApp(new DefaultApplicationId(5000, "of")).withHardTimeout(50000).makePermanent().build();
}
Also used : DeviceId(org.onosproject.net.DeviceId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Aggregations

DefaultApplicationId (org.onosproject.core.DefaultApplicationId)28 ApplicationId (org.onosproject.core.ApplicationId)19 Test (org.junit.Test)12 IntentMonitorAndRerouteService (org.onosproject.imr.IntentMonitorAndRerouteService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 Before (org.junit.Before)3 TunnelService (org.onosproject.incubator.net.tunnel.TunnelService)3 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 FlowRule (org.onosproject.net.flow.FlowRule)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 EqualsTester (com.google.common.testing.EqualsTester)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DefaultOpticalTunnelEndPoint (org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint)2