Search in sources :

Example 36 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class DefaultTrafficSelectorTest method testEquals.

/**
 * Tests equals(), hashCode() and toString() methods.
 */
@Test
public void testEquals() {
    final TrafficSelector selector1 = DefaultTrafficSelector.builder().add(Criteria.matchLambda(new OchSignal(GridType.FLEX, ChannelSpacing.CHL_100GHZ, 1, 1))).build();
    final TrafficSelector sameAsSelector1 = DefaultTrafficSelector.builder().add(Criteria.matchLambda(new OchSignal(GridType.FLEX, ChannelSpacing.CHL_100GHZ, 1, 1))).build();
    final TrafficSelector selector2 = DefaultTrafficSelector.builder().add(Criteria.matchLambda(new OchSignal(GridType.FLEX, ChannelSpacing.CHL_50GHZ, 1, 1))).build();
    new EqualsTester().addEqualityGroup(selector1, sameAsSelector1).addEqualityGroup(selector2).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) OchSignal(org.onosproject.net.OchSignal) Test(org.junit.Test)

Example 37 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class ClientLineTerminalDeviceDiscovery 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("PORT {} number {} added as CLIENT port", name, portNum);
        return OduCltPortHelper.oduCltPortDescription(portNum, true, CltSignalType.CLT_10GBE, DefaultAnnotations.builder().putAll(annotations).build());
    }
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
        log.debug("PORT {} number {} added as LINE port", name, portNum);
        // 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("PORT {} number {} is of UNKNOWN type", name, portNum);
    return null;
}
Also used : HashMap(java.util.HashMap) OchSignal(org.onosproject.net.OchSignal) PortNumber(org.onosproject.net.PortNumber)

Example 38 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class GnmiTerminalDeviceDiscovery method convertComponentToOdtnPortDesc.

/**
 * Converts gNMI updates to ODTN port description.
 *
 * Paths we expected per optical port component:
 * /components/component/state/type
 * /components/component/optical-channel/config/line-port
 *
 * @param name component name
 * @param updates gNMI updates
 * @return port description, null if it is not a valid component config/state
 */
private PortDescription convertComponentToOdtnPortDesc(String name, Collection<Gnmi.Update> updates) {
    Map<String, Gnmi.TypedValue> pathValue = Maps.newHashMap();
    updates.forEach(u -> pathValue.put(pathToString(u.getPath()), u.getVal()));
    String componentTypePathStr = String.format(COMPONENT_TYPE_PATH_TEMPLATE, name);
    Gnmi.TypedValue componentType = pathValue.get(componentTypePathStr);
    if (componentType == null || !componentType.getStringVal().equals("OPTICAL_CHANNEL")) {
        // Ignore the component which is not a optical channel type.
        return null;
    }
    Map<String, String> annotations = Maps.newHashMap();
    annotations.put(OC_NAME, name);
    annotations.put(OC_TYPE, componentType.getStringVal());
    String linePortPathStr = String.format(LINE_PORT_PATH_TEMPLATE, name);
    Gnmi.TypedValue linePort = pathValue.get(linePortPathStr);
    // Invalid optical port
    if (linePort == null) {
        return null;
    }
    // According to CassiniTerminalDevice class, we expected to received a string with
    // this format: port-[port id].
    // And we use "port id" from the string as the port number.
    // However, if we can't get port id from line port value, we will use
    // hash number of the port name. (According to TerminalDeviceDiscovery class)
    String linePortString = linePort.getStringVal();
    long portId = name.hashCode();
    if (linePortString.contains("-") && !linePortString.endsWith("-")) {
        try {
            portId = Long.parseUnsignedLong(linePortString.split("-")[1]);
        } catch (NumberFormatException e) {
            log.warn("Invalid line port string: {}, use {}", linePortString, portId);
        }
    }
    annotations.put(AnnotationKeys.PORT_NAME, linePortString);
    annotations.putIfAbsent(PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value());
    annotations.putIfAbsent(ONOS_PORT_INDEX, Long.toString(portId));
    annotations.putIfAbsent(CONNECTION_ID, "connection-" + portId);
    OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
    return OchPortHelper.ochPortDescription(PortNumber.portNumber(portId, name), true, // TODO: discover type via gNMI if possible
    OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
}
Also used : Gnmi(gnmi.Gnmi) OchSignal(org.onosproject.net.OchSignal) GnmiUtils.pathToString(org.onosproject.gnmi.api.GnmiUtils.pathToString)

Example 39 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class OpenRoadmFlowRuleProgrammable method buildFlowrule.

/**
 * Builds a flow rule from a connection object (as XML object).
 *
 * @param connection the connection hierarchy
 * @return the flow rule
 */
private FlowRule buildFlowrule(HierarchicalConfiguration connection) {
    String name = connection.getString("connection-name");
    if (name == null) {
        log.error("OPENROADM {}: connection name not correctly retrieved", did());
        return null;
    }
    // If the flow entry is not in the cache: return null
    FlowRule flowRule = getConnectionCache().get(did(), name);
    if (flowRule == null) {
        log.error("OPENROADM {}: name {} not in cache. delete editConfig", did(), name);
        editConfigDeleteConnection(name);
        return null;
    } else {
        openRoadmLog("connection retrieved {}", name);
    }
    OpenRoadmFlowRule xc = new OpenRoadmFlowRule(flowRule, getLinePorts());
    DeviceService deviceService = this.handler().get(DeviceService.class);
    OpenRoadmConnection conn = OpenRoadmConnectionFactory.create(name, xc, deviceService);
    OchSignal och = toOchSignalCenterWidth(conn.srcNmcFrequency, conn.srcNmcWidth);
    // Build the rule selector and treatment
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(conn.inPortNumber).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(och)).build();
    Instruction ochInstruction = Instructions.modL0Lambda(och);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().add(ochInstruction).setOutput(conn.outPortNumber).build();
    return DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selector).withTreatment(treatment).withPriority(conn.priority).withCookie(conn.id.value()).build();
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) OchSignal(org.onosproject.net.OchSignal) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) Instruction(org.onosproject.net.flow.instructions.Instruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 40 with OchSignal

use of org.onosproject.net.OchSignal in project onos by opennetworkinglab.

the class CassiniTerminalDeviceDiscovery method toPortDescriptionInternal.

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    Map<String, String> annotations = new HashMap<>();
    /*
        <components xmlns="http://openconfig.net/yang/platform">
             <component>
                <name>oc1/0</name>
                 <config>
                    <name>oc1/0</name>
                 </config>
                 <state>
                    <name>oc1/0</name>
                 <type>OPTICAL_CHANNEL</type>
                <id/>
                <description/>
                <mfg-name/>
                <hardware-version/>
                <firmware-version/>
                <software-version/>
                <serial-no/>
                <part-no/>
                <removable>true</removable>
                <empty>false</empty>
                <parent/>
                <temperature>
                <instant>0.0</instant>
                <avg>0.0</avg>
                <min>0.0</min>
                <max>0.0</max>
                <interval>0</interval>
                <min-time>0</min-time>
                <max-time>0</max-time>
                <alarm-status>true</alarm-status>
                <alarm-threshold>0</alarm-threshold>
                </temperature>
                <memory>
                    <available>0</available>
                    <utilized>0</utilized>
                </memory>
                <allocated-power>0</allocated-power>
                <used-power>0</used-power>
            </state>
            <optical-channel xmlns="http://openconfig.net/yang/terminal-device">
                <config>
                    <line-port>port-10101</line-port>
                </config>
            <state>
                <output-power/>
                <input-power/>
            </state>
            </optical-channel>
        </component>
        */
    String name = component.getString("name");
    String type = component.getString("state/type");
    checkNotNull(name, "name not found");
    checkNotNull(type, "state/type not found");
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    // TODO this currently support only line-side ports through parsing of optical channels.
    if (type.equals(OC_TRANSPORT_TYPES_OPTICAL_CHANNEL)) {
        String portName = component.getString("optical-channel/config/line-port");
        String portIndex = portName.split("-")[1];
        annotations.putIfAbsent(AnnotationKeys.PORT_NAME, portName);
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        annotations.putIfAbsent(ONOS_PORT_INDEX, portIndex);
        annotations.putIfAbsent(CONNECTION_ID, "connection-" + portIndex);
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(PortNumber.portNumber(Long.parseLong(portIndex)), true, // TODO Client signal to be discovered
        OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    } else {
        log.debug("Unknown port component type {}", type);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) OchSignal(org.onosproject.net.OchSignal)

Aggregations

OchSignal (org.onosproject.net.OchSignal)63 PortNumber (org.onosproject.net.PortNumber)17 ChannelSpacing (org.onosproject.net.ChannelSpacing)16 GridType (org.onosproject.net.GridType)14 DeviceId (org.onosproject.net.DeviceId)12 ConnectPoint (org.onosproject.net.ConnectPoint)11 DeviceService (org.onosproject.net.device.DeviceService)10 HashMap (java.util.HashMap)9 Set (java.util.Set)9 IntStream (java.util.stream.IntStream)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Logger (org.slf4j.Logger)8 ArrayList (java.util.ArrayList)7 Port (org.onosproject.net.Port)7 Collectors (java.util.stream.Collectors)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)6 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)6 Collections (java.util.Collections)5 List (java.util.List)5 Frequency (org.onlab.util.Frequency)5