use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class RoadmCrossConnectCommand method createOchSignal.
/**
* This method forms parameters and creates and OchSignal instance from
* central frequency and the slot width of the channel.
* @param frequency - central frequency of the connection.
* @param sw - slot width of the optical channel.
* @param grid - frequency grid type.
* @param spacing - channel spacing.
* @return - returns created instance of OchSignal.
*/
protected OchSignal createOchSignal(String frequency, String sw, String grid, String spacing) {
Frequency centralFreq = Frequency.ofGHz(Double.parseDouble(frequency));
Frequency slotWidth = Frequency.ofGHz(Double.parseDouble(sw));
GridType gridType = null;
try {
gridType = GridType.valueOf(grid.toUpperCase());
} catch (Exception e) {
gridType = GridType.DWDM;
}
ChannelSpacing channelSpacing = null;
// It requires passing channelSpacing in the following format CHL_6P25GHZ or similar
try {
channelSpacing = ChannelSpacing.valueOf(spacing);
} catch (Exception e) {
channelSpacing = ChannelSpacing.CHL_50GHZ;
}
return OpticalChannelUtility.createOchSignal(centralFreq, slotWidth, gridType, channelSpacing);
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class OpticalChannelUtility method extractOchFreqBounds.
/**
* This method extracts frequency bounds from OchSignal instance.
* @param signal - OchSignal instance.
* @param channelSpacing - channel spacing.
* @return - HashMap with upper and lower bounds of frequency.
*/
public static final Map<String, Frequency> extractOchFreqBounds(OchSignal signal, ChannelSpacing channelSpacing) {
// Initializing variables
int spacingMultiplier = signal.spacingMultiplier();
int slotGranularity = signal.slotGranularity();
// Computing central frequency
Frequency central = computeCentralFrequency(spacingMultiplier, channelSpacing);
// Computing HALF of slot width
Frequency halfSlotWidth = computeSlotWidth(slotGranularity).floorDivision(2);
// Getting frequency bounds
Frequency minFreq = central.subtract(halfSlotWidth);
Frequency maxFreq = central.add(halfSlotWidth);
Map<String, Frequency> freqs = new HashMap<String, Frequency>();
freqs.put("minFreq", minFreq);
freqs.put("maxFreq", maxFreq);
return freqs;
}
use of org.onlab.util.Frequency in project onos by opennetworkinglab.
the class OmsPortHelperTest method testOmsPortDescriptionCanBeConvertedToOmsPort.
@Test
public void testOmsPortDescriptionCanBeConvertedToOmsPort() {
PortNumber pn = PortNumber.portNumber(4900);
boolean isEnabled = true;
String anKey = "Base";
String anValue = "value";
SparseAnnotations an = DefaultAnnotations.builder().set(anKey, anValue).build();
Frequency minF = Frequency.ofGHz(3);
Frequency maxF = Frequency.ofGHz(33);
Frequency grid = Frequency.ofGHz(2);
PortDescription portDescription = OmsPortHelper.omsPortDescription(pn, isEnabled, minF, maxF, grid, an);
Port port = new DefaultPort(DEV, portDescription.portNumber(), portDescription.isEnabled(), portDescription.type(), portDescription.portSpeed(), portDescription.annotations());
Optional<OmsPort> maybeOms = OmsPortHelper.asOmsPort(port);
assertTrue(maybeOms.isPresent());
OmsPort oms = maybeOms.get();
assertThat(oms.isEnabled(), is(isEnabled));
assertThat(oms.number(), is(pn));
assertThat(oms.annotations().value(anKey), is(anValue));
assertThat("type is always OMS", oms.type(), is(Port.Type.OMS));
assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L)));
assertThat(oms.maxFrequency(), is(maxF));
assertThat(oms.minFrequency(), is(minF));
assertThat(oms.grid(), is(grid));
assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
}
use of org.onlab.util.Frequency 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.onlab.util.Frequency in project onos by opennetworkinglab.
the class OpenRoadmFlowRuleProgrammable method toOchSignalCenterWidth.
/**
* Helper method to create an OchSignal for a frequency slot.
*
* @param center the center frequency as per the ITU-grid.
* @param width slot width
* @return OCh signal
*/
public static OchSignal toOchSignalCenterWidth(Frequency center, Frequency width) {
Frequency radius = width.floorDivision(2);
// Frequency slot start and end frequency.
double start = center.subtract(radius).asGHz();
double end = center.add(radius).asGHz();
int slots = (int) ((end - start) / ChannelSpacing.CHL_12P5GHZ.frequency().asGHz());
int multiplier = 0;
// Conversion for 50 GHz slots
if (end - start == 50) {
multiplier = (int) (((end - start) / 2 + start - Spectrum.CENTER_FREQUENCY.asGHz()) / ChannelSpacing.CHL_50GHZ.frequency().asGHz());
return new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, multiplier, slots);
}
// Conversion for 100 GHz slots
if (end - start == 100) {
multiplier = (int) (((end - start) / 2 + start - Spectrum.CENTER_FREQUENCY.asGHz()) / ChannelSpacing.CHL_100GHZ.frequency().asGHz());
return new OchSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, multiplier, slots);
}
return null;
}
Aggregations