blob: 6d257e4b2d2585918dca010e5d74fcab3926c500 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -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 */
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;
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070031import org.onosproject.net.device.PortDescription;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070032import com.fasterxml.jackson.databind.ObjectMapper;
33import com.fasterxml.jackson.databind.node.JsonNodeFactory;
34
35import static org.junit.Assert.assertEquals;
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070036import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070037
38public class OpticalPortOperatorTest {
39 private static final DeviceId DID = DeviceId.deviceId("op-test");
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070040 private static final long PORT_NUMBER = 100;
41 private static final String CFG_KEY = "optical";
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070042
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070043 private static final String CFG_PORT_NAME = "cfg-name";
44 private static final long CFG_STATIC_LAMBDA = 300L;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070045
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070046 private static final String DESC_PORT_NAME = "test-port-100";
47 private static final PortNumber NAMED = PortNumber.portNumber(PORT_NUMBER, DESC_PORT_NAME);
48 private static final PortNumber UNNAMED = PortNumber.portNumber(PORT_NUMBER);
49
50 private static final String DESC_STATIC_PORT = "out-port-200";
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070051 private static final SparseAnnotations SA = DefaultAnnotations.builder()
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070052 .set(AnnotationKeys.STATIC_PORT, DESC_STATIC_PORT)
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070053 .build();
54
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070055 private static final PortDescription N_DESC = oduCltPortDescription(
Toru Furusawa72ee30c2016-01-08 13:29:04 -080056 NAMED, true, CltSignalType.CLT_100GBE, SA);
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070057 private static final PortDescription U_DESC = oduCltPortDescription(
58 UNNAMED, true, CltSignalType.CLT_100GBE, SA);
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070059
60 private final ConfigApplyDelegate delegate = new MockCfgDelegate();
61 private final ObjectMapper mapper = new ObjectMapper();
62
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070063 private static final ConnectPoint CP = new ConnectPoint(DID, UNNAMED);
64
65 private static final OpticalPortConfig OPC = new OpticalPortConfig();
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070066
67 @Before
68 public void setUp() {
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070069 OPC.init(CP, CFG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate);
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070070 }
71
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070072 @Test
73 public void testConfigPortName() {
74 OPC.portType(Port.Type.ODUCLT)
75 .portNumberName(PORT_NUMBER)
76 .portName(CFG_PORT_NAME);
77
78 PortDescription res;
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070079 // full desc + opc with name
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070080 res = OpticalPortOperator.combine(OPC, N_DESC);
81 assertEquals("Configured port name expected",
82 CFG_PORT_NAME, res.portNumber().name());
83 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
84
85 res = OpticalPortOperator.combine(OPC, U_DESC);
86 assertEquals("Configured port name expected",
87 CFG_PORT_NAME, res.portNumber().name());
88 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
Ayaka Koshibee39c23a2015-08-03 18:17:43 -070089 }
90
HIGUCHI Yutacc10558d2016-06-03 14:27:05 -070091 @Test
92 public void testConfigAddStaticLambda() {
93 OPC.portType(Port.Type.ODUCLT)
94 .portNumberName(PORT_NUMBER)
95 .staticLambda(CFG_STATIC_LAMBDA);
96
97 PortDescription res;
98 res = OpticalPortOperator.combine(OPC, N_DESC);
99 assertEquals("Original port name expected",
100 DESC_PORT_NAME, res.portNumber().name());
101 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
102 long sl = Long.valueOf(res.annotations().value(AnnotationKeys.STATIC_LAMBDA));
103 assertEquals(CFG_STATIC_LAMBDA, sl);
104 }
105
106 @Test
107 public void testEmptyConfig() {
108 OPC.portType(Port.Type.ODUCLT)
109 .portNumberName(PORT_NUMBER);
110
111 PortDescription res;
112 res = OpticalPortOperator.combine(OPC, N_DESC);
113 assertEquals("Configured port name expected",
114 DESC_PORT_NAME, res.portNumber().name());
115 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
116 }
117
118
Ayaka Koshibee39c23a2015-08-03 18:17:43 -0700119 private class MockCfgDelegate implements ConfigApplyDelegate {
120
121 @Override
122 public void onApply(@SuppressWarnings("rawtypes") Config config) {
123 config.apply();
124 }
125
126 }
127}