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();
}
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();
}
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();
}
Aggregations