Search in sources :

Example 41 with ApplicationId

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

the class AddTestFlowsCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowService = get(FlowRuleService.class);
    DeviceService deviceService = get(DeviceService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.registerApplication("onos.test.flow.installer");
    int flowsPerDevice = Integer.parseInt(flows);
    int num = Integer.parseInt(numOfRuns);
    ArrayList<Long> results = Lists.newArrayList();
    Iterable<Device> devices = deviceService.getDevices();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(RandomUtils.nextInt(MAX_OUT_PORT))).build();
    TrafficSelector.Builder sbuilder;
    FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
    FlowRuleOperations.Builder remove = FlowRuleOperations.builder();
    for (Device d : devices) {
        for (long i = 0; i < flowsPerDevice; i++) {
            sbuilder = DefaultTrafficSelector.builder();
            sbuilder.matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i)).matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));
            int randomPriority = RandomUtils.nextInt(FlowRule.MAX_PRIORITY - FlowRule.MIN_PRIORITY + 1) + FlowRule.MIN_PRIORITY;
            FlowRule addRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
            FlowRule removeRule = DefaultFlowRule.builder().forDevice(d.id()).withSelector(sbuilder.build()).withTreatment(treatment).withPriority(randomPriority).fromApp(appId).makeTemporary(10).build();
            rules.add(addRule);
            remove.remove(removeRule);
        }
    }
    // close stages
    rules.newStage();
    remove.newStage();
    for (int i = 0; i < num; i++) {
        printProgress("Run %d:", i);
        latch = new CountDownLatch(2);
        final CountDownLatch addSuccess = new CountDownLatch(1);
        printProgress("..batch add request");
        Stopwatch add = Stopwatch.createStarted();
        flowService.apply(rules.build(new FlowRuleOperationsContext() {

            private final Stopwatch timer = Stopwatch.createStarted();

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                timer.stop();
                printProgress("..add success");
                results.add(timer.elapsed(TimeUnit.MILLISECONDS));
                if (results.size() == num) {
                    if (outputJson()) {
                        print("%s", json(new ObjectMapper(), true, results));
                    } else {
                        printTime(true, results);
                    }
                }
                latch.countDown();
                addSuccess.countDown();
            }
        }));
        try {
            addSuccess.await();
            // wait until all flows reaches ADDED state
            while (!Streams.stream(flowService.getFlowEntriesById(appId)).allMatch(fr -> fr.state() == FlowEntryState.ADDED)) {
                Thread.sleep(100);
            }
            add.stop();
            printProgress("..completed %d ± 100 ms", add.elapsed(TimeUnit.MILLISECONDS));
        } catch (InterruptedException e1) {
            printProgress("Interrupted");
            Thread.currentThread().interrupt();
        }
        printProgress("..cleaning up");
        flowService.apply(remove.build(new FlowRuleOperationsContext() {

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                latch.countDown();
            }
        }));
        try {
            latch.await();
            while (!Iterables.isEmpty(flowService.getFlowEntriesById(appId))) {
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            printProgress("Interrupted.");
            Thread.currentThread().interrupt();
        }
    }
    if (outputJson()) {
        print("%s", json(new ObjectMapper(), true, results));
    } else {
        printTime(true, results);
    }
}
Also used : FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) Iterables(com.google.common.collect.Iterables) FlowEntryState(org.onosproject.net.flow.FlowEntry.FlowEntryState) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) Stopwatch(com.google.common.base.Stopwatch) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Command(org.apache.karaf.shell.api.action.Command) RandomUtils(org.apache.commons.lang.math.RandomUtils) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Lists(com.google.common.collect.Lists) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Device(org.onosproject.net.Device) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Argument(org.apache.karaf.shell.api.action.Argument) Streams(com.google.common.collect.Streams) TimeUnit(java.util.concurrent.TimeUnit) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) FlowRule(org.onosproject.net.flow.FlowRule) Service(org.apache.karaf.shell.api.action.lifecycle.Service) MacAddress(org.onlab.packet.MacAddress) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) Stopwatch(com.google.common.base.Stopwatch) CoreService(org.onosproject.core.CoreService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) CountDownLatch(java.util.concurrent.CountDownLatch) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 42 with ApplicationId

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

the class PortWaveLengthCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    if (operation.equals("edit-config") || operation.equals("delete-config")) {
        FlowRuleService flowService = get(FlowRuleService.class);
        DeviceService deviceService = get(DeviceService.class);
        CoreService coreService = get(CoreService.class);
        TrafficSelector.Builder trafficSelectorBuilder = DefaultTrafficSelector.builder();
        TrafficTreatment.Builder trafficTreatmentBuilder = DefaultTrafficTreatment.builder();
        FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
        ConnectPoint inCp, outCp = null;
        Device inDevice, outDevice = null;
        inCp = ConnectPoint.deviceConnectPoint(inConnectPointString);
        inDevice = deviceService.getDevice(inCp.deviceId());
        if (outConnectPointString != null) {
            outCp = ConnectPoint.deviceConnectPoint(outConnectPointString);
            outDevice = deviceService.getDevice(outCp.deviceId());
        }
        if (inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
            // Parsing the ochSignal
            OchSignal ochSignal;
            if (parameter.contains("/")) {
                ochSignal = createOchSignal();
            } else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
                ochSignal = createOchSignalFromWavelength(deviceService, inCp);
            } else {
                print("[ERROR] signal or wavelength %s are in uncorrect format");
                return;
            }
            if (ochSignal == null) {
                print("[ERROR] problem while creating OchSignal");
                return;
            }
            // Traffic selector
            TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).build();
            // Traffic treatment including ochSignal
            TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(inCp).number())).build();
            int priority = 100;
            ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
            // Flow rule using selector and treatment
            FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
            // Print output on CLI
            if (operation.equals("edit-config")) {
                flowService.applyFlowRules(addFlow);
                print("[INFO] Setting ochSignal on TERMINAL_DEVICE %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- port: %s", inCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
            } else {
                // This is delete-config
                flowService.removeFlowRules(addFlow);
                print("[INFO] Deleting ochSignal on TERMINAL_DEVICE %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- port: %s", inCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
            }
        }
        if (inDevice.type().equals(Device.Type.ROADM)) {
            if (outConnectPointString == null) {
                print("[ERROR] output port is required for ROADM devices");
                return;
            }
            if (!inDevice.equals(outDevice)) {
                print("[ERROR] input and output ports must be on the same device");
                return;
            }
            // Parsing the ochSignal
            OchSignal ochSignal;
            if (parameter.contains("/")) {
                ochSignal = createOchSignal();
            } else if (parameter.matches("-?\\d+(\\.\\d+)?")) {
                ochSignal = createOchSignalFromWavelength(deviceService, inCp);
            } else {
                print("[ERROR] signal or wavelength %s are in uncorrect format");
                return;
            }
            if (ochSignal == null) {
                print("[ERROR] problem while creating OchSignal");
                return;
            }
            // Traffic selector
            TrafficSelector trafficSelector = trafficSelectorBuilder.matchInPort(inCp.port()).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).build();
            // Traffic treatment
            TrafficTreatment trafficTreatment = trafficTreatmentBuilder.add(Instructions.modL0Lambda(ochSignal)).add(Instructions.createOutput(deviceService.getPort(outCp).number())).build();
            int priority = 100;
            ApplicationId appId = coreService.registerApplication("org.onosproject.optical-model");
            // Flow rule using selector and treatment
            FlowRule addFlow = flowRuleBuilder.withPriority(priority).fromApp(appId).withTreatment(trafficTreatment).withSelector(trafficSelector).forDevice(inDevice.id()).makePermanent().build();
            // Print output on CLI
            if (operation.equals("edit-config")) {
                flowService.applyFlowRules(addFlow);
                print("[INFO] Setting ochSignal on ROADM %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
                print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
            } else {
                // This is delete-config
                flowService.removeFlowRules(addFlow);
                print("[INFO] Deleting ochSignal on ROADM %s", ochSignal);
                print("--- device: %s", inDevice.id());
                print("--- input port %s, outpot port %s", inCp.port(), outCp.port());
                print("--- central frequency (GHz): %s", ochSignal.centralFrequency().asGHz());
                print("--- frequency slot width (GHz): %s", ochSignal.slotGranularity() * 12.5);
            }
        }
        if (!inDevice.type().equals(Device.Type.ROADM) && !inDevice.type().equals(Device.Type.TERMINAL_DEVICE)) {
            print("[ERROR] wrong device type: %s", inDevice.type());
        }
    } else {
        print("[ERROR] operation %s is not yet supported", operation);
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) OchSignal(org.onosproject.net.OchSignal) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId)

Example 43 with ApplicationId

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

the class SdnIpCommand method setEncap.

/**
 * Sets the encapsulation type for SDN-IP.
 *
 * @param encap the encapsulation type
 */
private void setEncap(String encap) {
    EncapsulationType encapType = EncapsulationType.enumFromString(encap);
    if (encapType.equals(EncapsulationType.NONE) && !encapType.toString().equals(encap)) {
        print(ENCAP_NOT_FOUND, encap);
        return;
    }
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(SdnIp.SDN_IP_APP);
    SdnIpConfig config = configService.addConfig(appId, SdnIpConfig.class);
    config.setEncap(encapType);
    config.apply();
// configService.applyConfig(appId, SdnIpConfig.class, config.node());
}
Also used : EncapsulationType(org.onosproject.net.EncapsulationType) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) SdnIpConfig(org.onosproject.sdnip.config.SdnIpConfig) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 44 with ApplicationId

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

the class DistributedKubevirtPodStore method activate.

@Activate
protected void activate() {
    ApplicationId appId = coreService.registerApplication(APP_ID);
    podStore = storageService.<String, Pod>consistentMapBuilder().withSerializer(Serializer.using(SERIALIZER_K8S_POD)).withName("kubevirt-pod-store").withApplicationId(appId).build();
    podStore.addListener(podMapListener);
    log.info("Started");
}
Also used : ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate)

Example 45 with ApplicationId

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

the class TelemetryVflowListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
    List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
    print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
    for (FlowEntry entry : flows) {
        TrafficSelector selector = entry.selector();
        IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
        IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
        TpPort srcPort = TpPort.tpPort(0);
        TpPort dstPort = TpPort.tpPort(0);
        String protocolStr = "ANY";
        Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
        if (ipProtocolCriterion != null) {
            short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
            if (protocol == PROTOCOL_TCP) {
                srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
                dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
                protocolStr = TCP;
            }
            if (protocol == PROTOCOL_UDP) {
                srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                protocolStr = UDP;
            }
        }
        print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
    }
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) CoreService(org.onosproject.core.CoreService) IpPrefix(org.onlab.packet.IpPrefix) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TpPort(org.onlab.packet.TpPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

ApplicationId (org.onosproject.core.ApplicationId)138 CoreService (org.onosproject.core.CoreService)36 Activate (org.osgi.service.component.annotations.Activate)36 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)25 Path (javax.ws.rs.Path)21 Produces (javax.ws.rs.Produces)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 GET (javax.ws.rs.GET)14 Test (org.junit.Test)13 ApplicationAdminService (org.onosproject.app.ApplicationAdminService)11 FlowRuleService (org.onosproject.net.flow.FlowRuleService)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Intent (org.onosproject.net.intent.Intent)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 InputStream (java.io.InputStream)9 DeviceId (org.onosproject.net.DeviceId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 IntentService (org.onosproject.net.intent.IntentService)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8