Search in sources :

Example 6 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.

the class TopoIntentFilter method getIntents.

// Produces a list of intents that target all selected hosts, devices, links or connect points.
private List<Intent> getIntents(Set<Host> hosts, Set<Device> devices, Set<Link> links, Set<ConnectPoint> edgePoints, Iterable<Intent> sourceIntents) {
    List<Intent> intents = new ArrayList<>();
    if (hosts.isEmpty() && devices.isEmpty() && links.isEmpty()) {
        return intents;
    }
    Set<OpticalConnectivityIntent> opticalIntents = new HashSet<>();
    // Search through all intents and see if they are relevant to our search.
    for (Intent intent : sourceIntents) {
        if (intentService.getIntentState(intent.key()) == INSTALLED) {
            boolean isRelevant = false;
            if (intent instanceof HostToHostIntent) {
                isRelevant = isIntentRelevantToHosts((HostToHostIntent) intent, hosts) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
            } else if (intent instanceof PointToPointIntent) {
                isRelevant = isIntentRelevant((PointToPointIntent) intent, edgePoints) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
            } else if (intent instanceof MultiPointToSinglePointIntent) {
                isRelevant = isIntentRelevant((MultiPointToSinglePointIntent) intent, edgePoints) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
            } else if (intent instanceof OpticalConnectivityIntent) {
                opticalIntents.add((OpticalConnectivityIntent) intent);
            }
            if (isRelevant) {
                intents.add(intent);
            }
        }
    }
    // packet-level ones.
    for (OpticalConnectivityIntent intent : opticalIntents) {
        if (isIntentRelevant(intent, intents) && isIntentRelevantToDevices(intent, devices)) {
            intents.add(intent);
        }
    }
    return intents;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ArrayList(java.util.ArrayList) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) HashSet(java.util.HashSet)

Example 7 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.

the class TrafficMonitorBase method addEdgeLinksIfNeeded.

protected Iterable<Link> addEdgeLinksIfNeeded(Intent parentIntent, Collection<Link> links) {
    if (parentIntent instanceof HostToHostIntent) {
        links = new HashSet<>(links);
        HostToHostIntent h2h = (HostToHostIntent) parentIntent;
        Host h1 = services.host().getHost(h2h.one());
        Host h2 = services.host().getHost(h2h.two());
        links.add(createEdgeLink(h1, true));
        links.add(createEdgeLink(h2, true));
    }
    return links;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Host(org.onosproject.net.Host)

Example 8 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.

the class IntentsResourceTest method testIntentsArrayWithoutDetail.

/**
 * Tests the result of the rest api GET when intents are defined and the detail flag is false.
 */
@Test
public void testIntentsArrayWithoutDetail() {
    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", false).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, false));
}
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 9 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.

the class IntentsResourceTest method testIntentsForApplicationWithDetail.

/**
 * Tests the result of the rest api GET when intents are defined and the detail flag is true.
 */
@Test
public void testIntentsForApplicationWithDetail() {
    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()).queryParam("detail", true).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, true));
    assertThat(jsonIntents1, is(not(hasIntent(intent2, true))));
    // Verify intents for app_id_2
    final String response2 = wt.path("intents/application/" + APP_ID_2.name()).queryParam("detail", true).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, true));
    assertThat(jsonIntents2, is(not(hasIntent(intent1, true))));
}
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)

Example 10 with HostToHostIntent

use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.

the class IntentsListCommand method detailsFormat.

/**
 * Returns detailed information text about a specific intent.
 *
 * @param intent to print
 * @param state of intent
 * @return detailed information or "" if {@code state} was null
 */
private StringBuilder detailsFormat(Intent intent, IntentState state) {
    StringBuilder builder = new StringBuilder();
    if (state == null) {
        return builder;
    }
    if (!intent.resources().isEmpty()) {
        builder.append('\n').append(format(RESOURCES, intent.resources()));
    }
    if (intent instanceof ConnectivityIntent) {
        ConnectivityIntent ci = (ConnectivityIntent) intent;
        if (!ci.selector().criteria().isEmpty()) {
            builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
        }
        if (!ci.treatment().allInstructions().isEmpty()) {
            builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
        }
        if (ci.constraints() != null && !ci.constraints().isEmpty()) {
            builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
        }
    }
    if (intent instanceof HostToHostIntent) {
        HostToHostIntent pi = (HostToHostIntent) intent;
        builder.append('\n').append(format(SRC + HOST, pi.one()));
        builder.append('\n').append(format(DST + HOST, pi.two()));
    } else if (intent instanceof PointToPointIntent) {
        PointToPointIntent pi = (PointToPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof MultiPointToSinglePointIntent) {
        MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
        builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof SinglePointToMultiPointIntent) {
        SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
    } else if (intent instanceof PathIntent) {
        PathIntent pi = (PathIntent) intent;
        builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
    } else if (intent instanceof LinkCollectionIntent) {
        LinkCollectionIntent li = (LinkCollectionIntent) intent;
        builder.append('\n').append(format("links=%s", li.links()));
        builder.append('\n').append(format(CP, li.egressPoints()));
    } else if (intent instanceof OpticalCircuitIntent) {
        OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    } else if (intent instanceof OpticalConnectivityIntent) {
        OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
        builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
    } else if (intent instanceof OpticalOduIntent) {
        OpticalOduIntent ci = (OpticalOduIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    }
    List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
    if (showInstallable && installable != null && !installable.isEmpty()) {
        builder.append('\n').append(format(INSTALLABLE, installable));
    }
    return builder;
}
Also used : StringFilter(org.onlab.util.StringFilter) StringUtils(org.apache.commons.lang.StringUtils) Tools(org.onlab.util.Tools) IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) JsonNode(com.fasterxml.jackson.databind.JsonNode) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Criterion(org.onosproject.net.flow.criteria.Criterion) NodeId(org.onosproject.cluster.NodeId) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) WordUtils.uncapitalize(org.apache.commons.lang3.text.WordUtils.uncapitalize) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Option(org.apache.karaf.shell.api.action.Option) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent)

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