blob: a09d5ec318d21d192b26eafaf150a91d180ca021 [file] [log] [blame]
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001/*
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 */
16package org.onosproject.net.optical.impl;
17
18import static org.hamcrest.Matchers.*;
19import static org.junit.Assert.*;
20import static org.onosproject.net.PortNumber.portNumber;
21
22import org.junit.Test;
23import org.onlab.packet.ChassisId;
24import org.onlab.util.Frequency;
25import org.onosproject.net.Annotations;
26import org.onosproject.net.DefaultAnnotations;
27import org.onosproject.net.DefaultDevice;
28import org.onosproject.net.DefaultPort;
29import org.onosproject.net.Device;
30import org.onosproject.net.Device.Type;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.Port;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.optical.OmsPort;
35import org.onosproject.net.provider.ProviderId;
36
37import com.google.common.testing.EqualsTester;
38
39/**
40 * Tests for {@link DefaultOmsPort}.
41 */
42public 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 Yan4deb03b2016-06-24 10:53:54 -0700118 assertThat("((33-3)/2)+1 = 16", oms.totalChannels(), is((short) 16));
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -0700119 }
120
121}