Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -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 | */ |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 16 | package org.onosproject.net.device.impl; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 20 | import org.onosproject.net.CltSignalType; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 21 | import org.onosproject.net.config.Config; |
| 22 | import org.onosproject.net.config.ConfigApplyDelegate; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 23 | import org.onosproject.net.config.basics.OpticalPortConfig; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 24 | import org.onosproject.net.AnnotationKeys; |
| 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.DefaultAnnotations; |
| 27 | import org.onosproject.net.DeviceId; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 28 | import org.onosproject.net.Port; |
| 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.net.SparseAnnotations; |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 31 | import org.onosproject.net.device.PortDescription; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 32 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 33 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 34 | |
| 35 | import static org.junit.Assert.assertEquals; |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 36 | import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 37 | |
| 38 | public class OpticalPortOperatorTest { |
| 39 | private static final DeviceId DID = DeviceId.deviceId("op-test"); |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 40 | private static final long PORT_NUMBER = 100; |
| 41 | private static final String CFG_KEY = "optical"; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 42 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 43 | private static final String CFG_PORT_NAME = "cfg-name"; |
| 44 | private static final long CFG_STATIC_LAMBDA = 300L; |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 45 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 46 | 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 Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 51 | private static final SparseAnnotations SA = DefaultAnnotations.builder() |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 52 | .set(AnnotationKeys.STATIC_PORT, DESC_STATIC_PORT) |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 53 | .build(); |
| 54 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 55 | private static final PortDescription N_DESC = oduCltPortDescription( |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 56 | NAMED, true, CltSignalType.CLT_100GBE, SA); |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 57 | private static final PortDescription U_DESC = oduCltPortDescription( |
| 58 | UNNAMED, true, CltSignalType.CLT_100GBE, SA); |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 59 | |
| 60 | private final ConfigApplyDelegate delegate = new MockCfgDelegate(); |
| 61 | private final ObjectMapper mapper = new ObjectMapper(); |
| 62 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 63 | private static final ConnectPoint CP = new ConnectPoint(DID, UNNAMED); |
| 64 | |
| 65 | private static final OpticalPortConfig OPC = new OpticalPortConfig(); |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 66 | |
| 67 | @Before |
| 68 | public void setUp() { |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 69 | OPC.init(CP, CFG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate); |
Ayaka Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 70 | } |
| 71 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 72 | @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 Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 79 | // full desc + opc with name |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 80 | 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 Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 89 | } |
| 90 | |
HIGUCHI Yuta | cc10558d | 2016-06-03 14:27:05 -0700 | [diff] [blame^] | 91 | @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 Koshibe | e39c23a | 2015-08-03 18:17:43 -0700 | [diff] [blame] | 119 | private class MockCfgDelegate implements ConfigApplyDelegate { |
| 120 | |
| 121 | @Override |
| 122 | public void onApply(@SuppressWarnings("rawtypes") Config config) { |
| 123 | config.apply(); |
| 124 | } |
| 125 | |
| 126 | } |
| 127 | } |