use of org.onosproject.net.config.inject.DeviceInjectionConfig in project onos by opennetworkinglab.
the class DeviceInjectionConfigMonitor method injectDevice.
private void injectDevice(DeviceId did) {
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
if (discovery.isPresent()) {
providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
providerService.updatePorts(did, discovery.get().discoverPortDetails());
} else {
String unk = "UNKNOWN";
DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
providerService.deviceConnected(did, desc);
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
int numPorts = Integer.parseInt(ports);
List<PortDescription> portDescs = new ArrayList<>(numPorts);
for (int i = 1; i <= numPorts; ++i) {
// TODO inject port details if something like BasicPortConfig was created
PortNumber number = portNumber(i);
boolean isEnabled = true;
portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
}
providerService.updatePorts(did, portDescs);
}
}
use of org.onosproject.net.config.inject.DeviceInjectionConfig in project onos by opennetworkinglab.
the class ConfigOpticalDeviceDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
NetworkConfigService netcfg = handler().get(NetworkConfigService.class);
DeviceId did = data().deviceId();
String unk = "UNKNOWN";
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfg.getConfig(did, DeviceInjectionConfig.class));
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfg.getConfig(did, BasicDeviceConfig.class));
Device.Type type = basic.map(BasicDeviceConfig::type).orElse(Device.Type.SWITCH);
String manufacturer = basic.map(BasicDeviceConfig::manufacturer).orElse(unk);
String hwVersion = basic.map(BasicDeviceConfig::hwVersion).orElse(unk);
String swVersion = basic.map(BasicDeviceConfig::swVersion).orElse(unk);
String serialNumber = basic.map(BasicDeviceConfig::serial).orElse(unk);
ChassisId chassis = new ChassisId();
// if inject is not specified, return default unavailable device
boolean defaultAvailable = inject.isPresent();
return new DefaultDeviceDescription(did.uri(), type, manufacturer, hwVersion, swVersion, serialNumber, chassis, defaultAvailable);
}
use of org.onosproject.net.config.inject.DeviceInjectionConfig 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;
}
Aggregations