Search in sources :

Example 6 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 7 with Frequency

use of org.onlab.util.Frequency in project onos by opennetworkinglab.

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for Polatis Snmp device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    List<PortDescription> ports = Lists.newArrayList();
    List<TableEvent> events;
    DeviceId deviceId = handler().data().deviceId();
    try {
        OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
        events = getTable(handler(), columnOIDs);
    } catch (IOException e) {
        log.error("Error reading ports table for device {} exception {}", deviceId, e);
        return ports;
    }
    if (events == null) {
        log.error("Error reading ports table for device {}", deviceId);
        return ports;
    }
    for (TableEvent event : events) {
        if (event == null) {
            log.error("Error reading event for device {}", deviceId);
            continue;
        }
        VariableBinding[] columns = event.getColumns();
        if (columns == null) {
            log.error("Error reading columns for device {} event {}", deviceId, event);
            continue;
        }
        VariableBinding portColumn = columns[0];
        if (portColumn == null) {
            continue;
        }
        int port = event.getIndex().last();
        boolean enabled = (portColumn.getVariable().toInt() == 1);
        PortNumber portNumber = PortNumber.portNumber(port);
        DefaultAnnotations annotations = DefaultAnnotations.builder().build();
        double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
        Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
        PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
        ports.add(p);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) TableEvent(org.snmp4j.util.TableEvent) Frequency(org.onlab.util.Frequency) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 8 with Frequency

use of org.onlab.util.Frequency in project onos by opennetworkinglab.

the class LumentumNetconfRoadmFlowRuleProgrammable method rpcAddConnection.

// Following Lumentum documentation rpc operation to configure a new connection
private boolean rpcAddConnection(LumentumFlowRule xc) {
    Pair<Short, Short> pair = setModuleIdConnection(xc);
    String module = pair.getLeft().toString();
    String connectionId = pair.getRight().toString();
    log.debug("Lumentum driver new connection sent moduleId {} connId {}", xc.getConnectionModule(), xc.getConnectionId());
    // Conversion of ochSignal format (center frequency + diameter) to Lumentum frequency slot format (start - end)
    Frequency freqRadius = Frequency.ofHz(xc.ochSignal().channelSpacing().frequency().asHz() / 2);
    Frequency center = xc.ochSignal().centralFrequency();
    String startFreq = String.valueOf(center.subtract(freqRadius).asHz() / GHZ);
    String endFreq = String.valueOf(center.add(freqRadius).asHz() / GHZ);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "\n");
    stringBuilder.append("<add-connection xmlns=\"http://www.lumentum.com/lumentum-ote-connection\">" + "\n");
    stringBuilder.append("<dn>ne=1;chassis=1;card=1;module=" + module + ";connection=" + connectionId + "</dn>" + "\n");
    stringBuilder.append("<start-freq>" + startFreq + "</start-freq>" + "\n");
    stringBuilder.append("<end-freq>" + endFreq + "</end-freq>" + "\n");
    stringBuilder.append("<attenuation>" + "0.0" + "</attenuation>" + "\n");
    stringBuilder.append("<blocked>" + "false" + "</blocked>" + "\n");
    stringBuilder.append("<maintenance-state>" + "in-service" + "</maintenance-state>" + "\n");
    if (xc.isAddRule()) {
        stringBuilder.append("<input-port-reference>" + DN_CARD1 + xc.addDrop().toString() + "</input-port-reference>" + "\n");
        stringBuilder.append("<output-port-reference>" + DN_CARD1 + MUX_OUT + "</output-port-reference>" + "\n");
    } else {
        stringBuilder.append("<input-port-reference>" + DN_CARD1 + DEMUX_IN + "</input-port-reference>" + "\n");
        stringBuilder.append("<output-port-reference>" + DN_CARD1 + xc.addDrop().toString() + "</output-port-reference>" + "\n");
    }
    stringBuilder.append("<custom-name>" + "onos-connection" + "</custom-name>" + "\n");
    stringBuilder.append("</add-connection>" + "\n");
    stringBuilder.append("</rpc>" + "\n");
    log.info("Lumentum ROADM20 - RPC add-connection sent to device {}", did());
    log.debug("Lumentum ROADM20 - RPC add-connection sent to device {} {}", did(), stringBuilder);
    return editCrossConnect(stringBuilder.toString());
}
Also used : Frequency(org.onlab.util.Frequency)

Example 9 with Frequency

use of org.onlab.util.Frequency in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceFlowRuleProgrammable method applyFlowRule.

/**
 * Apply a single flowrule to the device.
 *
 * --- Directionality details:
 * Driver supports ADD (INGRESS) and DROP (EGRESS) rules generated by OpticalCircuit/OpticalConnectivity intents
 * the format of the rules are checked in class TerminalDeviceFlowRule
 *
 * However, the physical transponder is always bidirectional as specified in OpenConfig YANG models
 * therefore ADD and DROP rules are mapped in the same xml that ENABLE (and tune) a transponder port.
 *
 * If the intent is generated as bidirectional both ADD and DROP flowrules are generated for each device, thus
 * the same xml is sent twice to the device.
 *
 * @param session   The Netconf session.
 * @param rule      Flow Rules to be applied.
 * @return true if no Netconf errors are received from the device when xml is sent
 * @throws NetconfException if exchange goes wrong
 */
protected boolean applyFlowRule(NetconfSession session, TerminalDeviceFlowRule rule) {
    // --- enable the line port
    if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS || rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
        FlowRuleParser frp = new FlowRuleParser(rule);
        String componentName = frp.getPortNumber().toString();
        Frequency centralFrequency = frp.getCentralFrequency();
        StringBuilder componentConf = new StringBuilder();
        log.info("Sending LINE FlowRule to device {} LINE port {}, frequency {}", did(), componentName, centralFrequency);
        try {
            setOpticalChannelFrequency(session, componentName, centralFrequency);
        } catch (NetconfException e) {
            log.error("Error writing central frequency in the component");
            return false;
        }
        try {
            setLogicalChannel(session, OPERATION_ENABLE, componentName);
        } catch (NetconfException e) {
            log.error("Error enabling the logical channel");
            return false;
        }
    }
    // TODO check the OTN mapping of client ports into the line port frame specified by parameter "<allocation>"
    if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS || rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
        String clientPortName;
        String linePortName;
        if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
            clientPortName = rule.inPort().toString();
            linePortName = rule.outPort().toString();
        } else {
            clientPortName = rule.outPort().toString();
            linePortName = rule.inPort().toString();
        }
        log.info("Sending CLIENT FlowRule to device {} CLIENT port: {}, LINE port {}", did(), clientPortName, linePortName);
        try {
            setLogicalChannelAssignment(session, OPERATION_ENABLE, clientPortName, linePortName, DEFAULT_ASSIGNMENT_INDEX, DEFAULT_ALLOCATION_INDEX);
        } catch (NetconfException e) {
            log.error("Error setting the logical channel assignment");
            return false;
        }
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Frequency(org.onlab.util.Frequency) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser)

Example 10 with Frequency

use of org.onlab.util.Frequency in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchConnectionsFromDevice.

/**
 * Fetches list of connections from device.
 *
 * TODO manage allow external flow rules (allowExternalFlowRules)
 * Currently removes from the device all connections that are not currently present in the DeviceConnectionCache.
 *
 * @return connections that are present on the device and in the DeviceConnectionCache.
 */
private List<FlowRule> fetchConnectionsFromDevice() {
    List<FlowRule> confirmedRules = new ArrayList<>();
    String reply;
    FlowRule cacheAddRule;
    FlowRule cacheDropRule;
    NetconfSession session = getNetconfSession();
    // Get relevant information from the device
    StringBuilder requestFilter = new StringBuilder();
    requestFilter.append("<components xmlns='http://openconfig.net/yang/platform'>");
    requestFilter.append("  <component>");
    requestFilter.append("    <name/>");
    requestFilter.append("    <oc-opt-term:optical-channel " + "xmlns:oc-opt-term='http://openconfig.net/yang/terminal-device'>");
    requestFilter.append("      <oc-opt-term:config/>");
    requestFilter.append("    </oc-opt-term:optical-channel>");
    requestFilter.append("  </component>");
    requestFilter.append("</components>");
    requestFilter.append("<terminal-device xmlns='http://openconfig.net/yang/terminal-device'>");
    requestFilter.append("  <logical-channels>");
    requestFilter.append("    <channel>");
    requestFilter.append("      <index/>");
    requestFilter.append("      <config>");
    requestFilter.append("        <admin-state/>");
    requestFilter.append("        <logical-channel-type/>");
    requestFilter.append("      </config>");
    requestFilter.append("      <logical-channel-assignments>");
    requestFilter.append("        <assignment>");
    requestFilter.append("          <config>");
    requestFilter.append("            <logical-channel/>");
    requestFilter.append("          </config>");
    requestFilter.append("        </assignment>");
    requestFilter.append("      </logical-channel-assignments>");
    requestFilter.append("    </channel>");
    requestFilter.append("  </logical-channels>");
    requestFilter.append("</terminal-device>");
    try {
        reply = session.get(requestFilter.toString(), null);
    // log.debug("TRANSPONDER CONNECTIONS - fetchConnectionsFromDevice {} reply {}", did(), reply);
    } catch (NetconfException e) {
        log.error("Failed to retrieve configuration details for device {}", handler().data().deviceId(), e);
        return ImmutableList.of();
    }
    HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
    List<HierarchicalConfiguration> logicalChannels = cfg.configurationsAt("data.terminal-device.logical-channels.channel");
    List<HierarchicalConfiguration> components = cfg.configurationsAt("data.components.component");
    // Retrieve the ENABLED line ports
    List<String> enabledOpticalChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_OTN)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
    log.debug("fetchConnectionsFromDevice {} enabledOpticalChannelsIndex {}", did(), enabledOpticalChannels);
    if (enabledOpticalChannels.size() != 0) {
        for (String channel : enabledOpticalChannels) {
            log.debug("fetchOpticalConnectionsFromDevice {} channel {}", did(), channel);
            // Retrieve the corresponding central frequency from the associated component
            // TODO correlate the components instead of relying on naming
            Frequency centralFreq = components.stream().filter(c -> c.getString("name").equals(PREFIX_CHANNEL + channel)).map(c -> c.getDouble("optical-channel.config.frequency")).map(c -> Frequency.ofMHz(c)).findFirst().orElse(null);
            confirmedRules.addAll(fetchLineConnectionFromDevice(channel, centralFreq));
        }
    }
    // Retrieve the ENABLED client ports
    List<String> enabledClientChannels = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).map(r -> r.getString("index")).collect(Collectors.toList());
    log.debug("fetchClientConnectionsFromDevice {} enabledClientChannelsIndex {}", did(), enabledClientChannels);
    if (enabledClientChannels.size() != 0) {
        for (String clientPort : enabledClientChannels) {
            log.debug("fetchClientConnectionsFromDevice {} channel {}", did(), clientPort);
            String linePort = logicalChannels.stream().filter(r -> r.getString("config.logical-channel-type").equals(OC_TYPE_PROT_ETH)).filter(r -> r.getString("config.admin-state").equals(OPERATION_ENABLE)).filter(r -> r.getString("index").equals(clientPort)).map(r -> r.getString("logical-channel-assignments.assignment.config.logical-channel")).findFirst().orElse(null);
            // Build the corresponding flow rule as expected
            // Selector including port
            // Treatment including port
            PortNumber clientPortNumber = PortNumber.portNumber(clientPort);
            PortNumber linePortNumber = PortNumber.portNumber(linePort);
            confirmedRules.addAll(fetchClientConnectionFromDevice(clientPortNumber, linePortNumber));
        }
    }
    // Returns rules that are both on the device and on the cache
    if (confirmedRules.size() != 0) {
        log.info("fetchConnectionsFromDevice {} number of confirmed rules {}", did(), confirmedRules.size());
        return confirmedRules;
    } else {
        return ImmutableList.of();
    }
}
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) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) Frequency(org.onlab.util.Frequency) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber)

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