HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
| 16 | package org.onosproject.net.optical.impl; |
| 17 | |
| 18 | import static org.hamcrest.Matchers.*; |
| 19 | import static org.junit.Assert.*; |
| 20 | import static org.onosproject.net.PortNumber.portNumber; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.ChassisId; |
| 24 | import org.onlab.util.Frequency; |
| 25 | import org.onosproject.net.Annotations; |
| 26 | import org.onosproject.net.DefaultAnnotations; |
| 27 | import org.onosproject.net.DefaultDevice; |
| 28 | import org.onosproject.net.DefaultPort; |
| 29 | import org.onosproject.net.Device; |
| 30 | import org.onosproject.net.Device.Type; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Port; |
| 33 | import org.onosproject.net.PortNumber; |
| 34 | import org.onosproject.net.optical.OmsPort; |
| 35 | import org.onosproject.net.provider.ProviderId; |
| 36 | |
| 37 | import com.google.common.testing.EqualsTester; |
| 38 | |
| 39 | /** |
| 40 | * Tests for {@link DefaultOmsPort}. |
| 41 | */ |
| 42 | public class DefaultOmsPortTest { |
| 43 | |
| 44 | private static final ProviderId PID = new ProviderId("test", "id"); |
| 45 | private static final DeviceId DID = DeviceId.deviceId("test:00123"); |
| 46 | private static final String MFC = "MFC"; |
| 47 | private static final String HW = "HW V"; |
| 48 | private static final String SW = "SW V"; |
| 49 | private static final String SER = "SER"; |
| 50 | private static final ChassisId CHS = new ChassisId(42); |
| 51 | private static final Annotations DEV_ANON = DefaultAnnotations.EMPTY; |
| 52 | private static final Device DEV = new DefaultDevice(PID, DID, Type.ROADM, MFC, HW, SW, SER, CHS, DEV_ANON); |
| 53 | |
| 54 | @Test |
| 55 | public void testEquality() { |
| 56 | PortNumber pn = PortNumber.portNumber(4900); |
| 57 | Annotations an = DefaultAnnotations.builder() |
| 58 | .set("Base", "value") |
| 59 | .build(); |
| 60 | Annotations an2 = DefaultAnnotations.builder() |
| 61 | .set("Base", "value2") |
| 62 | .build(); |
| 63 | |
| 64 | Port base = new DefaultPort(DEV, pn, true, Port.Type.VIRTUAL, 2, an); |
| 65 | Frequency minF = Frequency.ofGHz(3); |
| 66 | Frequency maxF = Frequency.ofGHz(33); |
| 67 | Frequency grid = Frequency.ofGHz(2); |
| 68 | |
| 69 | // reference OMS port |
| 70 | OmsPort oms = new DefaultOmsPort(base, minF, maxF, grid); |
| 71 | |
| 72 | new EqualsTester() |
| 73 | .addEqualityGroup(oms, |
| 74 | // different base port type or portspeed is ignored |
| 75 | new DefaultOmsPort(new DefaultPort(DEV, pn, true, an), minF, maxF, grid)) |
| 76 | // different port number |
| 77 | .addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, portNumber(1), true, an), minF, maxF, grid)) |
| 78 | // different isEnabled |
| 79 | .addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, pn, false, an), minF, maxF, grid)) |
| 80 | // different annotation |
| 81 | .addEqualityGroup(new DefaultOmsPort(new DefaultPort(DEV, pn, true, an2), minF, maxF, grid)) |
| 82 | // different minFreq |
| 83 | .addEqualityGroup(new DefaultOmsPort(base, Frequency.ofKHz(3), maxF, grid)) |
| 84 | // different maxFreq |
| 85 | .addEqualityGroup(new DefaultOmsPort(base, minF, Frequency.ofKHz(33), grid)) |
| 86 | // different grid |
| 87 | .addEqualityGroup(new DefaultOmsPort(base, minF, maxF, Frequency.ofKHz(2))) |
| 88 | .testEquals(); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | @Test |
| 93 | public void basicTests() { |
| 94 | PortNumber pn = PortNumber.portNumber(4900); |
| 95 | Annotations annotations = DefaultAnnotations.builder() |
| 96 | .set("Base", "value") |
| 97 | .build(); |
| 98 | |
| 99 | boolean isEnabled = true; |
| 100 | Port base = new DefaultPort(DEV, pn, isEnabled, Port.Type.VIRTUAL, 2, annotations); |
| 101 | Frequency minFrequency = Frequency.ofGHz(3); |
| 102 | Frequency maxFrequency = Frequency.ofGHz(33); |
| 103 | Frequency grid = Frequency.ofGHz(2); |
| 104 | OmsPort oms = new DefaultOmsPort(base, minFrequency, maxFrequency, grid); |
| 105 | |
| 106 | // basic attributes and annotations are inherited from base |
| 107 | assertThat(oms.element(), is(DEV)); |
| 108 | assertThat(oms.isEnabled(), is(isEnabled)); |
| 109 | assertThat(oms.number(), is(pn)); |
| 110 | assertThat(oms.annotations(), is(annotations)); |
| 111 | |
| 112 | assertThat("type is always OMS", oms.type(), is(Port.Type.OMS)); |
| 113 | assertThat("port speed is undefined", oms.portSpeed(), is(equalTo(0L))); |
| 114 | |
| 115 | assertThat(oms.maxFrequency(), is(maxFrequency)); |
| 116 | assertThat(oms.minFrequency(), is(minFrequency)); |
| 117 | assertThat(oms.grid(), is(grid)); |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 118 | assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16)); |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | } |