blob: c8c68f455e88a4d190f59c75f26b0953a798ea0f [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.device;
17
18import static org.hamcrest.Matchers.*;
19import static org.junit.Assert.*;
20
21import java.util.Optional;
22
23import org.junit.Test;
24import org.onlab.packet.ChassisId;
25import org.onlab.util.Frequency;
26import org.onosproject.net.Annotations;
27import org.onosproject.net.DefaultAnnotations;
28import org.onosproject.net.DefaultDevice;
29import org.onosproject.net.DefaultPort;
30import org.onosproject.net.Device;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.Port;
33import org.onosproject.net.PortNumber;
34import org.onosproject.net.SparseAnnotations;
35import org.onosproject.net.device.PortDescription;
36import org.onosproject.net.optical.OmsPort;
37import org.onosproject.net.Device.Type;
38import org.onosproject.net.provider.ProviderId;
39
40/**
41 * Tests for {@link OmsPortHelper}.
42 */
43public 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));
94 assertThat("(33-3)/2 = 15", oms.totalChannels(), is((short) 15));
95 }
96
97}