Search in sources :

Example 1 with OpticalPortConfig

use of org.onosproject.net.optical.config.OpticalPortConfig in project onos by opennetworkinglab.

the class ConfigOpticalDeviceDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
    DeviceId did = data().deviceId();
    DeviceInjectionConfig cfg = netcfg.getConfig(did, DeviceInjectionConfig.class);
    if (cfg == null) {
        return ImmutableList.of();
    }
    String ports = cfg.ports();
    // TODO: parse port format like [1-3,6] in the future
    int numPorts = Integer.parseInt(ports);
    List<PortDescription> portDescs = new ArrayList<>(numPorts);
    for (int i = 1; i <= numPorts; ++i) {
        PortNumber number = PortNumber.portNumber(i);
        ConnectPoint cp = new ConnectPoint(did, number);
        Optional<OpticalPortConfig> port = Optional.ofNullable(netcfg.getConfig(cp, OpticalPortConfig.class));
        boolean isEnabled = true;
        // default packet port speed on configured-optical device (in Mbps)
        int speedFallback = 10_000;
        long portSpeed = port.flatMap(OpticalPortConfig::speed).orElse(speedFallback);
        Port.Type type = port.map(OpticalPortConfig::type).orElse(Port.Type.COPPER);
        portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(type).portSpeed(portSpeed).build());
    }
    return portDescs;
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) OpticalPortConfig(org.onosproject.net.optical.config.OpticalPortConfig) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) PortNumber(org.onosproject.net.PortNumber)

Aggregations

ArrayList (java.util.ArrayList)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 DeviceId (org.onosproject.net.DeviceId)1 Port (org.onosproject.net.Port)1 PortNumber (org.onosproject.net.PortNumber)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 DeviceInjectionConfig (org.onosproject.net.config.inject.DeviceInjectionConfig)1 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)1 PortDescription (org.onosproject.net.device.PortDescription)1 OpticalPortConfig (org.onosproject.net.optical.config.OpticalPortConfig)1