Search in sources :

Example 11 with HostToHostIntent

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());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) HostId(org.onosproject.net.HostId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 12 with HostToHostIntent

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 13 with HostToHostIntent

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));
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) IntentJsonMatcher.matchesIntent(org.onosproject.codec.impl.IntentJsonMatcher.matchesIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 14 with HostToHostIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonArray(com.eclipsesource.json.JsonArray) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with HostToHostIntent

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))));
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) 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) WebTarget(javax.ws.rs.client.WebTarget) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Aggregations

HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)15 Test (org.junit.Test)8 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)7 Intent (org.onosproject.net.intent.Intent)7 ArrayList (java.util.ArrayList)5 JsonArray (com.eclipsesource.json.JsonArray)4 JsonObject (com.eclipsesource.json.JsonObject)4 WebTarget (javax.ws.rs.client.WebTarget)4 ConnectPoint (org.onosproject.net.ConnectPoint)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)4 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)4 PathIntent (org.onosproject.net.intent.PathIntent)4 HashSet (java.util.HashSet)3 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 List (java.util.List)2 Set (java.util.Set)2