ONOS-3931: BasicDeviceConfig to allow configuration of DeviceKeyId
Change-Id: I75d37709f19913f3382fa7614291e5a837ecf1a1
Showing
2 changed files
with
41 additions
and
4 deletions
... | @@ -17,7 +17,7 @@ package org.onosproject.net.config.basics; | ... | @@ -17,7 +17,7 @@ package org.onosproject.net.config.basics; |
17 | 17 | ||
18 | import org.onosproject.net.Device; | 18 | import org.onosproject.net.Device; |
19 | import org.onosproject.net.DeviceId; | 19 | import org.onosproject.net.DeviceId; |
20 | - | 20 | +import org.onosproject.net.key.DeviceKeyId; |
21 | /** | 21 | /** |
22 | * Basic configuration for network infrastructure devices. | 22 | * Basic configuration for network infrastructure devices. |
23 | */ | 23 | */ |
... | @@ -30,12 +30,13 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { | ... | @@ -30,12 +30,13 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { |
30 | private static final String HW_VERSION = "hwVersion"; | 30 | private static final String HW_VERSION = "hwVersion"; |
31 | private static final String SW_VERSION = "swVersion"; | 31 | private static final String SW_VERSION = "swVersion"; |
32 | private static final String SERIAL = "serial"; | 32 | private static final String SERIAL = "serial"; |
33 | + private static final String DEVICE_KEY_ID = "deviceKeyId"; | ||
33 | 34 | ||
34 | @Override | 35 | @Override |
35 | public boolean isValid() { | 36 | public boolean isValid() { |
36 | return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, | 37 | return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, |
37 | TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL, | 38 | TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL, |
38 | - MANAGEMENT_ADDRESS); | 39 | + MANAGEMENT_ADDRESS, DEVICE_KEY_ID); |
39 | } | 40 | } |
40 | 41 | ||
41 | /** | 42 | /** |
... | @@ -162,7 +163,7 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { | ... | @@ -162,7 +163,7 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { |
162 | } | 163 | } |
163 | 164 | ||
164 | /** | 165 | /** |
165 | - * Sets the driver name. | 166 | + * Sets the device management ip (ip:port). |
166 | * | 167 | * |
167 | * @param managementAddress new device management address (ip:port); null to clear | 168 | * @param managementAddress new device management address (ip:port); null to clear |
168 | * @return self | 169 | * @return self |
... | @@ -171,6 +172,27 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { | ... | @@ -171,6 +172,27 @@ public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { |
171 | return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); | 172 | return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); |
172 | } | 173 | } |
173 | 174 | ||
175 | + /** | ||
176 | + * Returns the device key id. | ||
177 | + * | ||
178 | + * @return device key id or null if not set | ||
179 | + */ | ||
180 | + public DeviceKeyId deviceKeyId() { | ||
181 | + String s = get(DEVICE_KEY_ID, null); | ||
182 | + return s == null ? null : DeviceKeyId.deviceKeyId(s); | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Sets the device key id. | ||
187 | + * | ||
188 | + * @param deviceKeyId new device key id; null to clear | ||
189 | + * @return self | ||
190 | + */ | ||
191 | + public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) { | ||
192 | + return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID, | ||
193 | + deviceKeyId != null ? deviceKeyId.id() : null); | ||
194 | + } | ||
195 | + | ||
174 | // TODO: device port meta-data to be configured via BasicPortsConfig | 196 | // TODO: device port meta-data to be configured via BasicPortsConfig |
175 | // TODO: device credentials/keys; in a separate config | 197 | // TODO: device credentials/keys; in a separate config |
176 | 198 | ... | ... |
... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; | 20 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
21 | import org.junit.Before; | 21 | import org.junit.Before; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onosproject.net.key.DeviceKeyId; | ||
23 | import org.onosproject.net.DeviceId; | 24 | import org.onosproject.net.DeviceId; |
24 | import org.onosproject.net.config.ConfigApplyDelegate; | 25 | import org.onosproject.net.config.ConfigApplyDelegate; |
25 | 26 | ||
... | @@ -39,12 +40,14 @@ public class BasicDeviceConfigTest { | ... | @@ -39,12 +40,14 @@ public class BasicDeviceConfigTest { |
39 | private static final String SW_VERSION = "0.0"; | 40 | private static final String SW_VERSION = "0.0"; |
40 | private static final String SERIAL = "1234"; | 41 | private static final String SERIAL = "1234"; |
41 | private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99"; | 42 | private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99"; |
43 | + private static final DeviceKeyId DEVICE_KEY_ID = DeviceKeyId.deviceKeyId("fooDeviceKeyId"); | ||
42 | private static final String DRIVER_NEW = "barDriver"; | 44 | private static final String DRIVER_NEW = "barDriver"; |
43 | private static final String MANUFACTURER_NEW = "barManufacturer"; | 45 | private static final String MANUFACTURER_NEW = "barManufacturer"; |
44 | private static final String HW_VERSION_NEW = "1.1"; | 46 | private static final String HW_VERSION_NEW = "1.1"; |
45 | private static final String SW_VERSION_NEW = "1.1"; | 47 | private static final String SW_VERSION_NEW = "1.1"; |
46 | private static final String SERIAL_NEW = "5678"; | 48 | private static final String SERIAL_NEW = "5678"; |
47 | private static final String MANAGEMENT_ADDRESS_NEW = "99.87.65.43:12"; | 49 | private static final String MANAGEMENT_ADDRESS_NEW = "99.87.65.43:12"; |
50 | + private static final DeviceKeyId DEVICE_KEY_ID_NEW = DeviceKeyId.deviceKeyId("barDeviceKeyId"); | ||
48 | 51 | ||
49 | private static final String NAME1 = "fooProtocol:fooIP:fooPort"; | 52 | private static final String NAME1 = "fooProtocol:fooIP:fooPort"; |
50 | 53 | ||
... | @@ -58,7 +61,8 @@ public class BasicDeviceConfigTest { | ... | @@ -58,7 +61,8 @@ public class BasicDeviceConfigTest { |
58 | public void setUp() { | 61 | public void setUp() { |
59 | SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); | 62 | SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
60 | SW_BDC.type(SWITCH).manufacturer(MANUFACTURER).hwVersion(HW_VERSION) | 63 | SW_BDC.type(SWITCH).manufacturer(MANUFACTURER).hwVersion(HW_VERSION) |
61 | - .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER); | 64 | + .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER) |
65 | + .deviceKeyId(DEVICE_KEY_ID); | ||
62 | } | 66 | } |
63 | 67 | ||
64 | @Test | 68 | @Test |
... | @@ -71,6 +75,7 @@ public class BasicDeviceConfigTest { | ... | @@ -71,6 +75,7 @@ public class BasicDeviceConfigTest { |
71 | assertEquals("Incorrect swVersion", SW_VERSION, SW_BDC.swVersion()); | 75 | assertEquals("Incorrect swVersion", SW_VERSION, SW_BDC.swVersion()); |
72 | assertEquals("Incorrect serial", SERIAL, SW_BDC.serial()); | 76 | assertEquals("Incorrect serial", SERIAL, SW_BDC.serial()); |
73 | assertEquals("Incorrect management Address", MANAGEMENT_ADDRESS, SW_BDC.managementAddress()); | 77 | assertEquals("Incorrect management Address", MANAGEMENT_ADDRESS, SW_BDC.managementAddress()); |
78 | + assertEquals("Incorrect deviceKeyId", DEVICE_KEY_ID, SW_BDC.deviceKeyId()); | ||
74 | } | 79 | } |
75 | 80 | ||
76 | 81 | ||
... | @@ -119,4 +124,14 @@ public class BasicDeviceConfigTest { | ... | @@ -119,4 +124,14 @@ public class BasicDeviceConfigTest { |
119 | SW_BDC.managementAddress(MANAGEMENT_ADDRESS_NEW); | 124 | SW_BDC.managementAddress(MANAGEMENT_ADDRESS_NEW); |
120 | assertEquals("Incorrect managementAddress", MANAGEMENT_ADDRESS_NEW, SW_BDC.managementAddress()); | 125 | assertEquals("Incorrect managementAddress", MANAGEMENT_ADDRESS_NEW, SW_BDC.managementAddress()); |
121 | } | 126 | } |
127 | + | ||
128 | + @Test | ||
129 | + public void testSetDeviceKeyId() { | ||
130 | + // change device key id | ||
131 | + SW_BDC.deviceKeyId(DEVICE_KEY_ID_NEW); | ||
132 | + assertEquals("Incorrect deviceKeyId", DEVICE_KEY_ID_NEW, SW_BDC.deviceKeyId()); | ||
133 | + // clear device key id | ||
134 | + SW_BDC.deviceKeyId(null); | ||
135 | + assertEquals("Incorrect deviceKeyId", null, SW_BDC.deviceKeyId()); | ||
136 | + } | ||
122 | } | 137 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment