Search in sources :

Example 1 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class GnpyManager method obtainConnectivity.

@Override
public Pair<IntentId, Double> obtainConnectivity(ConnectPoint ingress, ConnectPoint egress, boolean bidirectional) {
    ByteArrayOutputStream connectivityRequest = createGnpyRequest(ingress, egress, bidirectional);
    String response = gnpyHttpUtil.post(null, "/gnpy-experimental", new ByteArrayInputStream(connectivityRequest.toByteArray()), MediaType.APPLICATION_JSON_TYPE, String.class);
    ObjectMapper om = new ObjectMapper();
    final ObjectReader reader = om.reader();
    JsonNode jsonNode;
    try {
        jsonNode = reader.readTree(response);
        if (jsonNode == null) {
            log.error("JsonNode is null for response {}", response);
            return null;
        }
        log.info("Response {}", response);
        String bestPath;
        try {
            bestPath = getBestOsnrPathKey(jsonNode);
        } catch (IllegalStateException e) {
            log.error("Exception while contacting GNPy", e);
            return null;
        }
        OchSignal ochSignal = createOchSignal(jsonNode);
        Map<DeviceId, Double> deviceAtoBPowerMap = new HashMap<>();
        Map<DeviceId, Double> deviceBtoAPowerMap = new HashMap<>();
        // TODO this list is currently only populated in the forward direction
        List<DeviceId> deviceIds = getDeviceAndPopulatePowerMap(jsonNode, deviceAtoBPowerMap, deviceBtoAPowerMap, bestPath);
        Path suggestedPath = createSuggestedPath(deviceIds);
        log.info("Suggested path {}", suggestedPath);
        Intent intent = createOpticalIntent(ingress, egress, deviceService, null, appId, bidirectional, ochSignal, suggestedPath);
        intentsPowerMap.put(intent.id(), new GnpyPowerInfo(deviceAtoBPowerMap, deviceBtoAPowerMap, getLaunchPower(jsonNode), suggestedPath.links(), ingress, egress, ochSignal));
        intentService.submit(intent);
        return Pair.of(intent.id(), getOsnr(jsonNode, bestPath));
    } catch (IOException e) {
        log.error("Exception while reading response {}", response, e);
        return null;
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpticalIntentUtility.createOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent) Intent(org.onosproject.net.intent.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class GnpyManager method createOchSignal.

protected OchSignal createOchSignal(JsonNode connectivityReply) throws IllegalArgumentException {
    if (connectivityReply.has("result") && connectivityReply.get("result").has("response")) {
        Iterator<JsonNode> elements = connectivityReply.get("result").get("response").elements().next().get("path-properties").get("path-route-objects").elements();
        Iterable<JsonNode> iterable = () -> elements;
        List<JsonNode> elementsList = StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
        int n = 0;
        int m = 0;
        for (JsonNode node : elementsList) {
            if (node.get("path-route-object").has("label-hop")) {
                n = node.get("path-route-object").get("label-hop").get("N").asInt();
                m = node.get("path-route-object").get("label-hop").get("M").asInt();
                break;
            }
        }
        int offset = 193100;
        double centralFreq = offset + (n * CHL_6P25GHZ.frequency().asGHz());
        try {
            int multiplier = getMultplier(centralFreq, GridType.DWDM, CHL_50GHZ);
            return new OchSignal(GridType.DWDM, CHL_50GHZ, multiplier, 4);
        } catch (RuntimeException e) {
            /* catching RuntimeException as both NullPointerException (thrown by
                 * checkNotNull) and IllegalArgumentException (thrown by checkArgument)
                 * are subclasses of RuntimeException.
                 */
            throw new IllegalArgumentException(e);
        }
    }
    return null;
}
Also used : OchSignal(org.onosproject.net.OchSignal) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class RoadmUtil method createOchSignalFromWavelength.

public static OchSignal createOchSignalFromWavelength(double wavelength, DeviceService deviceService, DeviceId deviceId, PortNumber portNumber) {
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(deviceId, portNumber);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultiplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        return null;
    }
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OchSignal(org.onosproject.net.OchSignal) OchPort(org.onosproject.net.optical.OchPort) GridType(org.onosproject.net.GridType)

Example 4 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class PortWaveLengthCommand method createOchSignalFromWavelength.

private OchSignal createOchSignalFromWavelength(DeviceService deviceService, ConnectPoint cp) {
    long wavelength = Long.parseLong(parameter);
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(cp);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        print("[ERROR] connect point %s is not OChPort", cp);
        return null;
    }
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OchSignal(org.onosproject.net.OchSignal) OchPort(org.onosproject.net.optical.OchPort) ConnectPoint(org.onosproject.net.ConnectPoint) GridType(org.onosproject.net.GridType)

Example 5 with OchSignal

use of org.onosproject.net.OchSignal 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)

Aggregations

OchSignal (org.onosproject.net.OchSignal)63 PortNumber (org.onosproject.net.PortNumber)17 ChannelSpacing (org.onosproject.net.ChannelSpacing)16 GridType (org.onosproject.net.GridType)14 DeviceId (org.onosproject.net.DeviceId)12 ConnectPoint (org.onosproject.net.ConnectPoint)11 DeviceService (org.onosproject.net.device.DeviceService)10 HashMap (java.util.HashMap)9 Set (java.util.Set)9 IntStream (java.util.stream.IntStream)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Logger (org.slf4j.Logger)8 ArrayList (java.util.ArrayList)7 Port (org.onosproject.net.Port)7 Collectors (java.util.stream.Collectors)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)6 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)6 Collections (java.util.Collections)5 List (java.util.List)5 Frequency (org.onlab.util.Frequency)5