Search in sources :

Example 71 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class PolatisLinkDiscovery method getLinks.

/**
 * Returns the set of LinkDescriptions originating from a Polatis switch.
 * <p>
 * This is the callback required by the LinkDiscovery behaviour.
 * @return Set of outbound unidirectional links as LinkDescriptions
 */
@Override
public Set<LinkDescription> getLinks() {
    Set<LinkDescription> links = new HashSet<>();
    DeviceId deviceID = handler().data().deviceId();
    log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceID) == null) {
        log.warn("NETCONF session to device {} not yet established, will try again...", deviceID);
        return links;
    }
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceID);
    int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
    int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
    log.trace("Talking to device " + handler().data().deviceId().toString());
    String reply = netconfGet(handler(), getPortsFilter());
    // Get port details from switch as PortDescription objects
    List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
    int numPeerPortEntries = 0;
    int numPortsScanned = 0;
    ObjectMapper mapper = new ObjectMapper();
    for (PortDescription port : ports) {
        numPortsScanned++;
        if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
            String peerPortData = port.annotations().value(KEY_PORTPEER);
            if (!peerPortData.equals("")) {
                numPeerPortEntries++;
                if (peerPortData.charAt(0) == '{') {
                    ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
                    ConnectPoint farEndCP = null;
                    try {
                        farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
                    } catch (JsonProcessingException jpe) {
                        log.debug("Error processing peer-port JSON: {}", jpe.toString());
                    }
                    if (farEndCP != null) {
                        log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(), farEndCP.toString());
                        if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
                            log.trace("Peer {} checks out", farEndCP.toString());
                            // now add link to Set<LinkDescription>
                            DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_LINKBIDIR, VALUE_FALSE).set(KEY_LINKALLOWED, VALUE_TRUE).build();
                            ConnectPoint aEndCP = nearEndCP;
                            ConnectPoint bEndCP = farEndCP;
                            // reverse direction of unidirectional link if near-end port is INPUT
                            if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
                                aEndCP = farEndCP;
                                bEndCP = nearEndCP;
                            }
                            LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP, Link.Type.OPTICAL, true, annotations);
                            links.add(newLinkDesc);
                            log.debug("Adding link {}", newLinkDesc);
                        }
                    }
                }
            }
        }
    }
    log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries, links.size(), links.size() == 1 ? "is" : "are");
    log.trace("Links found on this iteration: {}", links);
    return links;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 72 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class OpticalPortOperatorTest method testConfigAddStaticLambda.

@Test
public void testConfigAddStaticLambda() {
    opc.portType(Port.Type.ODUCLT).portNumberName(PORT_NUMBER).staticLambda(CFG_STATIC_LAMBDA);
    PortDescription res;
    res = oper.combine(CP, N_DESC);
    assertEquals("Original port name expected", DESC_PORT_NAME, res.portNumber().name());
    assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
    long sl = Long.valueOf(res.annotations().value(AnnotationKeys.STATIC_LAMBDA));
    assertEquals(CFG_STATIC_LAMBDA, sl);
}
Also used : OduCltPortHelper.oduCltPortDescription(org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription) PortDescription(org.onosproject.net.device.PortDescription) Test(org.junit.Test)

Example 73 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class DeviceManager method removeDevicePorts.

@Override
public void removeDevicePorts(DeviceId deviceId) {
    checkNotNull(deviceId, DEVICE_ID_NULL);
    if (isAvailable(deviceId)) {
        log.debug("Cannot remove ports of device {} while it is available.", deviceId);
        return;
    }
    List<PortDescription> portDescriptions = ImmutableList.of();
    List<DeviceEvent> events = store.updatePorts(getProvider(deviceId).id(), deviceId, portDescriptions);
    if (events != null) {
        for (DeviceEvent event : events) {
            post(event);
        }
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Example 74 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class CzechLightDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId deviceId = handler().data().deviceId();
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceId);
    var deviceType = DeviceType.valueOf(device.annotations().value(DEVICE_TYPE_ANNOTATION));
    List<PortDescription> portDescriptions = Lists.newArrayList();
    if (deviceType == DeviceType.INLINE_AMP) {
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
        annotations.set(AnnotationKeys.PORT_NAME, DESC_PORT_LINE_WEST);
        annotations.set(OdtnDeviceDescriptionDiscovery.PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.toString());
        portDescriptions.add(omsPortDescription(PortNumber.portNumber(PORT_INLINE_WEST), true, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotations.build()));
        annotations = DefaultAnnotations.builder();
        annotations.set(AnnotationKeys.PORT_NAME, DESC_PORT_LINE_EAST);
        annotations.set(OdtnDeviceDescriptionDiscovery.PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.toString());
        portDescriptions.add(omsPortDescription(PortNumber.portNumber(PORT_INLINE_EAST), true, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotations.build()));
        return portDescriptions;
    }
    DefaultAnnotations.Builder annotationsForCommon = DefaultAnnotations.builder();
    switch(deviceType) {
        case LINE_DEGREE:
            annotationsForCommon.set(AnnotationKeys.PORT_NAME, DESC_PORT_LINE);
            annotationsForCommon.set(OdtnDeviceDescriptionDiscovery.PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.toString());
            break;
        case ADD_DROP_FLEX:
        case COHERENT_ADD_DROP:
            annotationsForCommon.set(AnnotationKeys.PORT_NAME, DESC_PORT_EXPRESS);
            break;
        case INLINE_AMP:
            assert false : "this cannot happen because it's handled above, but I have to type this here anyway";
        default:
            assert false : "unhandled device type";
    }
    portDescriptions.add(omsPortDescription(PortNumber.portNumber(PORT_COMMON), true, START_CENTER_FREQ_50, END_CENTER_FREQ_50, CHANNEL_SPACING_50.frequency(), annotationsForCommon.build()));
    final int leafPortCount;
    switch(deviceType) {
        case LINE_DEGREE:
            leafPortCount = 9;
            break;
        case ADD_DROP_FLEX:
            leafPortCount = 20;
            break;
        case COHERENT_ADD_DROP:
            leafPortCount = 8;
            break;
        default:
            log.error("Unsupported CzechLight device type");
            return null;
    }
    for (var i = 1; i <= leafPortCount; ++i) {
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
        final Frequency channelSpacing;
        annotations.set(AnnotationKeys.PORT_NAME, leafPortName(deviceType, i));
        switch(deviceType) {
            case LINE_DEGREE:
                channelSpacing = CHANNEL_SPACING_50.frequency();
                break;
            case ADD_DROP_FLEX:
                annotations.set(OdtnDeviceDescriptionDiscovery.PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.toString());
                channelSpacing = CHANNEL_SPACING_50.frequency();
                break;
            case COHERENT_ADD_DROP:
                annotations.set(OdtnDeviceDescriptionDiscovery.PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.toString());
                channelSpacing = CHANNEL_SPACING_NONE.frequency();
                break;
            default:
                log.error("Unsupported CzechLight device type");
                return null;
        }
        portDescriptions.add(omsPortDescription(PortNumber.portNumber(i), true, START_CENTER_FREQ_50, END_CENTER_FREQ_50, channelSpacing, annotations.build()));
    }
    return portDescriptions;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) Frequency(org.onlab.util.Frequency)

Example 75 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class CiscoNxosDeviceDescription method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    ArrayList<String> cmd = new ArrayList<>();
    cmd.add(SHOW_INTERFACES_CMD);
    String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
    String response = NxApiRequest.post(controller, deviceId, req);
    // parse interface information from response
    List<PortDescription> ports = Lists.newArrayList();
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        JsonNode interfaces = json.findValue(ROW_INTERFACE);
        if (interfaces != null) {
            interfaces.forEach(itf -> {
                String ifName = itf.get(INTERFACE).asText();
                if (ifName.startsWith(ETH)) {
                    String ifNum = ifName.substring(ETHERNET.length()).replace(SLASH, ZERO);
                    boolean state = itf.get(STATE).asText().equals(UP);
                    // in Mbps
                    long portSpeed = itf.get(ETH_BW).asLong() / ONE_THOUSAND;
                    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, ifName);
                    PortDescription desc = DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(ifNum)).isEnabled(state).type(Port.Type.FIBER).portSpeed(portSpeed).annotations(annotations.build()).build();
                    ports.add(desc);
                }
            });
        }
    } catch (IOException e) {
        log.error("Failed to to retrieve Interfaces {}", e);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) RestSBController(org.onosproject.protocol.rest.RestSBController) DriverHandler(org.onosproject.net.driver.DriverHandler) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)81 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)41 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)24 DeviceId (org.onosproject.net.DeviceId)23 ArrayList (java.util.ArrayList)22 Port (org.onosproject.net.Port)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)14 ProviderId (org.onosproject.net.provider.ProviderId)13 Device (org.onosproject.net.Device)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DefaultPort (org.onosproject.net.DefaultPort)9 DeviceService (org.onosproject.net.device.DeviceService)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)6