blob: 3d8a83d8de40329dde78672c8fe3d2dfa63a38fc [file] [log] [blame]
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -07003 *
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 */
16package org.onosproject.net.device.impl;
17
Andrea Campanellab75b4882016-01-15 15:15:09 -080018import com.fasterxml.jackson.databind.ObjectMapper;
19import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070020import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.ChassisId;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070023import org.onosproject.net.AnnotationKeys;
24import org.onosproject.net.DefaultAnnotations;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.SparseAnnotations;
Andrea Campanellab75b4882016-01-15 15:15:09 -080027import org.onosproject.net.config.ConfigApplyDelegate;
28import org.onosproject.net.config.basics.BasicDeviceConfig;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070029import org.onosproject.net.device.DefaultDeviceDescription;
30import org.onosproject.net.device.DeviceDescription;
31
Andrea Campanellab75b4882016-01-15 15:15:09 -080032import java.net.URI;
33
34import static org.junit.Assert.assertEquals;
35import static org.onosproject.net.Device.Type.ROADM;
36import static org.onosproject.net.Device.Type.SWITCH;
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020037import static org.onosproject.net.Device.Type.OTN;
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070038
39public class BasicDeviceOperatorTest {
40
41 private static final String NAME1 = "of:foo";
42 private static final String NAME2 = "of:bar";
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020043 private static final String NAME3 = "of:otn";
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070044 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 Campanellab75b4882016-01-15 15:15:09 -080051 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 Koshibeb1ffb002015-08-04 15:10:03 -070057
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 SHIMIZU74626412015-09-11 11:46:27 -070064 private final ConfigApplyDelegate delegate = config -> { };
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070065 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 Ashkenazy8ebfff02016-02-01 11:56:36 +020069 private static final BasicDeviceConfig OT_BDC = new BasicDeviceConfig();
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070070
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 Campanellab75b4882016-01-15 15:15:09 -080076 RD_BDC.type(ROADM).manufacturer(MANUFACTURER).hwVersion(HW_VERSION)
77 .swVersion(SW_VERSION).serial(SERIAL).managementAddress(MANAGEMENT_ADDRESS).driver(DRIVER).owner(OWNER);
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020078 OT_BDC.init(DeviceId.deviceId(NAME3), NAME3, JsonNodeFactory.instance.objectNode(), mapper, delegate);
79 OT_BDC.type(OTN);
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070080 }
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 Campanellab75b4882016-01-15 15:15:09 -080091 // override Device Information
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070092 desc = BasicDeviceOperator.combine(RD_BDC, DEV1);
Andrea Campanellab75b4882016-01-15 15:15:09 -080093 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 Ashkenazy8ebfff02016-02-01 11:56:36 +0200100
101 // override Device type
102 desc = BasicDeviceOperator.combine(OT_BDC, DEV1);
103 assertEquals(OTN, desc.type());
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -0700104 }
105}