blob: 8d0bc8712f4aa956a87183db36949b832d0e2278 [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.DefaultAnnotations;
29import org.onosproject.net.DefaultLink;
30import org.onosproject.net.DeviceId;
31import org.onosproject.net.Link;
32import org.onosproject.net.OduSignalType;
33import org.onosproject.net.Path;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.intent.Intent;
36import org.onosproject.net.intent.OpticalCircuitIntent;
37import org.onosproject.net.intent.OpticalConnectivityIntent;
38import org.onosproject.net.provider.ProviderId;
39import org.onosproject.newoptical.api.OpticalConnectivityId;
40
41import java.time.Duration;
42import java.util.List;
43import java.util.stream.Collectors;
44import java.util.stream.Stream;
45
46import static org.junit.Assert.assertEquals;
47import static org.junit.Assert.assertFalse;
48import static org.junit.Assert.assertNotNull;
49import static org.junit.Assert.assertTrue;
50
51/**
52 * Test class for OpticalConnectivity.
53 */
54public class OpticalConnectivityTest {
55
56 private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest");
57 private ProviderId providerId = new ProviderId("of", "foo");
58 private IdGenerator idGenerator;
59
60 @Before
61 public void setUp() {
62 idGenerator = new IdGenerator() {
63 int counter = 1;
64
65 @Override
66 public long getNewId() {
67 return counter++;
68 }
69 };
70
71 Intent.bindIdGenerator(idGenerator);
72 }
73
74 @After
75 public void tearDown() {
76 Intent.unbindIdGenerator(idGenerator);
77 }
78
79 /**
80 * Checks the construction of OpticalConnectivity object.
81 */
82 @Test
83 public void testCreate() {
84 Bandwidth bandwidth = Bandwidth.bps(100);
85 Duration latency = Duration.ofMillis(10);
86
87 // Mock 3-nodes linear topology
88 ConnectPoint cp12 = createConnectPoint(1, 2);
89 ConnectPoint cp21 = createConnectPoint(2, 1);
90 ConnectPoint cp22 = createConnectPoint(2, 2);
91 ConnectPoint cp31 = createConnectPoint(3, 1);
92
93 Link link1 = createLink(cp12, cp21);
94 Link link2 = createLink(cp22, cp31);
95 List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
96
97 Path path = new MockPath(cp12, cp31, links);
98
99 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
100 OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
101
102 assertNotNull(oc);
103 assertEquals(oc.id(), cid);
104 assertEquals(oc.links(), links);
105 assertEquals(oc.bandwidth(), bandwidth);
106 assertEquals(oc.latency(), latency);
107 }
108
109 /**
110 * Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
111 */
112 @Test
113 public void testLinkEstablishedByConnectivityIntent() {
114 // Mock 7-nodes linear topology
115 ConnectPoint cp12 = createConnectPoint(1, 2);
116 ConnectPoint cp21 = createConnectPoint(2, 1);
117 ConnectPoint cp22 = createConnectPoint(2, 2);
118 ConnectPoint cp31 = createConnectPoint(3, 1);
119 ConnectPoint cp32 = createConnectPoint(3, 2);
120 ConnectPoint cp41 = createConnectPoint(4, 1);
121 ConnectPoint cp42 = createConnectPoint(4, 2);
122 ConnectPoint cp51 = createConnectPoint(5, 1);
123 ConnectPoint cp52 = createConnectPoint(5, 2);
124 ConnectPoint cp61 = createConnectPoint(6, 1);
125 ConnectPoint cp62 = createConnectPoint(6, 2);
126 ConnectPoint cp71 = createConnectPoint(7, 1);
127
128 Link link1 = createLink(cp12, cp21);
129 Link link2 = createLink(cp22, cp31);
130 Link link3 = createLink(cp32, cp41);
131 Link link4 = createLink(cp42, cp51);
132 Link link5 = createLink(cp52, cp61);
133 Link link6 = createLink(cp62, cp71);
134 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
135
136 Path path = new MockPath(cp12, cp71, links);
137
138 // Mocks 2 intents to create OduCtl connectivity
139 OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
140 PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
141 connIntent1);
142
143 OpticalConnectivityIntent connIntent2 = createConnectivityIntent(cp51, cp62);
144 PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
145 connIntent2);
146
147 Bandwidth bandwidth = Bandwidth.bps(100);
148 Duration latency = Duration.ofMillis(10);
149
150 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
151 OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
152
153 oc.addRealizingLink(oduLink1);
154 oc.addRealizingLink(oduLink2);
155
156 assertTrue(oc.isAllRealizingLinkNotEstablished());
157 assertFalse(oc.isAllRealizingLinkEstablished());
158
159 // Sets link realized by connIntent1 to be established
160 oc.setLinkEstablished(cp12, cp41);
161
162 assertFalse(oc.isAllRealizingLinkNotEstablished());
163 assertFalse(oc.isAllRealizingLinkEstablished());
164
165 // Sets link realized by connIntent2 to be established
166 oc.setLinkEstablished(cp42, cp71);
167
168 assertFalse(oc.isAllRealizingLinkNotEstablished());
169 assertTrue(oc.isAllRealizingLinkEstablished());
170 }
171
172 /**
173 * Checks that isAllRealizingLink(Not)Established works for OpticalCircuitIntent.
174 */
175 @Test
176 public void testLinkEstablishedByCircuitIntent() {
177 // Mock 7-nodes linear topology
178 ConnectPoint cp12 = createConnectPoint(1, 2);
179 ConnectPoint cp21 = createConnectPoint(2, 1);
180 ConnectPoint cp22 = createConnectPoint(2, 2);
181 ConnectPoint cp31 = createConnectPoint(3, 1);
182 ConnectPoint cp32 = createConnectPoint(3, 2);
183 ConnectPoint cp41 = createConnectPoint(4, 1);
184 ConnectPoint cp42 = createConnectPoint(4, 2);
185 ConnectPoint cp51 = createConnectPoint(5, 1);
186 ConnectPoint cp52 = createConnectPoint(5, 2);
187 ConnectPoint cp61 = createConnectPoint(6, 1);
188 ConnectPoint cp62 = createConnectPoint(6, 2);
189 ConnectPoint cp71 = createConnectPoint(7, 1);
190
191 Link link1 = createLink(cp12, cp21);
192 Link link2 = createLink(cp22, cp31);
193 Link link3 = createLink(cp32, cp41);
194 Link link4 = createLink(cp42, cp51);
195 Link link5 = createLink(cp52, cp61);
196 Link link6 = createLink(cp62, cp71);
197 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
198
199 Path path = new MockPath(cp12, cp71, links);
200
201 // Mocks 2 intents to create Och connectivity
202 OpticalCircuitIntent circuitIntent1 = createCircuitIntent(cp21, cp32);
203 PacketLinkRealizedByOptical ochLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
204 circuitIntent1);
205
206 OpticalCircuitIntent circuitIntent2 = createCircuitIntent(cp51, cp62);
207 PacketLinkRealizedByOptical ochLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
208 circuitIntent2);
209
210 Bandwidth bandwidth = Bandwidth.bps(100);
211 Duration latency = Duration.ofMillis(10);
212
213 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
214 OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
215
216 oc.addRealizingLink(ochLink1);
217 oc.addRealizingLink(ochLink2);
218
219 assertTrue(oc.isAllRealizingLinkNotEstablished());
220 assertFalse(oc.isAllRealizingLinkEstablished());
221
222 // Sets link realized by circuitIntent1 to be established
223 oc.setLinkEstablished(cp12, cp41);
224
225 assertFalse(oc.isAllRealizingLinkNotEstablished());
226 assertFalse(oc.isAllRealizingLinkEstablished());
227
228 // Sets link realized by circuitIntent2 to be established
229 oc.setLinkEstablished(cp42, cp71);
230
231 assertFalse(oc.isAllRealizingLinkNotEstablished());
232 assertTrue(oc.isAllRealizingLinkEstablished());
233 }
234
235 private ConnectPoint createConnectPoint(long devIdNum, long portIdNum) {
236 return new ConnectPoint(
237 DeviceId.deviceId(String.format("of:%016d", devIdNum)),
238 PortNumber.portNumber(portIdNum));
239 }
240
241 private Link createLink(ConnectPoint src, ConnectPoint dst) {
242 return DefaultLink.builder()
243 .providerId(providerId)
244 .src(src)
245 .dst(dst)
246 .type(Link.Type.DIRECT)
247 .annotations(DefaultAnnotations.EMPTY)
248 .build();
249 }
250
251 private OpticalCircuitIntent createCircuitIntent(ConnectPoint src, ConnectPoint dst) {
252 OpticalCircuitIntent intent = OpticalCircuitIntent.builder()
253 .appId(appId)
254 .bidirectional(true)
255 .src(src)
256 .dst(dst)
257 .signalType(CltSignalType.CLT_100GBE)
258 .build();
259
260 return intent;
261 }
262
263 private OpticalConnectivityIntent createConnectivityIntent(ConnectPoint src, ConnectPoint dst) {
264 OpticalConnectivityIntent intent = OpticalConnectivityIntent.builder()
265 .appId(appId)
266 .bidirectional(true)
267 .src(src)
268 .dst(dst)
269 .signalType(OduSignalType.ODU4)
270 .build();
271
272 return intent;
273 }
274
275 private class MockPath extends DefaultLink implements Path {
276 List<Link> links;
277
278 protected MockPath(ConnectPoint src, ConnectPoint dst, List<Link> links) {
279 super(providerId, src, dst, Type.INDIRECT, State.ACTIVE);
280 this.links = links;
281 }
282
283 @Override
284 public List<Link> links() {
285 return links;
286 }
287
288 @Override
289 public double cost() {
290 return 0;
291 }
292 }
293}