use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class AddHostToHostIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
HostId oneId = HostId.hostId(one);
HostId twoId = HostId.hostId(two);
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
HostToHostIntent intent = HostToHostIntent.builder().appId(appId()).key(key()).one(oneId).two(twoId).selector(selector).treatment(treatment).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Host to Host intent submitted:\n%s", intent.toString());
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentCodecTest method hostToHostIntent.
/**
* Tests the encoding of a host to host intent.
*/
@Test
public void hostToHostIntent() {
final HostToHostIntent intent = HostToHostIntent.builder().appId(appId).one(id1).two(id2).build();
final JsonCodec<HostToHostIntent> intentCodec = context.codec(HostToHostIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentCodecTest method decodeHostToHostIntent.
/**
* Tests the host to host intent JSON codec.
*
* @throws IOException
*/
@Test
public void decodeHostToHostIntent() throws IOException {
JsonCodec<Intent> intentCodec = context.codec(Intent.class);
assertThat(intentCodec, notNullValue());
Intent intent = getIntent("HostToHostIntent.json", intentCodec);
assertThat(intent, notNullValue());
assertThat(intent, instanceOf(HostToHostIntent.class));
HostToHostIntent hostIntent = (HostToHostIntent) intent;
assertThat(hostIntent.priority(), is(7));
assertThat(hostIntent.constraints(), hasSize(1));
}
use of org.onosproject.net.intent.HostToHostIntent 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));
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsForApplicationWithoutDetail.
/**
* Tests the result of the rest api GET when intents are defined.
*/
@Test
public void testIntentsForApplicationWithoutDetail() {
final Intent intent1 = PointToPointIntent.builder().key(Key.of(0, APP_ID)).appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
final HostToHostIntent intent2 = HostToHostIntent.builder().key(Key.of(1, APP_ID_2)).appId(APP_ID_2).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
intents.add(intent1);
List<Intent> appIntents1 = new ArrayList<>();
appIntents1.add(intent1);
intents.add(intent2);
List<Intent> appIntents2 = new ArrayList<>();
appIntents2.add(intent2);
expect(mockIntentService.getIntentsByAppId(APP_ID)).andReturn(appIntents1).anyTimes();
expect(mockIntentService.getIntentsByAppId(APP_ID_2)).andReturn(appIntents2).anyTimes();
replay(mockIntentService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID_2.name())).andReturn(APP_ID_2).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Verify intents for app_id
final String response1 = wt.path("intents/application/" + APP_ID.name()).request().get(String.class);
assertThat(response1, containsString("{\"intents\":["));
final JsonObject result1 = Json.parse(response1).asObject();
assertThat(result1, notNullValue());
assertThat(result1.names(), hasSize(1));
assertThat(result1.names().get(0), is("intents"));
final JsonArray jsonIntents1 = result1.get("intents").asArray();
assertThat(jsonIntents1, notNullValue());
assertThat(jsonIntents1.size(), is(1));
assertThat(jsonIntents1, hasIntent(intent1, false));
assertThat(jsonIntents1, is(not(hasIntent(intent2, false))));
// Verify intents for app_id_2 with detail = false
final String response2 = wt.path("intents/application/" + APP_ID_2.name()).queryParam("detail", false).request().get(String.class);
assertThat(response2, containsString("{\"intents\":["));
final JsonObject result2 = Json.parse(response2).asObject();
assertThat(result2, notNullValue());
assertThat(result2.names(), hasSize(1));
assertThat(result2.names().get(0), is("intents"));
final JsonArray jsonIntents2 = result2.get("intents").asArray();
assertThat(jsonIntents2, notNullValue());
assertThat(jsonIntents2.size(), is(1));
assertThat(jsonIntents2, hasIntent(intent2, false));
assertThat(jsonIntents2, is(not(hasIntent(intent1, false))));
}
Aggregations