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