blob: e2570edc516df4119e8bea7cc8c407b541300dc0 [file] [log] [blame]
Naoki Shiota03c29e12016-05-16 16:58:07 -07001/*
2 * Copyright 2016 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
17package org.onosproject.newoptical;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.util.Bandwidth;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.core.DefaultApplicationId;
25import org.onosproject.core.IdGenerator;
26import org.onosproject.net.CltSignalType;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.OduSignalType;
30import org.onosproject.net.PortNumber;
31import org.onosproject.net.intent.Intent;
32import org.onosproject.net.intent.Key;
33import org.onosproject.net.intent.OpticalCircuitIntent;
34import org.onosproject.net.intent.OpticalConnectivityIntent;
35
36import static org.junit.Assert.*;
37
38/**
39 * Test class for PacketLinkRealizedByOptical class.
40 */
41public class PacketLinkRealizedByOpticalTest {
42
43 private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest");
44 private IdGenerator idGenerator;
45
46 @Before
47 public void setUp() {
48 idGenerator = new IdGenerator() {
49 int counter = 1;
50
51 @Override
52 public long getNewId() {
53 return counter++;
54 }
55 };
56
57 Intent.bindIdGenerator(idGenerator);
58 }
59
60 @After
61 public void tearDown() {
62 Intent.unbindIdGenerator(idGenerator);
63 }
64
65 /**
66 * Checks the construction of PacketLinkRealizedByOptical object with all parameters specified.
67 */
68 @Test
69 public void testCreate() {
70 ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
71 ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
72 Key key = Key.of(10L, appId);
73 Bandwidth bandwidth = Bandwidth.bps(100L);
74
75 PacketLinkRealizedByOptical plink = new PacketLinkRealizedByOptical(cp1, cp2, key, bandwidth);
76
77 assertNotNull(plink);
78 assertEquals(plink.src(), cp1);
79 assertEquals(plink.dst(), cp2);
80 assertEquals((long) plink.bandwidth().bps(), 100L);
81 }
82
83 /**
84 * Checks the construction of OpticalConnectivityId object with OpticalCircuitIntent.
85 */
86 @Test
87 public void testCreateWithCircuitIntent() {
88 ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
89 ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
90 OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder()
91 .appId(appId)
92 .src(cp1)
93 .dst(cp2)
94 .bidirectional(true)
95 .key(Key.of(0, appId))
96 .signalType(CltSignalType.CLT_1GBE)
97 .build();
98
99 PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, circuitIntent);
100
101 assertNotNull(plink);
102 assertEquals(plink.src(), cp1);
103 assertEquals(plink.dst(), cp2);
104 assertEquals((long) plink.bandwidth().bps(), CltSignalType.CLT_1GBE.bitRate());
105 }
106
107 /**
108 * Checks the construction of OpticalConnectivityId object with OpticalConnectivityIntent.
109 */
110 @Test
111 public void testCreateWithConnectivityIntent() {
112 ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
113 ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
114 OpticalConnectivityIntent connIntent = OpticalConnectivityIntent.builder()
115 .appId(appId)
116 .src(cp1)
117 .dst(cp2)
118 .bidirectional(true)
119 .key(Key.of(0, appId))
120 .signalType(OduSignalType.ODU4)
121 .build();
122
123 PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, connIntent);
124
125 assertNotNull(plink);
126 assertEquals(plink.src(), cp1);
127 assertEquals(plink.dst(), cp2);
128 assertEquals((long) plink.bandwidth().bps(), OduSignalType.ODU4.bitRate());
129 }
130
131 /**
132 * Checks that isBetween() method works.
133 */
134 @Test
135 public void testIsBetween() {
136 ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
137 ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
138 ConnectPoint cp3 = new ConnectPoint(DeviceId.deviceId("of:0000000000000003"), PortNumber.portNumber(3L));
139 OpticalCircuitIntent ochIntent = OpticalCircuitIntent.builder()
140 .appId(appId)
141 .src(cp1)
142 .dst(cp2)
143 .bidirectional(true)
144 .key(Key.of(0, appId))
145 .signalType(CltSignalType.CLT_1GBE)
146 .build();
147
148 PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, ochIntent);
149
150 assertTrue(plink.isBetween(cp1, cp2));
151 assertFalse(plink.isBetween(cp1, cp3));
152 }
153}