HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -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.optical.device; |
| 17 | |
| 18 | import static org.hamcrest.Matchers.*; |
| 19 | import static org.junit.Assert.*; |
| 20 | |
| 21 | import java.util.Optional; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | import org.onlab.packet.ChassisId; |
| 25 | import org.onlab.util.Frequency; |
| 26 | import org.onosproject.net.Annotations; |
| 27 | import org.onosproject.net.DefaultAnnotations; |
| 28 | import org.onosproject.net.DefaultDevice; |
| 29 | import org.onosproject.net.DefaultPort; |
| 30 | import org.onosproject.net.Device; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Port; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.SparseAnnotations; |
| 35 | import org.onosproject.net.device.PortDescription; |
| 36 | import org.onosproject.net.optical.OmsPort; |
| 37 | import org.onosproject.net.Device.Type; |
| 38 | import org.onosproject.net.provider.ProviderId; |
| 39 | |
| 40 | /** |
| 41 | * Tests for {@link OmsPortHelper}. |
| 42 | */ |
| 43 | public class OmsPortHelperTest { |
| 44 | |
| 45 | private static final ProviderId PID = new ProviderId("test", "id"); |
| 46 | private static final DeviceId DID = DeviceId.deviceId("test:00123"); |
| 47 | private static final String MFC = "MFC"; |
| 48 | private static final String HW = "HW V"; |
| 49 | private static final String SW = "SW V"; |
| 50 | private static final String SER = "SER"; |
| 51 | private static final ChassisId CHS = new ChassisId(42); |
| 52 | private static final Annotations DEV_ANON = DefaultAnnotations.EMPTY; |
| 53 | private static final Device DEV = new DefaultDevice(PID, DID, Type.ROADM, MFC, HW, SW, SER, CHS, DEV_ANON); |
| 54 | |
| 55 | |
| 56 | @Test |
| 57 | public void testOmsPortDescriptionCanBeConvertedToOmsPort() { |
| 58 | PortNumber pn = PortNumber.portNumber(4900); |
| 59 | |
| 60 | boolean isEnabled = true; |
| 61 | String anKey = "Base"; |
| 62 | String anValue = "value"; |
| 63 | SparseAnnotations an = DefaultAnnotations.builder() |
| 64 | .set(anKey, anValue) |
| 65 | .build(); |
| 66 | |
| 67 | Frequency minF = Frequency.ofGHz(3); |
| 68 | Frequency maxF = Frequency.ofGHz(33); |
| 69 | Frequency grid = Frequency.ofGHz(2); |
| 70 | |
| 71 | PortDescription portDescription = OmsPortHelper.omsPortDescription(pn, isEnabled, minF, maxF, grid, an); |
| 72 | Port port = new DefaultPort(DEV, |
| 73 | portDescription.portNumber(), |
| 74 | portDescription.isEnabled(), |
| 75 | portDescription.type(), |
| 76 | portDescription.portSpeed(), |
| 77 | portDescription.annotations()); |
| 78 | |
| 79 | Optional<OmsPort> maybeOms = OmsPortHelper.asOmsPort(port); |
| 80 | assertTrue(maybeOms.isPresent()); |
| 81 | |
| 82 | OmsPort oms = maybeOms.get(); |
| 83 | |
| 84 | assertThat(oms.isEnabled(), is(isEnabled)); |
| 85 | assertThat(oms.number(), is(pn)); |
| 86 | assertThat(oms.annotations().value(anKey), is(anValue)); |
| 87 | |
| 88 | assertThat("type is always OMS", oms.type(), is(Port.Type.OMS)); |
| 89 | assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L))); |
| 90 | |
| 91 | assertThat(oms.maxFrequency(), is(maxF)); |
| 92 | assertThat(oms.minFrequency(), is(minF)); |
| 93 | assertThat(oms.grid(), is(grid)); |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 94 | assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16)); |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } |