blob: 7d26dcd0348e28d858961f6d5152518ba9df6570 [file] [log] [blame]
Naoki Shiota03c29e12016-05-16 16:58:07 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Naoki Shiota03c29e12016-05-16 16:58:07 -07003 *
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
Naoki Shiota7c3111b2016-06-09 16:12:11 -070019import com.google.common.collect.ImmutableSet;
Naoki Shiota03c29e12016-05-16 16:58:07 -070020import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
Andrey Komarov2398d962016-09-26 15:11:23 +030023import org.onlab.graph.Weight;
Naoki Shiota03c29e12016-05-16 16:58:07 -070024import org.onlab.util.Bandwidth;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.core.DefaultApplicationId;
27import org.onosproject.core.IdGenerator;
28import org.onosproject.net.CltSignalType;
29import org.onosproject.net.ConnectPoint;
30import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DefaultLink;
32import org.onosproject.net.DeviceId;
33import org.onosproject.net.Link;
34import org.onosproject.net.OduSignalType;
35import org.onosproject.net.Path;
36import org.onosproject.net.PortNumber;
37import org.onosproject.net.intent.Intent;
38import org.onosproject.net.intent.OpticalCircuitIntent;
39import org.onosproject.net.intent.OpticalConnectivityIntent;
40import org.onosproject.net.provider.ProviderId;
41import org.onosproject.newoptical.api.OpticalConnectivityId;
42
43import java.time.Duration;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070044import java.util.Collections;
Naoki Shiota03c29e12016-05-16 16:58:07 -070045import java.util.List;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070046import java.util.Set;
Naoki Shiota03c29e12016-05-16 16:58:07 -070047import java.util.stream.Collectors;
48import java.util.stream.Stream;
49
50import static org.junit.Assert.assertEquals;
51import static org.junit.Assert.assertFalse;
52import static org.junit.Assert.assertNotNull;
53import static org.junit.Assert.assertTrue;
54
55/**
56 * Test class for OpticalConnectivity.
57 */
58public class OpticalConnectivityTest {
59
60 private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest");
61 private ProviderId providerId = new ProviderId("of", "foo");
62 private IdGenerator idGenerator;
63
64 @Before
65 public void setUp() {
66 idGenerator = new IdGenerator() {
67 int counter = 1;
68
69 @Override
70 public long getNewId() {
71 return counter++;
72 }
73 };
74
Thomas Vachuska23235962017-02-03 11:44:15 -080075 Intent.unbindIdGenerator(idGenerator);
Naoki Shiota03c29e12016-05-16 16:58:07 -070076 Intent.bindIdGenerator(idGenerator);
77 }
78
79 @After
80 public void tearDown() {
81 Intent.unbindIdGenerator(idGenerator);
82 }
83
84 /**
85 * Checks the construction of OpticalConnectivity object.
86 */
87 @Test
88 public void testCreate() {
89 Bandwidth bandwidth = Bandwidth.bps(100);
90 Duration latency = Duration.ofMillis(10);
91
92 // Mock 3-nodes linear topology
93 ConnectPoint cp12 = createConnectPoint(1, 2);
94 ConnectPoint cp21 = createConnectPoint(2, 1);
95 ConnectPoint cp22 = createConnectPoint(2, 2);
96 ConnectPoint cp31 = createConnectPoint(3, 1);
97
98 Link link1 = createLink(cp12, cp21);
99 Link link2 = createLink(cp22, cp31);
100 List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
101
Naoki Shiota03c29e12016-05-16 16:58:07 -0700102 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700103 OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency,
104 Collections.emptySet(), Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700105
106 assertNotNull(oc);
107 assertEquals(oc.id(), cid);
108 assertEquals(oc.links(), links);
109 assertEquals(oc.bandwidth(), bandwidth);
110 assertEquals(oc.latency(), latency);
111 }
112
113 /**
114 * Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
115 */
116 @Test
117 public void testLinkEstablishedByConnectivityIntent() {
118 // Mock 7-nodes linear topology
119 ConnectPoint cp12 = createConnectPoint(1, 2);
120 ConnectPoint cp21 = createConnectPoint(2, 1);
121 ConnectPoint cp22 = createConnectPoint(2, 2);
122 ConnectPoint cp31 = createConnectPoint(3, 1);
123 ConnectPoint cp32 = createConnectPoint(3, 2);
124 ConnectPoint cp41 = createConnectPoint(4, 1);
125 ConnectPoint cp42 = createConnectPoint(4, 2);
126 ConnectPoint cp51 = createConnectPoint(5, 1);
127 ConnectPoint cp52 = createConnectPoint(5, 2);
128 ConnectPoint cp61 = createConnectPoint(6, 1);
129 ConnectPoint cp62 = createConnectPoint(6, 2);
130 ConnectPoint cp71 = createConnectPoint(7, 1);
131
132 Link link1 = createLink(cp12, cp21);
133 Link link2 = createLink(cp22, cp31);
134 Link link3 = createLink(cp32, cp41);
135 Link link4 = createLink(cp42, cp51);
136 Link link5 = createLink(cp52, cp61);
137 Link link6 = createLink(cp62, cp71);
138 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
139
Naoki Shiota03c29e12016-05-16 16:58:07 -0700140 // Mocks 2 intents to create OduCtl connectivity
141 OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
142 PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
143 connIntent1);
144
145 OpticalConnectivityIntent connIntent2 = createConnectivityIntent(cp51, cp62);
146 PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
147 connIntent2);
148
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700149 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
150
Naoki Shiota03c29e12016-05-16 16:58:07 -0700151 Bandwidth bandwidth = Bandwidth.bps(100);
152 Duration latency = Duration.ofMillis(10);
153
154 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700155 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
156 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700157
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700158 assertTrue(oc1.isAllRealizingLinkNotEstablished());
159 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700160
161 // Sets link realized by connIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700162 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700163
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700164 assertFalse(oc2.isAllRealizingLinkNotEstablished());
165 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700166
167 // Sets link realized by connIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700168 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700169
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700170 assertFalse(oc3.isAllRealizingLinkNotEstablished());
171 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700172 }
173
174 /**
175 * Checks that isAllRealizingLink(Not)Established works for OpticalCircuitIntent.
176 */
177 @Test
178 public void testLinkEstablishedByCircuitIntent() {
179 // Mock 7-nodes linear topology
180 ConnectPoint cp12 = createConnectPoint(1, 2);
181 ConnectPoint cp21 = createConnectPoint(2, 1);
182 ConnectPoint cp22 = createConnectPoint(2, 2);
183 ConnectPoint cp31 = createConnectPoint(3, 1);
184 ConnectPoint cp32 = createConnectPoint(3, 2);
185 ConnectPoint cp41 = createConnectPoint(4, 1);
186 ConnectPoint cp42 = createConnectPoint(4, 2);
187 ConnectPoint cp51 = createConnectPoint(5, 1);
188 ConnectPoint cp52 = createConnectPoint(5, 2);
189 ConnectPoint cp61 = createConnectPoint(6, 1);
190 ConnectPoint cp62 = createConnectPoint(6, 2);
191 ConnectPoint cp71 = createConnectPoint(7, 1);
192
193 Link link1 = createLink(cp12, cp21);
194 Link link2 = createLink(cp22, cp31);
195 Link link3 = createLink(cp32, cp41);
196 Link link4 = createLink(cp42, cp51);
197 Link link5 = createLink(cp52, cp61);
198 Link link6 = createLink(cp62, cp71);
199 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
200
Naoki Shiota03c29e12016-05-16 16:58:07 -0700201 // 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
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700210 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2);
211
Naoki Shiota03c29e12016-05-16 16:58:07 -0700212 Bandwidth bandwidth = Bandwidth.bps(100);
213 Duration latency = Duration.ofMillis(10);
214
215 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700216 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
217 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700218
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700219 assertTrue(oc1.isAllRealizingLinkNotEstablished());
220 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700221
222 // Sets link realized by circuitIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700223 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700224
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700225 assertFalse(oc2.isAllRealizingLinkNotEstablished());
226 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700227
228 // Sets link realized by circuitIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700229 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700230
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700231 assertFalse(oc3.isAllRealizingLinkNotEstablished());
232 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700233 }
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 }
Andrey Komarov2398d962016-09-26 15:11:23 +0300292
293 @Override
294 public Weight weight() {
295 return null;
296 }
Naoki Shiota03c29e12016-05-16 16:58:07 -0700297 }
298}