Search in sources :

Example 51 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class OpticalPortsListCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService service = opticalView(get(DeviceService.class));
    if (uri == null) {
        if (outputJson()) {
            print("%s", jsonPorts(service, getSortedDevices(service)));
        } else {
            for (Device device : getSortedDevices(service)) {
                printDevice(service, device);
                printPorts(service, device);
            }
        }
    } else {
        Device device = service.getDevice(deviceId(uri));
        if (device == null) {
            error("No such device %s", uri);
        } else if (outputJson()) {
            print("%s", jsonPorts(service, new ObjectMapper(), device));
        } else {
            printDevice(service, device);
            printPorts(service, device);
        }
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class PortAvailableWaveLengthCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    DeviceService deviceService = get(DeviceService.class);
    ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPointString);
    Device d = deviceService.getDevice(cp.deviceId());
    if (d.is(LambdaQuery.class)) {
        LambdaQuery lambdaQuery = d.as(LambdaQuery.class);
        lambdaQuery.queryLambdas(cp.port()).forEach(lambda -> {
            print(FMT, lambda.toString(), lambda.centralFrequency().asGHz());
        });
    } else {
        print("Device is not capable of querying lambdas");
    }
}
Also used : LambdaQuery(org.onosproject.net.behaviour.LambdaQuery) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 53 with DeviceService

use of org.onosproject.net.device.DeviceService 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 54 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class DefaultOpticalDevice method delegate.

@Override
public Device delegate() {
    if (delegate == null) {
        // dirty work around.
        // wanted to pass delegate Device at construction,
        // but was not possible. A Behaviour requires no-arg constructor.
        checkState(data() != null, "DriverData must exist");
        DriverData data = data();
        DeviceService service = DefaultServiceDirectory.getService(DeviceService.class);
        delegate = checkNotNull(service.getDevice(data.deviceId()), "No Device found for %s", data.deviceId());
    }
    return delegate;
}
Also used : DriverData(org.onosproject.net.driver.DriverData) DeviceService(org.onosproject.net.device.DeviceService)

Example 55 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class LinkDiscoveryAristaImpl method findRemoteDeviceByChassisId.

private Optional<Device> findRemoteDeviceByChassisId(DeviceService deviceService, String remoteChassisIdString) {
    String forMacTmp = remoteChassisIdString.replace(".", "").replaceAll("(.{2})", "$1:").trim().substring(0, 17);
    MacAddress mac = MacAddress.valueOf(forMacTmp);
    Supplier<Stream<Device>> deviceStream = () -> StreamSupport.stream(deviceService.getAvailableDevices().spliterator(), false);
    Optional<Device> remoteDeviceOptional = deviceStream.get().filter(device -> device.chassisId() != null && MacAddress.valueOf(device.chassisId().value()).equals(mac)).findAny();
    if (remoteDeviceOptional.isPresent()) {
        log.debug("remoteDevice found by chassis id: {}", forMacTmp);
        return remoteDeviceOptional;
    } else {
        remoteDeviceOptional = deviceStream.get().filter(device -> Tools.stream(deviceService.getPorts(device.id())).anyMatch(port -> port.annotations().keys().contains(AnnotationKeys.PORT_MAC) && MacAddress.valueOf(port.annotations().value(AnnotationKeys.PORT_MAC)).equals(mac))).findAny();
        if (remoteDeviceOptional.isPresent()) {
            log.debug("remoteDevice found by port mac: {}", forMacTmp);
            return remoteDeviceOptional;
        } else {
            return Optional.empty();
        }
    }
}
Also used : Tools(org.onlab.util.Tools) Supplier(com.google.common.base.Supplier) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Port(org.onosproject.net.Port) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Sets(com.google.common.collect.Sets) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) Objects(java.util.Objects) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Stream(java.util.stream.Stream) MacAddress(org.onlab.packet.MacAddress)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14