Andrea Campanella
Committed by Gerrit Code Review

ONOS-3760 Injection of mfg/hw/sw/serial in BasicDeviceConfig

Change-Id: I7f2269039e0cdabbee85cdad178c4ca27cdc2dce
...@@ -26,11 +26,16 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { ...@@ -26,11 +26,16 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
26 private static final String TYPE = "type"; 26 private static final String TYPE = "type";
27 private static final String DRIVER = "driver"; 27 private static final String DRIVER = "driver";
28 private static final String MANAGEMENT_ADDRESS = "managementAddress"; 28 private static final String MANAGEMENT_ADDRESS = "managementAddress";
29 + private static final String MANUFACTURER = "manufacturer";
30 + private static final String HW_VERSION = "hwVersion";
31 + private static final String SW_VERSION = "swVersion";
32 + private static final String SERIAL = "serial";
29 33
30 @Override 34 @Override
31 public boolean isValid() { 35 public boolean isValid() {
32 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, 36 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER,
33 - TYPE, DRIVER, MANAGEMENT_ADDRESS); 37 + TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
38 + MANAGEMENT_ADDRESS);
34 } 39 }
35 40
36 /** 41 /**
...@@ -55,7 +60,7 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { ...@@ -55,7 +60,7 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
55 /** 60 /**
56 * Returns the device driver name. 61 * Returns the device driver name.
57 * 62 *
58 - * @return driver name of null if not set 63 + * @return driver name or null if not set
59 */ 64 */
60 public String driver() { 65 public String driver() {
61 return get(DRIVER, null); 66 return get(DRIVER, null);
...@@ -67,8 +72,84 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { ...@@ -67,8 +72,84 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
67 * @param driverName new driver name; null to clear 72 * @param driverName new driver name; null to clear
68 * @return self 73 * @return self
69 */ 74 */
70 - public BasicElementConfig driver(String driverName) { 75 + public BasicDeviceConfig driver(String driverName) {
71 - return (BasicElementConfig) setOrClear(DRIVER, driverName); 76 + return (BasicDeviceConfig) setOrClear(DRIVER, driverName);
77 + }
78 +
79 + /**
80 + * Returns the device manufacturer.
81 + *
82 + * @return manufacturer or null if not set
83 + */
84 + public String manufacturer() {
85 + return get(MANUFACTURER, null);
86 + }
87 +
88 + /**
89 + * Sets the device manufacturer.
90 + *
91 + * @param manufacturerName new manufacturer; null to clear
92 + * @return self
93 + */
94 + public BasicDeviceConfig manufacturer(String manufacturerName) {
95 + return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName);
96 + }
97 +
98 + /**
99 + * Returns the device hardware version.
100 + *
101 + * @return hardware version or null if not set
102 + */
103 + public String hwVersion() {
104 + return get(HW_VERSION, null);
105 + }
106 +
107 + /**
108 + * Sets the device hardware version.
109 + *
110 + * @param hwVersion new hardware version; null to clear
111 + * @return self
112 + */
113 + public BasicDeviceConfig hwVersion(String hwVersion) {
114 + return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion);
115 + }
116 +
117 + /**
118 + * Returns the device software version.
119 + *
120 + * @return software version or null if not set
121 + */
122 + public String swVersion() {
123 + return get(SW_VERSION, null);
124 + }
125 +
126 + /**
127 + * Sets the device software version.
128 + *
129 + * @param swVersion new software version; null to clear
130 + * @return self
131 + */
132 + public BasicDeviceConfig swVersion(String swVersion) {
133 + return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion);
134 + }
135 +
136 + /**
137 + * Returns the device serial number.
138 + *
139 + * @return serial number or null if not set
140 + */
141 + public String serial() {
142 + return get(SERIAL, null);
143 + }
144 +
145 + /**
146 + * Sets the device serial number.
147 + *
148 + * @param serial new serial number; null to clear
149 + * @return self
150 + */
151 + public BasicDeviceConfig serial(String serial) {
152 + return (BasicDeviceConfig) setOrClear(SERIAL, serial);
72 } 153 }
73 154
74 /** 155 /**
...@@ -86,8 +167,8 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { ...@@ -86,8 +167,8 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
86 * @param managementAddress new device management address (ip:port); null to clear 167 * @param managementAddress new device management address (ip:port); null to clear
87 * @return self 168 * @return self
88 */ 169 */
89 - public BasicElementConfig managementAddress(String managementAddress) { 170 + public BasicDeviceConfig managementAddress(String managementAddress) {
90 - return (BasicElementConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); 171 + return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
91 } 172 }
92 173
93 // TODO: device port meta-data to be configured via BasicPortsConfig 174 // TODO: device port meta-data to be configured via BasicPortsConfig
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.net.config.basics;
18 +
19 +import com.fasterxml.jackson.databind.ObjectMapper;
20 +import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onosproject.net.DeviceId;
24 +import org.onosproject.net.config.ConfigApplyDelegate;
25 +
26 +import static org.junit.Assert.assertEquals;
27 +import static org.junit.Assert.assertTrue;
28 +import static org.onosproject.net.Device.Type.OTN;
29 +import static org.onosproject.net.Device.Type.SWITCH;
30 +
31 +/**
32 + * Test class for BasicDeviceConfig.
33 + */
34 +public class BasicDeviceConfigTest {
35 +
36 + private static final String DRIVER = "fooDriver";
37 + private static final String MANUFACTURER = "fooManufacturer";
38 + private static final String HW_VERSION = "0.0";
39 + private static final String SW_VERSION = "0.0";
40 + private static final String SERIAL = "1234";
41 + private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99";
42 + private static final String DRIVER_NEW = "barDriver";
43 + private static final String MANUFACTURER_NEW = "barManufacturer";
44 + private static final String HW_VERSION_NEW = "1.1";
45 + private static final String SW_VERSION_NEW = "1.1";
46 + private static final String SERIAL_NEW = "5678";
47 + private static final String MANAGEMENT_ADDRESS_NEW = "99.87.65.43:12";
48 +
49 + private static final String NAME1 = "fooProtocol:fooIP:fooPort";
50 +
51 + private final ConfigApplyDelegate delegate = config -> {
52 + };
53 + private final ObjectMapper mapper = new ObjectMapper();
54 +
55 + private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig();
56 +
57 + @Before
58 + public void setUp() {
59 + SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate);
60 + SW_BDC.type(SWITCH).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
61 + .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER);
62 + }
63 +
64 + @Test
65 + public void testCorrectConfiguration() {
66 + assertTrue("Configuration contains not valid fields", SW_BDC.isValid());
67 + assertEquals("Incorrect type", SWITCH, SW_BDC.type());
68 + assertEquals("Incorrect driver", DRIVER, SW_BDC.driver());
69 + assertEquals("Incorrect manufacturer", MANUFACTURER, SW_BDC.manufacturer());
70 + assertEquals("Incorrect HwVersion", HW_VERSION, SW_BDC.hwVersion());
71 + assertEquals("Incorrect swVersion", SW_VERSION, SW_BDC.swVersion());
72 + assertEquals("Incorrect serial", SERIAL, SW_BDC.serial());
73 + assertEquals("Incorrect management Address", MANAGEMENT_ADDRESS, SW_BDC.managementAddress());
74 + }
75 +
76 +
77 + @Test
78 + public void testSetType() {
79 + SW_BDC.type(OTN);
80 + assertEquals("Incorrect type", OTN, SW_BDC.type());
81 + }
82 +
83 +
84 + @Test
85 + public void testSetDriver() {
86 + SW_BDC.driver(DRIVER_NEW);
87 + assertEquals("Incorrect driver", DRIVER_NEW, SW_BDC.driver());
88 + }
89 +
90 +
91 + @Test
92 + public void testSetManufacturer() {
93 + SW_BDC.manufacturer(MANUFACTURER_NEW);
94 + assertEquals("Incorrect manufacturer", MANUFACTURER_NEW, SW_BDC.manufacturer());
95 + }
96 +
97 +
98 + @Test
99 + public void testSetHwVersion() {
100 + SW_BDC.hwVersion(HW_VERSION_NEW);
101 + assertEquals("Incorrect HwVersion", HW_VERSION_NEW, SW_BDC.hwVersion());
102 + }
103 +
104 +
105 + @Test
106 + public void testSetSwVersion() {
107 + SW_BDC.swVersion(SW_VERSION_NEW);
108 + assertEquals("Incorrect swVersion", SW_VERSION_NEW, SW_BDC.swVersion());
109 + }
110 +
111 + @Test
112 + public void testSetSerial() {
113 + SW_BDC.serial(SERIAL_NEW);
114 + assertEquals("Incorrect serial", SERIAL_NEW, SW_BDC.serial());
115 + }
116 +
117 + @Test
118 + public void testSetManagementAddress() {
119 + SW_BDC.managementAddress(MANAGEMENT_ADDRESS_NEW);
120 + assertEquals("Incorrect managementAddress", MANAGEMENT_ADDRESS_NEW, SW_BDC.managementAddress());
121 + }
122 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -59,11 +59,27 @@ public final class BasicDeviceOperator implements ConfigOperator { ...@@ -59,11 +59,27 @@ public final class BasicDeviceOperator implements ConfigOperator {
59 if (bdc.type() != null && bdc.type() != type) { 59 if (bdc.type() != null && bdc.type() != type) {
60 type = bdc.type(); 60 type = bdc.type();
61 } 61 }
62 + String manufacturer = descr.manufacturer();
63 + if (bdc.manufacturer() != null && !bdc.manufacturer().equals(manufacturer)) {
64 + manufacturer = bdc.manufacturer();
65 + }
66 + String hwVersion = descr.hwVersion();
67 + if (bdc.hwVersion() != null && !bdc.hwVersion().equals(hwVersion)) {
68 + hwVersion = bdc.hwVersion();
69 + }
70 + String swVersion = descr.swVersion();
71 + if (bdc.swVersion() != null && !bdc.swVersion().equals(swVersion)) {
72 + swVersion = bdc.swVersion();
73 + }
74 + String serial = descr.serialNumber();
75 + if (bdc.serial() != null && !bdc.serial().equals(serial)) {
76 + serial = bdc.serial();
77 + }
62 78
63 SparseAnnotations sa = combine(bdc, descr.annotations()); 79 SparseAnnotations sa = combine(bdc, descr.annotations());
64 - return new DefaultDeviceDescription(descr.deviceUri(), type, descr.manufacturer(), 80 + return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer,
65 - descr.hwVersion(), descr.swVersion(), 81 + hwVersion, swVersion,
66 - descr.serialNumber(), descr.chassisId(), sa); 82 + serial, descr.chassisId(), sa);
67 } 83 }
68 84
69 /** 85 /**
......
...@@ -15,26 +15,25 @@ ...@@ -15,26 +15,25 @@
15 */ 15 */
16 package org.onosproject.net.device.impl; 16 package org.onosproject.net.device.impl;
17 17
18 -import static org.onosproject.net.Device.Type.SWITCH; 18 +import com.fasterxml.jackson.databind.ObjectMapper;
19 -import static org.onosproject.net.Device.Type.ROADM; 19 +import com.fasterxml.jackson.databind.node.JsonNodeFactory;
20 -import static org.junit.Assert.assertEquals;
21 -
22 -import java.net.URI;
23 -
24 import org.junit.Before; 20 import org.junit.Before;
25 import org.junit.Test; 21 import org.junit.Test;
26 import org.onlab.packet.ChassisId; 22 import org.onlab.packet.ChassisId;
27 -import org.onosproject.net.config.ConfigApplyDelegate;
28 -import org.onosproject.net.config.basics.BasicDeviceConfig;
29 import org.onosproject.net.AnnotationKeys; 23 import org.onosproject.net.AnnotationKeys;
30 import org.onosproject.net.DefaultAnnotations; 24 import org.onosproject.net.DefaultAnnotations;
31 import org.onosproject.net.DeviceId; 25 import org.onosproject.net.DeviceId;
32 import org.onosproject.net.SparseAnnotations; 26 import org.onosproject.net.SparseAnnotations;
27 +import org.onosproject.net.config.ConfigApplyDelegate;
28 +import org.onosproject.net.config.basics.BasicDeviceConfig;
33 import org.onosproject.net.device.DefaultDeviceDescription; 29 import org.onosproject.net.device.DefaultDeviceDescription;
34 import org.onosproject.net.device.DeviceDescription; 30 import org.onosproject.net.device.DeviceDescription;
35 31
36 -import com.fasterxml.jackson.databind.ObjectMapper; 32 +import java.net.URI;
37 -import com.fasterxml.jackson.databind.node.JsonNodeFactory; 33 +
34 +import static org.junit.Assert.assertEquals;
35 +import static org.onosproject.net.Device.Type.ROADM;
36 +import static org.onosproject.net.Device.Type.SWITCH;
38 37
39 public class BasicDeviceOperatorTest { 38 public class BasicDeviceOperatorTest {
40 39
...@@ -47,6 +46,12 @@ public class BasicDeviceOperatorTest { ...@@ -47,6 +46,12 @@ public class BasicDeviceOperatorTest {
47 private static final String SW = "3.9.1"; 46 private static final String SW = "3.9.1";
48 private static final String SN = "43311-12345"; 47 private static final String SN = "43311-12345";
49 private static final ChassisId CID = new ChassisId(); 48 private static final ChassisId CID = new ChassisId();
49 + private static final String DRIVER = "fooDriver";
50 + private static final String MANUFACTURER = "fooManufacturer";
51 + private static final String HW_VERSION = "0.0";
52 + private static final String SW_VERSION = "0.0";
53 + private static final String SERIAL = "1234";
54 + private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99";
50 55
51 private static final SparseAnnotations SA = DefaultAnnotations.builder() 56 private static final SparseAnnotations SA = DefaultAnnotations.builder()
52 .set(AnnotationKeys.DRIVER, NAME2).build(); 57 .set(AnnotationKeys.DRIVER, NAME2).build();
...@@ -65,7 +70,8 @@ public class BasicDeviceOperatorTest { ...@@ -65,7 +70,8 @@ public class BasicDeviceOperatorTest {
65 SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); 70 SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate);
66 SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER); 71 SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER);
67 RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate); 72 RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate);
68 - RD_BDC.type(ROADM); 73 + RD_BDC.type(ROADM).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
74 + .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER).owner(OWNER);
69 } 75 }
70 76
71 @Test 77 @Test
...@@ -77,8 +83,14 @@ public class BasicDeviceOperatorTest { ...@@ -77,8 +83,14 @@ public class BasicDeviceOperatorTest {
77 desc = BasicDeviceOperator.combine(SW_BDC, DEV1); 83 desc = BasicDeviceOperator.combine(SW_BDC, DEV1);
78 assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER)); 84 assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER));
79 85
80 - // override Device Type 86 + // override Device Information
81 desc = BasicDeviceOperator.combine(RD_BDC, DEV1); 87 desc = BasicDeviceOperator.combine(RD_BDC, DEV1);
82 - assertEquals(ROADM, desc.type()); 88 + assertEquals("Wrong type", ROADM, desc.type());
89 + assertEquals("Wrong manufacturer", MANUFACTURER, desc.manufacturer());
90 + assertEquals("Wrong HwVersion", HW_VERSION, desc.hwVersion());
91 + assertEquals("Wrong swVersion", SW_VERSION, desc.swVersion());
92 + assertEquals("Wrong serial", SERIAL, desc.serialNumber());
93 + assertEquals("Wrong management Address", MANAGEMENT_ADDRESS,
94 + desc.annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS));
83 } 95 }
84 } 96 }
......