Search in sources :

Example 36 with CoreService

use of org.onosproject.core.CoreService in project fabric-tna by stratum.

the class FabricUpfProgrammable method setupBehaviour.

@Override
protected boolean setupBehaviour(String opName) {
    /* Always setup internally the behavior to refresh
           the internal references: client, controller, etc*/
    if (!super.setupBehaviour(opName)) {
        return false;
    }
    // Already initialized.
    if (appId != null) {
        return true;
    }
    if (!computeHardwareResourceSizes()) {
        // error message will be printed by computeHardwareResourceSizes()
        return false;
    }
    flowRuleService = handler().get(FlowRuleService.class);
    meterService = handler().get(MeterService.class);
    packetService = handler().get(PacketService.class);
    slicingService = handler().get(SlicingService.class);
    upfTranslator = new FabricUpfTranslator();
    final CoreService coreService = handler().get(CoreService.class);
    appId = coreService.getAppId(Constants.APP_NAME_UPF);
    if (appId == null) {
        log.warn("Application ID is null. Cannot initialize behaviour.");
        return false;
    }
    var capabilities = new FabricCapabilities(pipeconf);
    if (!capabilities.supportUpf()) {
        log.warn("Pipeconf {} on {} does not support UPF capabilities, " + "cannot perform {}", pipeconf.id(), deviceId, opName);
        return false;
    }
    return true;
}
Also used : PacketService(org.onosproject.net.packet.PacketService) CoreService(org.onosproject.core.CoreService) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) FlowRuleService(org.onosproject.net.flow.FlowRuleService) MeterService(org.onosproject.net.meter.MeterService) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService)

Example 37 with CoreService

use of org.onosproject.core.CoreService in project fabric-tna by stratum.

the class FabricIntProgrammable method setupBehaviour.

private boolean setupBehaviour() {
    deviceId = this.data().deviceId();
    flowRuleService = handler().get(FlowRuleService.class);
    groupService = handler().get(GroupService.class);
    cfgService = handler().get(NetworkConfigService.class);
    hostService = handler().get(HostService.class);
    final CoreService coreService = handler().get(CoreService.class);
    appId = coreService.getAppId(Constants.APP_NAME);
    if (appId == null) {
        log.warn("Application ID is null. Cannot initialize behaviour.");
        return false;
    }
    return true;
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) GroupService(org.onosproject.net.group.GroupService)

Example 38 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class VirtualFlowsListCommand method printFlows.

/**
 * Prints flows.
 *
 * @param d     the device
 * @param flows the set of flows for that device
 * @param coreService core system service
 */
protected void printFlows(Device d, List<FlowEntry> flows, CoreService coreService) {
    List<FlowEntry> filteredFlows = flows.stream().filter(f -> contentFilter.filter(f)).collect(Collectors.toList());
    boolean empty = filteredFlows == null || filteredFlows.isEmpty();
    print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : filteredFlows.size());
    if (empty || countOnly) {
        return;
    }
    for (FlowEntry f : filteredFlows) {
        if (shortOutput) {
            print(SHORT_FORMAT, f.state(), f.bytes(), f.packets(), f.tableId(), f.priority(), f.selector().criteria(), printTreatment(f.treatment()));
        } else {
            ApplicationId appId = coreService.getAppId(f.appId());
            print(LONG_FORMAT, Long.toHexString(f.id().value()), f.state(), f.bytes(), f.packets(), f.life(), f.liveType(), f.priority(), f.tableId(), appId != null ? appId.name() : "<none>", f.selector().criteria(), f.treatment());
        }
    }
}
Also used : StringFilter(org.onlab.util.StringFilter) Comparators(org.onosproject.utils.Comparators) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowRuleStatusCompleter(org.onosproject.cli.net.FlowRuleStatusCompleter) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) JsonNode(com.fasterxml.jackson.databind.JsonNode) PlaceholderCompleter(org.onosproject.cli.PlaceholderCompleter) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Device(org.onosproject.net.Device) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) SortedMap(java.util.SortedMap) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 39 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class VirtualNetworkIntentRemoveCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    IntentService intentService = service.get(NetworkId.networkId(networkId), IntentService.class);
    CoreService coreService = get(CoreService.class);
    if (purgeAfterRemove || sync) {
        print("Using \"sync\" to remove/purge intents - this may take a while...");
        print("Check \"summary\" to see remove/purge progress.");
    }
    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
        appId = coreService.getAppId(applicationIdString);
        if (appId == null) {
            print("Cannot find application Id %s", applicationIdString);
            return;
        }
    }
    if (isNullOrEmpty(keyString)) {
        for (Intent intent : intentService.getIntents()) {
            if (intent.appId().equals(appId)) {
                removeIntent(intentService, intent);
            }
        }
    } else {
        final Key key;
        if (keyString.startsWith("0x")) {
            // The intent uses a LongKey
            keyString = keyString.replaceFirst("0x", "");
            key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
        } else {
            // The intent uses a StringKey
            key = Key.of(keyString, appId);
        }
        Intent intent = intentService.getIntent(key);
        if (intent != null) {
            removeIntent(intentService, intent);
        } else {
            print("Intent not found!");
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Example 40 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class IntentRemoveCommand method removeIntent.

/**
 * Removes the intents passed as argument, assuming these
 * belong to the application's ID provided (if any) and
 * contain a key string.
 *
 * If an application ID is provided, it will be used to further
 * filter the intents to be removed.
 *
 * @param intents list of intents to remove
 * @param applicationIdString application ID to filter intents
 * @param keyString string to filter intents
 * @param purgeAfterRemove states whether the intents should be also purged
 * @param sync states whether the cli should wait for the operation to finish
 *             before returning
 */
private void removeIntent(Iterable<Intent> intents, String applicationIdString, String keyString, boolean purgeAfterRemove, boolean sync) {
    IntentService intentService = get(IntentService.class);
    CoreService coreService = get(CoreService.class);
    this.applicationIdString = applicationIdString;
    this.keyString = keyString;
    this.purgeAfterRemove = purgeAfterRemove;
    this.sync = sync;
    if (purgeAfterRemove || sync) {
        print("Using \"sync\" to remove/purge intents - this may take a while...");
        print("Check \"summary\" to see remove/purge progress.");
    }
    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
        appId = coreService.getAppId(applicationIdString);
        if (appId == null) {
            print("Cannot find application Id %s", applicationIdString);
            return;
        }
    }
    if (isNullOrEmpty(keyString)) {
        removeIntentsByAppId(intentService, intents, appId);
    } else {
        final Key key;
        if (keyString.startsWith("0x")) {
            // The intent uses a LongKey
            keyString = keyString.replaceFirst("0x", "");
            key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
        } else {
            // The intent uses a StringKey
            key = Key.of(keyString, appId);
        }
        Intent intent = intentService.getIntent(key);
        if (intent != null) {
            removeIntent(intentService, intent);
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Aggregations

CoreService (org.onosproject.core.CoreService)71 Before (org.junit.Before)31 ApplicationId (org.onosproject.core.ApplicationId)30 FlowRuleService (org.onosproject.net.flow.FlowRuleService)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)12 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)12 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 DeviceId (org.onosproject.net.DeviceId)10 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)10 TestServiceDirectory (org.onlab.osgi.TestServiceDirectory)9 MockResourceService (org.onosproject.net.resource.MockResourceService)9 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)8 DistributedVirtualNetworkStore (org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore)8 DeviceService (org.onosproject.net.device.DeviceService)8 TestStorageService (org.onosproject.store.service.TestStorageService)8 ArrayList (java.util.ArrayList)7 DomainService (org.onosproject.net.domain.DomainService)6