blob: 4f122e176a3bce3f46d23ce0b077a22b3f6805c3 [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
75 Intent.bindIdGenerator(idGenerator);
76 }
77
78 @After
79 public void tearDown() {
80 Intent.unbindIdGenerator(idGenerator);
81 }
82
83 /**
84 * Checks the construction of OpticalConnectivity object.
85 */
86 @Test
87 public void testCreate() {
88 Bandwidth bandwidth = Bandwidth.bps(100);
89 Duration latency = Duration.ofMillis(10);
90
91 // Mock 3-nodes linear topology
92 ConnectPoint cp12 = createConnectPoint(1, 2);
93 ConnectPoint cp21 = createConnectPoint(2, 1);
94 ConnectPoint cp22 = createConnectPoint(2, 2);
95 ConnectPoint cp31 = createConnectPoint(3, 1);
96
97 Link link1 = createLink(cp12, cp21);
98 Link link2 = createLink(cp22, cp31);
99 List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
100
Naoki Shiota03c29e12016-05-16 16:58:07 -0700101 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700102 OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency,
103 Collections.emptySet(), Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700104
105 assertNotNull(oc);
106 assertEquals(oc.id(), cid);
107 assertEquals(oc.links(), links);
108 assertEquals(oc.bandwidth(), bandwidth);
109 assertEquals(oc.latency(), latency);
110 }
111
112 /**
113 * Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
114 */
115 @Test
116 public void testLinkEstablishedByConnectivityIntent() {
117 // Mock 7-nodes linear topology
118 ConnectPoint cp12 = createConnectPoint(1, 2);
119 ConnectPoint cp21 = createConnectPoint(2, 1);
120 ConnectPoint cp22 = createConnectPoint(2, 2);
121 ConnectPoint cp31 = createConnectPoint(3, 1);
122 ConnectPoint cp32 = createConnectPoint(3, 2);
123 ConnectPoint cp41 = createConnectPoint(4, 1);
124 ConnectPoint cp42 = createConnectPoint(4, 2);
125 ConnectPoint cp51 = createConnectPoint(5, 1);
126 ConnectPoint cp52 = createConnectPoint(5, 2);
127 ConnectPoint cp61 = createConnectPoint(6, 1);
128 ConnectPoint cp62 = createConnectPoint(6, 2);
129 ConnectPoint cp71 = createConnectPoint(7, 1);
130
131 Link link1 = createLink(cp12, cp21);
132 Link link2 = createLink(cp22, cp31);
133 Link link3 = createLink(cp32, cp41);
134 Link link4 = createLink(cp42, cp51);
135 Link link5 = createLink(cp52, cp61);
136 Link link6 = createLink(cp62, cp71);
137 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
138
Naoki Shiota03c29e12016-05-16 16:58:07 -0700139 // Mocks 2 intents to create OduCtl connectivity
140 OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
141 PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
142 connIntent1);
143
144 OpticalConnectivityIntent connIntent2 = createConnectivityIntent(cp51, cp62);
145 PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
146 connIntent2);
147
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700148 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
149
Naoki Shiota03c29e12016-05-16 16:58:07 -0700150 Bandwidth bandwidth = Bandwidth.bps(100);
151 Duration latency = Duration.ofMillis(10);
152
153 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700154 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
155 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700156
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700157 assertTrue(oc1.isAllRealizingLinkNotEstablished());
158 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700159
160 // Sets link realized by connIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700161 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700162
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700163 assertFalse(oc2.isAllRealizingLinkNotEstablished());
164 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700165
166 // Sets link realized by connIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700167 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700168
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700169 assertFalse(oc3.isAllRealizingLinkNotEstablished());
170 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700171 }
172
173 /**
174 * Checks that isAllRealizingLink(Not)Established works for OpticalCircuitIntent.
175 */
176 @Test
177 public void testLinkEstablishedByCircuitIntent() {
178 // Mock 7-nodes linear topology
179 ConnectPoint cp12 = createConnectPoint(1, 2);
180 ConnectPoint cp21 = createConnectPoint(2, 1);
181 ConnectPoint cp22 = createConnectPoint(2, 2);
182 ConnectPoint cp31 = createConnectPoint(3, 1);
183 ConnectPoint cp32 = createConnectPoint(3, 2);
184 ConnectPoint cp41 = createConnectPoint(4, 1);
185 ConnectPoint cp42 = createConnectPoint(4, 2);
186 ConnectPoint cp51 = createConnectPoint(5, 1);
187 ConnectPoint cp52 = createConnectPoint(5, 2);
188 ConnectPoint cp61 = createConnectPoint(6, 1);
189 ConnectPoint cp62 = createConnectPoint(6, 2);
190 ConnectPoint cp71 = createConnectPoint(7, 1);
191
192 Link link1 = createLink(cp12, cp21);
193 Link link2 = createLink(cp22, cp31);
194 Link link3 = createLink(cp32, cp41);
195 Link link4 = createLink(cp42, cp51);
196 Link link5 = createLink(cp52, cp61);
197 Link link6 = createLink(cp62, cp71);
198 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
199
Naoki Shiota03c29e12016-05-16 16:58:07 -0700200 // Mocks 2 intents to create Och connectivity
201 OpticalCircuitIntent circuitIntent1 = createCircuitIntent(cp21, cp32);
202 PacketLinkRealizedByOptical ochLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
203 circuitIntent1);
204
205 OpticalCircuitIntent circuitIntent2 = createCircuitIntent(cp51, cp62);
206 PacketLinkRealizedByOptical ochLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
207 circuitIntent2);
208
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700209 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2);
210
Naoki Shiota03c29e12016-05-16 16:58:07 -0700211 Bandwidth bandwidth = Bandwidth.bps(100);
212 Duration latency = Duration.ofMillis(10);
213
214 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700215 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
216 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700217
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700218 assertTrue(oc1.isAllRealizingLinkNotEstablished());
219 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700220
221 // Sets link realized by circuitIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700222 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700223
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700224 assertFalse(oc2.isAllRealizingLinkNotEstablished());
225 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700226
227 // Sets link realized by circuitIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700228 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700229
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700230 assertFalse(oc3.isAllRealizingLinkNotEstablished());
231 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700232 }
233
234 private ConnectPoint createConnectPoint(long devIdNum, long portIdNum) {
235 return new ConnectPoint(
236 DeviceId.deviceId(String.format("of:%016d", devIdNum)),
237 PortNumber.portNumber(portIdNum));
238 }
239
240 private Link createLink(ConnectPoint src, ConnectPoint dst) {
241 return DefaultLink.builder()
242 .providerId(providerId)
243 .src(src)
244 .dst(dst)
245 .type(Link.Type.DIRECT)
246 .annotations(DefaultAnnotations.EMPTY)
247 .build();
248 }
249
250 private OpticalCircuitIntent createCircuitIntent(ConnectPoint src, ConnectPoint dst) {
251 OpticalCircuitIntent intent = OpticalCircuitIntent.builder()
252 .appId(appId)
253 .bidirectional(true)
254 .src(src)
255 .dst(dst)
256 .signalType(CltSignalType.CLT_100GBE)
257 .build();
258
259 return intent;
260 }
261
262 private OpticalConnectivityIntent createConnectivityIntent(ConnectPoint src, ConnectPoint dst) {
263 OpticalConnectivityIntent intent = OpticalConnectivityIntent.builder()
264 .appId(appId)
265 .bidirectional(true)
266 .src(src)
267 .dst(dst)
268 .signalType(OduSignalType.ODU4)
269 .build();
270
271 return intent;
272 }
273
274 private class MockPath extends DefaultLink implements Path {
275 List<Link> links;
276
277 protected MockPath(ConnectPoint src, ConnectPoint dst, List<Link> links) {
278 super(providerId, src, dst, Type.INDIRECT, State.ACTIVE);
279 this.links = links;
280 }
281
282 @Override
283 public List<Link> links() {
284 return links;
285 }
286
287 @Override
288 public double cost() {
289 return 0;
290 }
Andrey Komarov2398d962016-09-26 15:11:23 +0300291
292 @Override
293 public Weight weight() {
294 return null;
295 }
Naoki Shiota03c29e12016-05-16 16:58:07 -0700296 }
297}