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;
}
}
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;
}
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;
}
}
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;
}
}
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);
}
}
Aggregations