Search in sources :

Example 1 with Frequency

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);
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) Frequency(org.onlab.util.Frequency) GridType(org.onosproject.net.GridType)

Example 2 with Frequency

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;
}
Also used : HashMap(java.util.HashMap) Frequency(org.onlab.util.Frequency)

Example 3 with Frequency

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));
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) OmsPort(org.onosproject.net.optical.OmsPort) DefaultPort(org.onosproject.net.DefaultPort) OmsPort(org.onosproject.net.optical.OmsPort) Port(org.onosproject.net.Port) Frequency(org.onlab.util.Frequency) PortDescription(org.onosproject.net.device.PortDescription) PortNumber(org.onosproject.net.PortNumber) DefaultPort(org.onosproject.net.DefaultPort) Test(org.junit.Test)

Example 4 with Frequency

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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) XPath(javax.xml.xpath.XPath) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) Spectrum(org.onlab.util.Spectrum) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController) Document(org.w3c.dom.Document) NamespaceContext(javax.xml.namespace.NamespaceContext) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) InputSource(org.xml.sax.InputSource) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) DatastoreId(org.onosproject.netconf.DatastoreId) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) StringReader(java.io.StringReader) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ChannelSpacing(org.onosproject.net.ChannelSpacing) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DeviceId(org.onosproject.net.DeviceId) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with Frequency

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;
}
Also used : Frequency(org.onlab.util.Frequency) OchSignal(org.onosproject.net.OchSignal)

Aggregations

Frequency (org.onlab.util.Frequency)17 PortNumber (org.onosproject.net.PortNumber)6 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)5 DeviceId (org.onosproject.net.DeviceId)4 OchSignal (org.onosproject.net.OchSignal)4 Port (org.onosproject.net.Port)4 DeviceService (org.onosproject.net.device.DeviceService)4 Test (org.junit.Test)3 FlowRuleParser (org.onosproject.drivers.odtn.impl.FlowRuleParser)3 Annotations (org.onosproject.net.Annotations)3 ChannelSpacing (org.onosproject.net.ChannelSpacing)3 DefaultPort (org.onosproject.net.DefaultPort)3 GridType (org.onosproject.net.GridType)3 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 OmsPort (org.onosproject.net.optical.OmsPort)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2