ONOS-3760 Injection of mfg/hw/sw/serial in BasicDeviceConfig
Change-Id: I7f2269039e0cdabbee85cdad178c4ca27cdc2dce
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 108d68d..c4a4291 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
@@ -59,11 +59,27 @@
if (bdc.type() != null && bdc.type() != type) {
type = bdc.type();
}
+ String manufacturer = descr.manufacturer();
+ if (bdc.manufacturer() != null && !bdc.manufacturer().equals(manufacturer)) {
+ manufacturer = bdc.manufacturer();
+ }
+ String hwVersion = descr.hwVersion();
+ if (bdc.hwVersion() != null && !bdc.hwVersion().equals(hwVersion)) {
+ hwVersion = bdc.hwVersion();
+ }
+ String swVersion = descr.swVersion();
+ if (bdc.swVersion() != null && !bdc.swVersion().equals(swVersion)) {
+ swVersion = bdc.swVersion();
+ }
+ String serial = descr.serialNumber();
+ if (bdc.serial() != null && !bdc.serial().equals(serial)) {
+ serial = bdc.serial();
+ }
SparseAnnotations sa = combine(bdc, descr.annotations());
- return new DefaultDeviceDescription(descr.deviceUri(), type, descr.manufacturer(),
- descr.hwVersion(), descr.swVersion(),
- descr.serialNumber(), descr.chassisId(), sa);
+ return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer,
+ hwVersion, swVersion,
+ serial, descr.chassisId(), sa);
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java b/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
index 2be0df7..138283c 100644
--- a/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
@@ -15,26 +15,25 @@
*/
package org.onosproject.net.device.impl;
-import static org.onosproject.net.Device.Type.SWITCH;
-import static org.onosproject.net.Device.Type.ROADM;
-import static org.junit.Assert.assertEquals;
-
-import java.net.URI;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ChassisId;
-import org.onosproject.net.config.ConfigApplyDelegate;
-import org.onosproject.net.config.basics.BasicDeviceConfig;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DeviceId;
import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.config.ConfigApplyDelegate;
+import org.onosproject.net.config.basics.BasicDeviceConfig;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DeviceDescription;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import java.net.URI;
+
+import static org.junit.Assert.assertEquals;
+import static org.onosproject.net.Device.Type.ROADM;
+import static org.onosproject.net.Device.Type.SWITCH;
public class BasicDeviceOperatorTest {
@@ -47,6 +46,12 @@
private static final String SW = "3.9.1";
private static final String SN = "43311-12345";
private static final ChassisId CID = new ChassisId();
+ private static final String DRIVER = "fooDriver";
+ private static final String MANUFACTURER = "fooManufacturer";
+ private static final String HW_VERSION = "0.0";
+ private static final String SW_VERSION = "0.0";
+ private static final String SERIAL = "1234";
+ private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99";
private static final SparseAnnotations SA = DefaultAnnotations.builder()
.set(AnnotationKeys.DRIVER, NAME2).build();
@@ -65,7 +70,8 @@
SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate);
SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER);
RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate);
- RD_BDC.type(ROADM);
+ RD_BDC.type(ROADM).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
+ .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER).owner(OWNER);
}
@Test
@@ -77,8 +83,14 @@
desc = BasicDeviceOperator.combine(SW_BDC, DEV1);
assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER));
- // override Device Type
+ // override Device Information
desc = BasicDeviceOperator.combine(RD_BDC, DEV1);
- assertEquals(ROADM, desc.type());
+ assertEquals("Wrong type", ROADM, desc.type());
+ assertEquals("Wrong manufacturer", MANUFACTURER, desc.manufacturer());
+ assertEquals("Wrong HwVersion", HW_VERSION, desc.hwVersion());
+ assertEquals("Wrong swVersion", SW_VERSION, desc.swVersion());
+ assertEquals("Wrong serial", SERIAL, desc.serialNumber());
+ assertEquals("Wrong management Address", MANAGEMENT_ADDRESS,
+ desc.annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS));
}
}