diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java index 4949bc40a4..8c5fb7909c 100644 --- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java +++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java @@ -25,8 +25,10 @@ package org.onosproject.net; */ public final class AnnotationKeys { + // Prohibit instantiation - private AnnotationKeys() {} + private AnnotationKeys() { + } /** * Annotation key for instance name. @@ -124,13 +126,23 @@ 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) { diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java index fd8bfa3ec1..afde9a9e6e 100644 --- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java +++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicDeviceConfig.java @@ -25,6 +25,7 @@ public class BasicDeviceConfig extends BasicElementConfig { 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 { 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 diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java b/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java index 7900d185ff..fa90eb650b 100644 --- a/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java +++ b/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java @@ -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); } diff --git a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java index 2108ba408e..4fa961f81b 100644 --- a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java +++ b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java @@ -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 =