Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 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 | package org.onosproject.net.device.impl; |
| 17 | |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.ChassisId; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 23 | import org.onosproject.net.AnnotationKeys; |
| 24 | import org.onosproject.net.DefaultAnnotations; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.SparseAnnotations; |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 27 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 28 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 29 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 30 | import org.onosproject.net.device.DeviceDescription; |
| 31 | |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 32 | import java.net.URI; |
| 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; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 37 | import static org.onosproject.net.Device.Type.OTN; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 38 | |
| 39 | public class BasicDeviceOperatorTest { |
| 40 | |
| 41 | private static final String NAME1 = "of:foo"; |
| 42 | private static final String NAME2 = "of:bar"; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 43 | private static final String NAME3 = "of:otn"; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 44 | private static final String OWNER = "somebody"; |
| 45 | private static final URI DURI = URI.create(NAME1); |
| 46 | private static final String MFR = "whitebox"; |
| 47 | private static final String HW = "1.1.x"; |
| 48 | private static final String SW = "3.9.1"; |
| 49 | private static final String SN = "43311-12345"; |
| 50 | private static final ChassisId CID = new ChassisId(); |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 51 | private static final String DRIVER = "fooDriver"; |
| 52 | private static final String MANUFACTURER = "fooManufacturer"; |
| 53 | private static final String HW_VERSION = "0.0"; |
| 54 | private static final String SW_VERSION = "0.0"; |
| 55 | private static final String SERIAL = "1234"; |
| 56 | private static final String MANAGEMENT_ADDRESS = "12.34.56.78:99"; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 57 | |
| 58 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
| 59 | .set(AnnotationKeys.DRIVER, NAME2).build(); |
| 60 | |
| 61 | private static final DeviceDescription DEV1 = new DefaultDeviceDescription( |
| 62 | DURI, SWITCH, MFR, HW, SW, SN, CID, SA); |
| 63 | |
Sho SHIMIZU | 7462641 | 2015-09-11 11:46:27 -0700 | [diff] [blame] | 64 | private final ConfigApplyDelegate delegate = config -> { }; |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 65 | private final ObjectMapper mapper = new ObjectMapper(); |
| 66 | |
| 67 | private static final BasicDeviceConfig SW_BDC = new BasicDeviceConfig(); |
| 68 | private static final BasicDeviceConfig RD_BDC = new BasicDeviceConfig(); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 69 | private static final BasicDeviceConfig OT_BDC = new BasicDeviceConfig(); |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 70 | |
| 71 | @Before |
| 72 | public void setUp() { |
| 73 | SW_BDC.init(DeviceId.deviceId(NAME1), NAME1, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 74 | SW_BDC.type(SWITCH).driver(NAME1).owner(OWNER); |
| 75 | RD_BDC.init(DeviceId.deviceId(NAME2), NAME2, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 76 | RD_BDC.type(ROADM).manufacturer(MANUFACTURER).hwVersion(HW_VERSION) |
| 77 | .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER).owner(OWNER); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 78 | OT_BDC.init(DeviceId.deviceId(NAME3), NAME3, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
| 79 | OT_BDC.type(OTN); |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testDescOps() { |
| 84 | DeviceDescription desc = BasicDeviceOperator.combine(null, DEV1); |
| 85 | assertEquals(desc, DEV1); |
| 86 | |
| 87 | // override driver name |
| 88 | desc = BasicDeviceOperator.combine(SW_BDC, DEV1); |
| 89 | assertEquals(NAME1, desc.annotations().value(AnnotationKeys.DRIVER)); |
| 90 | |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 91 | // override Device Information |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 92 | desc = BasicDeviceOperator.combine(RD_BDC, DEV1); |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 93 | assertEquals("Wrong type", ROADM, desc.type()); |
| 94 | assertEquals("Wrong manufacturer", MANUFACTURER, desc.manufacturer()); |
| 95 | assertEquals("Wrong HwVersion", HW_VERSION, desc.hwVersion()); |
| 96 | assertEquals("Wrong swVersion", SW_VERSION, desc.swVersion()); |
| 97 | assertEquals("Wrong serial", SERIAL, desc.serialNumber()); |
| 98 | assertEquals("Wrong management Address", MANAGEMENT_ADDRESS, |
| 99 | desc.annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS)); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 100 | |
| 101 | // override Device type |
| 102 | desc = BasicDeviceOperator.combine(OT_BDC, DEV1); |
| 103 | assertEquals(OTN, desc.type()); |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 104 | } |
| 105 | } |