use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class TapiDeviceHelper method getOchSignal.
/**
* If SIP info match our criteria, SIP component shall includes mc-pool information which must be obtained in order
* to complete the OchSignal info. with the TAPI SIP information included in spectrum-supported, spectrum-available
* and spectrum-occupied tapi objects.
*
* @param mcPool the MC_POOL json node
* @return the set of OCH signals given the port's information
*/
protected static Set<OchSignal> getOchSignal(JsonNode mcPool) {
Set<OchSignal> lambdas = new LinkedHashSet<>();
long availableUpperFrec = 0;
long availableLowerFrec = 0;
String availableAdjustmentGranularity = "";
String availableGridType = "";
JsonNode availableSpectrum = mcPool.get(AVAILABLE_SPECTRUM);
if (availableSpectrum == null) {
availableSpectrum = mcPool.get(SUPPORTABLE_SPECTRUM);
}
Iterator<JsonNode> iterAvailable = availableSpectrum.iterator();
while (iterAvailable.hasNext()) {
JsonNode availableSpec = iterAvailable.next();
availableUpperFrec = availableSpec.get(UPPER_FREQUENCY).asLong();
availableLowerFrec = availableSpec.get(LOWER_FREQUENCY).asLong();
log.debug("availableUpperFrec {}, availableLowerFrec {}", availableUpperFrec, availableLowerFrec);
availableAdjustmentGranularity = availableSpec.get(FREQUENCY_CONSTRAINT).get(ADJUSTMENT_GRANULARITY).textValue();
availableGridType = availableSpec.get(FREQUENCY_CONSTRAINT).get(GRID_TYPE).textValue();
log.debug("adjustment {}, availableLowerFrec {}", availableUpperFrec, availableLowerFrec);
int slotGranularity;
ChannelSpacing chSpacing = getChannelSpacing(availableAdjustmentGranularity);
double spacingFrequency = chSpacing.frequency().asMHz();
int lambdaCount = (int) ((availableUpperFrec - availableLowerFrec) / spacingFrequency);
GridType gridType = GridType.valueOf(availableGridType);
if (gridType == GridType.DWDM) {
slotGranularity = getSlotGranularity(chSpacing);
int finalSlotGranularity = slotGranularity;
long finalAvailableUpperFrec = availableUpperFrec;
long finalAvailableLowerFrec = availableLowerFrec;
IntStream.range(0, lambdaCount).forEach(x -> {
int spacingMultiplier = 0;
if (finalAvailableUpperFrec > BASE_FREQUENCY) {
spacingMultiplier = (int) (((finalAvailableUpperFrec - (chSpacing.frequency().asMHz() * lambdaCount * x) - slotGranularity / 2) - BASE_FREQUENCY) / (chSpacing.frequency().asMHz()));
} else {
spacingMultiplier = (int) ((BASE_FREQUENCY - (finalAvailableLowerFrec + (chSpacing.frequency().asMHz() * lambdaCount * x) + slotGranularity / 2)) / (chSpacing.frequency().asMHz()));
}
OchSignal ochSignal = new OchSignal(GridType.DWDM, chSpacing, spacingMultiplier, finalSlotGranularity);
log.debug("Spacing Freq {}, LambdaCount {}, FinalSlotGran {}, Spacing mult {}, CentralFreq {}", spacingFrequency, lambdaCount, finalSlotGranularity, spacingMultiplier, ochSignal.centralFrequency());
lambdas.add(ochSignal);
});
} else if (gridType == GridType.CWDM) {
log.warn("GridType CWDM. Not implemented");
} else if (gridType == GridType.FLEX) {
log.warn("GridType FLEX. Not implemented");
} else {
log.warn("Unknown GridType");
}
}
return lambdas;
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class OFOpticalSwitch13LambdaQuery method queryLambdas.
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
Port p = deviceService.getPort(this.data().deviceId(), port);
// Only OMS ports expose lambda resources
if (p == null || !p.type().equals(Port.Type.OMS)) {
return Collections.emptySet();
}
short lambdaCount = ((OmsPort) p).totalChannels();
// OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
return IntStream.rangeClosed(1, lambdaCount).mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x)).collect(GuavaCollectors.toImmutableSet());
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class TapiDeviceDescriptionDiscovery method parseTapiPorts.
protected List<PortDescription> parseTapiPorts(JsonNode tapiContext) {
List<PortDescription> ports = Lists.newArrayList();
/*
This annotations are used to store persistent mapping information between TAPI SIP's uuid
and ONOS device portNumbers. This is needed to be publicly available at least within ODTN app
when connectivity services will be sent to OLS Controller.
*/
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
Iterator<JsonNode> iter = tapiContext.get(CONTEXT).get(SERVICE_INTERFACE_POINT).iterator();
while (iter.hasNext()) {
JsonNode sipAttributes = iter.next();
if (checkValidEndpoint(sipAttributes)) {
String uuid = sipAttributes.get(UUID).textValue();
String[] uuidSeg = uuid.split("-");
PortNumber portNumber = PortNumber.portNumber(uuidSeg[uuidSeg.length - 1]);
annotations.set(UUID, uuid);
JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
// We get the first OCH signal as reported by the device.
OchSignal ochSignal = getOchSignal(mcPool).iterator().next();
// add och port
ports.add(ochPortDescription(portNumber, true, OduSignalType.ODU4, false, ochSignal, annotations.build()));
} else {
log.error("SIP {} is not valid", sipAttributes);
}
}
log.debug("PortList: {}", ports);
return ImmutableList.copyOf(ports);
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchLineConnectionFromDevice.
private List<FlowRule> fetchLineConnectionFromDevice(String channel, Frequency centralFreq) {
List<FlowRule> confirmedRules = new ArrayList<>();
FlowRule cacheAddRule;
FlowRule cacheDropRule;
NetconfSession session = getNetconfSession();
log.debug("fetchOpticalConnectionsFromDevice {} frequency {}", did(), centralFreq);
// Build the corresponding flow rule as expected
// Selector including port and ochSignal
// Treatment including port
PortNumber inputPortNumber = PortNumber.portNumber(channel);
PortNumber outputPortNumber = PortNumber.portNumber(channel);
log.debug("fetchOpticalConnectionsFromDevice {} port {}-{}", did(), inputPortNumber, outputPortNumber);
TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).add(Criteria.matchLambda(toOchSignal(centralFreq, 50.0))).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).build();
TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(outputPortNumber).build();
TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).build();
TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(toOchSignal(centralFreq, 50.0))).setOutput(outputPortNumber).build();
// Retrieved rules and cached rules are considered equal if both selector and treatment are equal
cacheAddRule = null;
cacheDropRule = null;
if (getConnectionCache().size(did()) != 0) {
cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
}
// Include the DROP rule to the retrieved rules if found in cache
if ((cacheDropRule != null)) {
confirmedRules.add(cacheDropRule);
log.debug("fetchOpticalConnectionsFromDevice {} DROP LINE rule included in the cache {}", did(), cacheDropRule);
} else {
log.warn("fetchOpticalConnectionsFromDevice {} DROP LINE rule not included in cache", did());
}
// Include the ADD rule to the retrieved rules if found in cache
if ((cacheAddRule != null)) {
confirmedRules.add(cacheAddRule);
log.debug("fetchOpticalConnectionsFromDevice {} ADD LINE rule included in the cache {}", did(), cacheAddRule.selector());
} else {
log.warn("fetchOpticalConnectionsFromDevice {} ADD LINE rule not included in cache", did());
}
// If neither Add or Drop rules are present in the cache, remove configuration from the device
if ((cacheDropRule == null) && (cacheAddRule == null)) {
log.warn("fetchOpticalConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
try {
// TODO this is not required if allowExternalFlowRules
TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
removeFlowRule(session, addRule);
TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
removeFlowRule(session, dropRule);
} catch (NetconfException e) {
openConfigError("Error removing LINE rule from device", e);
}
}
return confirmedRules;
}
use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method parsePortComponent.
/**
* Parses a component XML doc into a PortDescription.
*
* @param component subtree to parse. It must be a component ot type PORT.
* @param components the full components tree, to cross-ref in
* case we need to check transceivers or optical channels.
*
* @return PortDescription or null if component does not have onos-index
*/
private PortDescription parsePortComponent(HierarchicalConfiguration component, HierarchicalConfiguration components) {
Map<String, String> annotations = new HashMap<>();
String name = component.getString("name");
String type = component.getString("state/type");
log.info("Parsing Component {} type {}", name, type);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
// Store all properties as port properties
component.configurationsAt("properties/property").forEach(property -> {
String pn = property.getString("name");
String pv = property.getString("state/value");
annotations.put(pn, pv);
});
// Assing an ONOS port number
PortNumber portNum;
if (annotations.containsKey(ONOS_PORT_INDEX)) {
portNum = PortNumber.portNumber(Long.parseLong(annotations.get(ONOS_PORT_INDEX)));
} else {
log.warn("PORT {} does not include onos-index, hashing...", name);
portNum = PortNumber.portNumber(name.hashCode());
}
log.debug("PORT {} number {}", name, portNum);
// The heuristic to know if it is client or line side
if (!annotations.containsKey(PORT_TYPE)) {
if (hasTransceiverSubComponent(component, components)) {
annotations.put(PORT_TYPE, OdtnPortType.CLIENT.value());
} else if (hasOpticalChannelSubComponent(component, components)) {
annotations.put(PORT_TYPE, OdtnPortType.LINE.value());
}
}
// to be an issue with resource mapping
if (annotations.get(PORT_TYPE).equals(OdtnPortType.CLIENT.value())) {
log.debug("Adding CLIENT port");
Builder builder = DefaultPortDescription.builder();
builder.type(Type.PACKET);
builder.withPortNumber(portNum);
builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
}
if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
log.debug("Adding LINE port");
// TODO: To be configured
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(portNum, true, // TODO Client signal to be discovered
OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
}
log.error("Unknown port type");
return null;
}
Aggregations