blob: 7c1aefdc91eed538087b237c37ece507075c499b [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 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 */
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070016package org.onosproject.net.device.impl;
17
18import org.junit.Before;
19import org.junit.Test;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080020import org.onosproject.net.CltSignalType;
Ray Milkeya4122362015-08-18 15:19:08 -070021import org.onosproject.net.config.Config;
22import org.onosproject.net.config.ConfigApplyDelegate;
Thomas Vachuska4998caa2015-08-26 13:28:38 -070023import org.onosproject.net.config.basics.OpticalPortConfig;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070024import org.onosproject.net.AnnotationKeys;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.DefaultAnnotations;
27import org.onosproject.net.DeviceId;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070028import org.onosproject.net.Port;
29import org.onosproject.net.PortNumber;
30import org.onosproject.net.SparseAnnotations;
31import org.onosproject.net.device.OduCltPortDescription;
32
33import com.fasterxml.jackson.databind.ObjectMapper;
34import com.fasterxml.jackson.databind.node.JsonNodeFactory;
35
36import static org.junit.Assert.assertEquals;
37
38public class OpticalPortOperatorTest {
39 private static final DeviceId DID = DeviceId.deviceId("op-test");
40 private static final String TPNAME = "test-port-100";
41 private static final String SPNAME = "out-port-200";
42 private static final String CFGNAME = "cfg-name";
43
44 private static final PortNumber NAMED = PortNumber.portNumber(100, TPNAME);
45 private static final PortNumber UNNAMED = PortNumber.portNumber(101);
46 private static final ConnectPoint NCP = new ConnectPoint(DID, UNNAMED);
47
48 private static final SparseAnnotations SA = DefaultAnnotations.builder()
49 .set(AnnotationKeys.STATIC_PORT, SPNAME)
50 .build();
51
52 private static final OduCltPortDescription N_DESC = new OduCltPortDescription(
Toru Furusawa72ee30c2016-01-08 13:29:04 -080053 NAMED, true, CltSignalType.CLT_100GBE, SA);
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070054 private static final OduCltPortDescription FAULTY = new OduCltPortDescription(
Toru Furusawa72ee30c2016-01-08 13:29:04 -080055 null, true, CltSignalType.CLT_100GBE);
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070056
57 private final ConfigApplyDelegate delegate = new MockCfgDelegate();
58 private final ObjectMapper mapper = new ObjectMapper();
59
60 private static final OpticalPortConfig N_OPC = new OpticalPortConfig();
61 private static final OpticalPortConfig UNN_OPC = new OpticalPortConfig();
62
63 @Before
64 public void setUp() {
65 N_OPC.init(NCP, TPNAME, JsonNodeFactory.instance.objectNode(), mapper, delegate);
66 UNN_OPC.init(NCP, TPNAME, JsonNodeFactory.instance.objectNode(), mapper, delegate);
67
68 N_OPC.portName(CFGNAME).portNumberName(101L).portType(Port.Type.ODUCLT).staticLambda(300L);
69 UNN_OPC.portType(Port.Type.ODUCLT);
70 }
71
72 @Test(expected = RuntimeException.class)
73 public void testDescOps() {
74 // port-null desc + opc with port number name
75 OduCltPortDescription res = (OduCltPortDescription) OpticalPortOperator.combine(N_OPC, FAULTY);
76 assertEquals(CFGNAME, res.portNumber().name());
77 // full desc + opc with name
78 assertEquals(TPNAME, N_DESC.portNumber().name());
79 res = (OduCltPortDescription) OpticalPortOperator.combine(N_OPC, N_DESC);
80 long sl = Long.valueOf(res.annotations().value(AnnotationKeys.STATIC_LAMBDA));
81 assertEquals(CFGNAME, res.portNumber().name());
82 assertEquals(300L, sl);
83 // port-null desc + opc without port number name - throws RE
84 res = (OduCltPortDescription) OpticalPortOperator.combine(UNN_OPC, FAULTY);
85 }
86
87 private class MockCfgDelegate implements ConfigApplyDelegate {
88
89 @Override
90 public void onApply(@SuppressWarnings("rawtypes") Config config) {
91 config.apply();
92 }
93
94 }
95}