Search in sources :

Example 1 with PortAnnotationConfig

use of org.onosproject.net.config.basics.PortAnnotationConfig in project onos by opennetworkinglab.

the class PortAnnotationOperator method combine.

@Override
public PortDescription combine(ConnectPoint cp, PortDescription descr) {
    PortAnnotationConfig cfg = lookupConfig(cp);
    if (cfg == null) {
        return descr;
    }
    Map<String, String> annotations = cfg.annotations();
    if (annotations.isEmpty()) {
        return descr;
    }
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(descr.annotations());
    builder.putAll(annotations);
    return DefaultPortDescription.builder(descr).annotations(builder.build()).build();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 2 with PortAnnotationConfig

use of org.onosproject.net.config.basics.PortAnnotationConfig in project onos by opennetworkinglab.

the class AnnotatePortCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port);
    if (deviceService.getPort(connectPoint) == null) {
        print("Port %s does not exist.", port);
        return;
    }
    if (removeCfg && key == null) {
        // remove whole port annotation config
        netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class);
        print("Annotation Config about %s removed", connectPoint);
        return;
    }
    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class);
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    cfg.apply();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with PortAnnotationConfig

use of org.onosproject.net.config.basics.PortAnnotationConfig in project onos by opennetworkinglab.

the class PortAnnotationOperator method combine.

@Override
public PortDescription combine(ConnectPoint cp, PortDescription descr, Optional<Config> prevConfig) {
    PortAnnotationConfig cfg = lookupConfig(cp);
    Map<String, String> annotations = new HashMap<>();
    if (cfg != null) {
        annotations.putAll(cfg.annotations());
    }
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(descr.annotations());
    if (prevConfig.isPresent()) {
        PortAnnotationConfig prevDeviceAnnotationConfig = (PortAnnotationConfig) prevConfig.get();
        for (String key : prevDeviceAnnotationConfig.annotations().keySet()) {
            if (!annotations.containsKey(key)) {
                builder.remove(key);
            }
        }
    }
    builder.putAll(annotations);
    return DefaultPortDescription.builder(descr).annotations(builder.build()).build();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) HashMap(java.util.HashMap) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Aggregations

PortAnnotationConfig (org.onosproject.net.config.basics.PortAnnotationConfig)3 Builder (org.onosproject.net.DefaultAnnotations.Builder)2 HashMap (java.util.HashMap)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 DeviceService (org.onosproject.net.device.DeviceService)1