andrea
Committed by Gerrit Code Review

minor formatting changes

Change-Id: I361955b820489793ffb8f6b9b9ff24d429e1dd99
......@@ -25,8 +25,10 @@ package org.onosproject.net;
*/
public final class AnnotationKeys {
// Prohibit instantiation
private AnnotationKeys() {}
private AnnotationKeys() {
}
/**
* Annotation key for instance name.
......@@ -125,12 +127,22 @@ public final class AnnotationKeys {
public static final String OWNER = "owner";
/**
* Annotation key for the channel id.
*/
public static final String CHANNEL_ID = "channelId";
/**
* Annotation key for the management address.
*/
public static final String MANAGEMENT_ADDRESS = "managementAddress";
/**
* Returns the value annotated object for the specified annotation key.
* The annotated value is expected to be String that can be parsed as double.
* If parsing fails, the returned value will be 1.0.
*
* @param annotated annotated object whose annotated value is obtained
* @param key key of annotation
* @param key key of annotation
* @return double value of annotated object for the specified key
*/
public static double getAnnotatedValue(Annotated annotated, String key) {
......
......@@ -25,6 +25,7 @@ public class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
public static final String TYPE = "type";
public static final String DRIVER = "driver";
public static final String MANAGEMENT_ADDRESS = "managementAddress";
/**
* Returns the device type.
......@@ -64,6 +65,25 @@ public class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
return (BasicElementConfig) setOrClear(DRIVER, driverName);
}
/**
* Returns the device management ip (ip:port).
*
* @return device management address (ip:port) or null if not set
*/
public String managementAddress() {
return get(MANAGEMENT_ADDRESS, null);
}
/**
* Sets the driver name.
*
* @param managementAddress new device management address (ip:port); null to clear
* @return self
*/
public BasicElementConfig managementAddress(String managementAddress) {
return (BasicElementConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
}
// TODO: device port meta-data to be configured via BasicPortsConfig
// TODO: device credentials/keys
......
......@@ -15,21 +15,21 @@
*/
package org.onosproject.net.device.impl;
import static org.slf4j.LoggerFactory.getLogger;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onosproject.net.config.ConfigOperator;
import org.onosproject.net.config.basics.BasicDeviceConfig;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.config.ConfigOperator;
import org.onosproject.net.config.basics.BasicDeviceConfig;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DeviceDescription;
import org.slf4j.Logger;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Implementations of merge policies for various sources of device configuration
* information. This includes applications, provides, and network configurations.
......@@ -46,7 +46,7 @@ public final class BasicDeviceOperator implements ConfigOperator {
* Generates a DeviceDescription containing fields from a DeviceDescription and
* a DeviceConfig.
*
* @param bdc the device config entity from network config
* @param bdc the device config entity from network config
* @param descr a DeviceDescription
* @return DeviceDescription based on both sources
*/
......@@ -70,7 +70,7 @@ public final class BasicDeviceOperator implements ConfigOperator {
* Generates an annotation from an existing annotation and DeviceConfig.
*
* @param bdc the device config entity from network config
* @param an the annotation
* @param an the annotation
* @return annotation combining both sources
*/
public static SparseAnnotations combine(BasicDeviceConfig bdc, SparseAnnotations an) {
......@@ -93,6 +93,9 @@ public final class BasicDeviceOperator implements ConfigOperator {
if (bdc.owner() != null) {
newBuilder.set(AnnotationKeys.OWNER, bdc.owner());
}
if (bdc.managementAddress() != null) {
newBuilder.set(AnnotationKeys.MANAGEMENT_ADDRESS, bdc.managementAddress());
}
DefaultAnnotations newAnnotations = newBuilder.build();
return DefaultAnnotations.union(an, newAnnotations);
}
......
......@@ -323,8 +323,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
ChassisId cId = new ChassisId(dpid.value());
SparseAnnotations annotations = DefaultAnnotations.builder()
.set("protocol", sw.factory().getVersion().toString())
.set("channelId", sw.channelId())
.set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString())
.set(AnnotationKeys.CHANNEL_ID, sw.channelId())
.set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0])
.build();
DeviceDescription description =
......