Search in sources :

Example 31 with IntentService

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

the class IntentsWebResource method getIntentFlowsById.

/**
 * Gets all related flow entries created by a particular intent.
 * Returns all flow entries of the specified intent.
 *
 * @param appId application identifier
 * @param key   intent key
 * @return 200 OK with intent data
 * @onos.rsModel Relatedflows
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("relatedflows/{appId}/{key}")
public Response getIntentFlowsById(@PathParam("appId") String appId, @PathParam("key") String key) {
    ApplicationId applicationId = get(CoreService.class).getAppId(appId);
    nullIsNotFound(applicationId, APP_ID_NOT_FOUND);
    IntentService intentService = get(IntentService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    Intent intent = intentService.getIntent(Key.of(key, applicationId));
    if (intent == null) {
        long numericalKey = Long.decode(key);
        intent = intentService.getIntent(Key.of(numericalKey, applicationId));
    }
    nullIsNotFound(intent, INTENT_NOT_FOUND);
    ObjectNode root = mapper().createObjectNode();
    root.put(APP_ID, appId);
    root.put(ID, key);
    IntentFilter intentFilter = new IntentFilter(intentService, flowService);
    List<Intent> installables = intentService.getInstallableIntents(intent.key());
    root.put(INTENT_TYPE, intent.getClass().getSimpleName());
    ArrayNode pathsNode = root.putArray(INTENT_PATHS);
    for (List<FlowEntry> flowEntries : intentFilter.readIntentFlows(installables)) {
        ArrayNode flowNode = pathsNode.addArray();
        for (FlowEntry entry : flowEntries) {
            flowNode.add(codec(FlowEntry.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentFilter(org.onosproject.net.intent.util.IntentFilter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with IntentService

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

the class IntentKeyCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Fetch our service and feed it's offerings to the string completer
    IntentService service = AbstractShellCommand.get(IntentService.class);
    Iterator<Intent> it = service.getIntents().iterator();
    SortedSet<String> strings = delegate.getStrings();
    while (it.hasNext()) {
        strings.add(it.next().key().toString());
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Intent(org.onosproject.net.intent.Intent)

Example 33 with IntentService

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

the class OpticalIntentsWebResource method createIntent.

/**
 * Submits a new optical intent.
 * Creates and submits optical intents from the JSON request.
 *
 * @param stream input JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel CreateIntent
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createIntent(InputStream stream) {
    try {
        IntentService service = get(IntentService.class);
        ObjectNode root = readTreeFromStream(mapper(), stream);
        Intent intent = decode(root);
        service.submit(intent);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("intents").path(intent.appId().name()).path(Long.toString(intent.id().fingerprint()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 34 with IntentService

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

the class IntentSynchronizerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    setUpConnectPoints();
    intentService = EasyMock.createMock(IntentService.class);
    intentSynchronizer = new TestIntentSynchronizer();
    intentSynchronizer.coreService = new TestCoreService();
    intentSynchronizer.clusterService = new TestClusterService();
    intentSynchronizer.leadershipService = new LeadershipServiceAdapter();
    intentSynchronizer.intentService = intentService;
    intentSynchronizer.activate();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) LeadershipServiceAdapter(org.onosproject.cluster.LeadershipServiceAdapter) Before(org.junit.Before)

Example 35 with IntentService

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

the class StartMonitorCommand method doExecute.

@Override
protected void doExecute() {
    imrService = get(IntentMonitorAndRerouteService.class);
    intentService = get(IntentService.class);
    if (appId != null && appName != null) {
        if (key != null) {
            /*
                Intent key might be a StringKey or a LongKey, but in any case is
                provided via CLI as a string. To solve only ambiguity we check if
                "--longkey" CLI parameter has been set.
                 */
            if (treatAsLongKey) {
                try {
                    Key intentKeyLong = Key.of(Integer.decode(key), new DefaultApplicationId(appId, appName));
                    for (Intent intent : intentService.getIntents()) {
                        if (intent.key().equals(intentKeyLong)) {
                            imrService.startMonitorIntent(intentKeyLong);
                            print("Started monitoring of intent with LongKey %s", intentKeyLong);
                            return;
                        }
                    }
                    imrService.startMonitorIntent(intentKeyLong);
                    print("Started monitoring of intent with LongKey %s, even if not yet submitted", intentKeyLong);
                } catch (NumberFormatException nfe) {
                    print("\"%s\" is not a valid LongKey", key);
                }
            } else {
                Key intentKeyString = Key.of(key, new DefaultApplicationId(appId, appName));
                for (Intent intent : intentService.getIntents()) {
                    if (intent.key().equals(intentKeyString)) {
                        imrService.startMonitorIntent(intentKeyString);
                        print("Started monitoring of intent with StringKey %s", intentKeyString);
                        return;
                    }
                }
                imrService.startMonitorIntent(intentKeyString);
                print("Started monitoring of intent with StringKey %s, even if not yet submitted", intentKeyString);
            }
        } else {
            intentService.getIntents().forEach(i -> {
                if (i.appId().equals(new DefaultApplicationId(appId, appName))) {
                    imrService.startMonitorIntent(i.key());
                    print("Started monitoring of intent with Key %s", i.key());
                }
            });
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentMonitorAndRerouteService(org.onosproject.imr.IntentMonitorAndRerouteService) Intent(org.onosproject.net.intent.Intent) Key(org.onosproject.net.intent.Key) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Aggregations

IntentService (org.onosproject.net.intent.IntentService)36 Intent (org.onosproject.net.intent.Intent)19 ApplicationId (org.onosproject.core.ApplicationId)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 CoreService (org.onosproject.core.CoreService)7 Key (org.onosproject.net.intent.Key)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)5 Link (org.onosproject.net.Link)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 Constraint (org.onosproject.net.intent.Constraint)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Consumes (javax.ws.rs.Consumes)3