Search in sources :

Example 1 with LinkDiscoveryFromDevice

use of org.onosproject.provider.lldp.impl.LinkDiscoveryFromDevice in project onos by opennetworkinglab.

the class ConfigLinkDiscoveryCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    DeviceId did = DeviceId.deviceId(device);
    ConnectPoint cp = Optional.ofNullable(port).map(PortNumber::fromString).map(pn -> new ConnectPoint(did, pn)).orElse(null);
    if (cp == null) {
        // device config
        if (!remove) {
            if (deviceService.getDevice(did) == null) {
                print("[WARN] configuring about unknown device %s", did);
            }
            LinkDiscoveryFromDevice cfg;
            cfg = netcfgService.addConfig(did, LinkDiscoveryFromDevice.class);
            cfg.enabled(enable);
            cfg.apply();
        } else {
            netcfgService.removeConfig(did, LinkDiscoveryFromDevice.class);
        }
    } else {
        // port config
        if (!remove) {
            if (deviceService.getPort(cp) == null) {
                print("[WARN] configuring about unknown port %s", cp);
            }
            LinkDiscoveryFromPort cfg;
            cfg = netcfgService.addConfig(cp, LinkDiscoveryFromPort.class);
            cfg.enabled(enable);
            cfg.apply();
        } else {
            netcfgService.removeConfig(cp, LinkDiscoveryFromPort.class);
        }
    }
}
Also used : PortNumberCompleter(org.onosproject.cli.net.PortNumberCompleter) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Argument(org.apache.karaf.shell.api.action.Argument) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) LinkDiscoveryFromPort(org.onosproject.provider.lldp.impl.LinkDiscoveryFromPort) DeviceIdCompleter(org.onosproject.cli.net.DeviceIdCompleter) LinkDiscoveryFromDevice(org.onosproject.provider.lldp.impl.LinkDiscoveryFromDevice) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) LinkDiscoveryFromPort(org.onosproject.provider.lldp.impl.LinkDiscoveryFromPort) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) LinkDiscoveryFromDevice(org.onosproject.provider.lldp.impl.LinkDiscoveryFromDevice) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

Optional (java.util.Optional)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1 Option (org.apache.karaf.shell.api.action.Option)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 DeviceIdCompleter (org.onosproject.cli.net.DeviceIdCompleter)1 PortNumberCompleter (org.onosproject.cli.net.PortNumberCompleter)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 DeviceId (org.onosproject.net.DeviceId)1 PortNumber (org.onosproject.net.PortNumber)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 DeviceService (org.onosproject.net.device.DeviceService)1 LinkDiscoveryFromDevice (org.onosproject.provider.lldp.impl.LinkDiscoveryFromDevice)1 LinkDiscoveryFromPort (org.onosproject.provider.lldp.impl.LinkDiscoveryFromPort)1