blob: 7535f7c4527503ba38431614c4dba3ab57bb1628 [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
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;
23import org.onlab.util.Bandwidth;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.core.DefaultApplicationId;
26import org.onosproject.core.IdGenerator;
27import org.onosproject.net.CltSignalType;
28import org.onosproject.net.ConnectPoint;
29import org.onosproject.net.DefaultAnnotations;
30import org.onosproject.net.DefaultLink;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.Link;
33import org.onosproject.net.OduSignalType;
34import org.onosproject.net.Path;
35import org.onosproject.net.PortNumber;
36import org.onosproject.net.intent.Intent;
37import org.onosproject.net.intent.OpticalCircuitIntent;
38import org.onosproject.net.intent.OpticalConnectivityIntent;
39import org.onosproject.net.provider.ProviderId;
40import org.onosproject.newoptical.api.OpticalConnectivityId;
41
42import java.time.Duration;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070043import java.util.Collections;
Naoki Shiota03c29e12016-05-16 16:58:07 -070044import java.util.List;
Naoki Shiota7c3111b2016-06-09 16:12:11 -070045import java.util.Set;
Naoki Shiota03c29e12016-05-16 16:58:07 -070046import java.util.stream.Collectors;
47import java.util.stream.Stream;
48
49import static org.junit.Assert.assertEquals;
50import static org.junit.Assert.assertFalse;
51import static org.junit.Assert.assertNotNull;
52import static org.junit.Assert.assertTrue;
53
54/**
55 * Test class for OpticalConnectivity.
56 */
57public class OpticalConnectivityTest {
58
59 private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest");
60 private ProviderId providerId = new ProviderId("of", "foo");
61 private IdGenerator idGenerator;
62
63 @Before
64 public void setUp() {
65 idGenerator = new IdGenerator() {
66 int counter = 1;
67
68 @Override
69 public long getNewId() {
70 return counter++;
71 }
72 };
73
74 Intent.bindIdGenerator(idGenerator);
75 }
76
77 @After
78 public void tearDown() {
79 Intent.unbindIdGenerator(idGenerator);
80 }
81
82 /**
83 * Checks the construction of OpticalConnectivity object.
84 */
85 @Test
86 public void testCreate() {
87 Bandwidth bandwidth = Bandwidth.bps(100);
88 Duration latency = Duration.ofMillis(10);
89
90 // Mock 3-nodes linear topology
91 ConnectPoint cp12 = createConnectPoint(1, 2);
92 ConnectPoint cp21 = createConnectPoint(2, 1);
93 ConnectPoint cp22 = createConnectPoint(2, 2);
94 ConnectPoint cp31 = createConnectPoint(3, 1);
95
96 Link link1 = createLink(cp12, cp21);
97 Link link2 = createLink(cp22, cp31);
98 List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
99
Naoki Shiota03c29e12016-05-16 16:58:07 -0700100 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700101 OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency,
102 Collections.emptySet(), Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700103
104 assertNotNull(oc);
105 assertEquals(oc.id(), cid);
106 assertEquals(oc.links(), links);
107 assertEquals(oc.bandwidth(), bandwidth);
108 assertEquals(oc.latency(), latency);
109 }
110
111 /**
112 * Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
113 */
114 @Test
115 public void testLinkEstablishedByConnectivityIntent() {
116 // Mock 7-nodes linear topology
117 ConnectPoint cp12 = createConnectPoint(1, 2);
118 ConnectPoint cp21 = createConnectPoint(2, 1);
119 ConnectPoint cp22 = createConnectPoint(2, 2);
120 ConnectPoint cp31 = createConnectPoint(3, 1);
121 ConnectPoint cp32 = createConnectPoint(3, 2);
122 ConnectPoint cp41 = createConnectPoint(4, 1);
123 ConnectPoint cp42 = createConnectPoint(4, 2);
124 ConnectPoint cp51 = createConnectPoint(5, 1);
125 ConnectPoint cp52 = createConnectPoint(5, 2);
126 ConnectPoint cp61 = createConnectPoint(6, 1);
127 ConnectPoint cp62 = createConnectPoint(6, 2);
128 ConnectPoint cp71 = createConnectPoint(7, 1);
129
130 Link link1 = createLink(cp12, cp21);
131 Link link2 = createLink(cp22, cp31);
132 Link link3 = createLink(cp32, cp41);
133 Link link4 = createLink(cp42, cp51);
134 Link link5 = createLink(cp52, cp61);
135 Link link6 = createLink(cp62, cp71);
136 List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
137
Naoki Shiota03c29e12016-05-16 16:58:07 -0700138 // 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
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700147 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
148
Naoki Shiota03c29e12016-05-16 16:58:07 -0700149 Bandwidth bandwidth = Bandwidth.bps(100);
150 Duration latency = Duration.ofMillis(10);
151
152 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700153 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
154 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700155
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700156 assertTrue(oc1.isAllRealizingLinkNotEstablished());
157 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700158
159 // Sets link realized by connIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700160 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700161
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700162 assertFalse(oc2.isAllRealizingLinkNotEstablished());
163 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700164
165 // Sets link realized by connIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700166 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700167
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700168 assertFalse(oc3.isAllRealizingLinkNotEstablished());
169 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700170 }
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
Naoki Shiota03c29e12016-05-16 16:58:07 -0700199 // Mocks 2 intents to create Och connectivity
200 OpticalCircuitIntent circuitIntent1 = createCircuitIntent(cp21, cp32);
201 PacketLinkRealizedByOptical ochLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
202 circuitIntent1);
203
204 OpticalCircuitIntent circuitIntent2 = createCircuitIntent(cp51, cp62);
205 PacketLinkRealizedByOptical ochLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
206 circuitIntent2);
207
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700208 Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2);
209
Naoki Shiota03c29e12016-05-16 16:58:07 -0700210 Bandwidth bandwidth = Bandwidth.bps(100);
211 Duration latency = Duration.ofMillis(10);
212
213 OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700214 OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
215 plinks, Collections.emptySet());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700216
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700217 assertTrue(oc1.isAllRealizingLinkNotEstablished());
218 assertFalse(oc1.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700219
220 // Sets link realized by circuitIntent1 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700221 OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700222
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700223 assertFalse(oc2.isAllRealizingLinkNotEstablished());
224 assertFalse(oc2.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700225
226 // Sets link realized by circuitIntent2 to be established
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700227 OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
Naoki Shiota03c29e12016-05-16 16:58:07 -0700228
Naoki Shiota7c3111b2016-06-09 16:12:11 -0700229 assertFalse(oc3.isAllRealizingLinkNotEstablished());
230 assertTrue(oc3.isAllRealizingLinkEstablished());
Naoki Shiota03c29e12016-05-16 16:58:07 -0700231 }
232
233 private ConnectPoint createConnectPoint(long devIdNum, long portIdNum) {
234 return new ConnectPoint(
235 DeviceId.deviceId(String.format("of:%016d", devIdNum)),
236 PortNumber.portNumber(portIdNum));
237 }
238
239 private Link createLink(ConnectPoint src, ConnectPoint dst) {
240 return DefaultLink.builder()
241 .providerId(providerId)
242 .src(src)
243 .dst(dst)
244 .type(Link.Type.DIRECT)
245 .annotations(DefaultAnnotations.EMPTY)
246 .build();
247 }
248
249 private OpticalCircuitIntent createCircuitIntent(ConnectPoint src, ConnectPoint dst) {
250 OpticalCircuitIntent intent = OpticalCircuitIntent.builder()
251 .appId(appId)
252 .bidirectional(true)
253 .src(src)
254 .dst(dst)
255 .signalType(CltSignalType.CLT_100GBE)
256 .build();
257
258 return intent;
259 }
260
261 private OpticalConnectivityIntent createConnectivityIntent(ConnectPoint src, ConnectPoint dst) {
262 OpticalConnectivityIntent intent = OpticalConnectivityIntent.builder()
263 .appId(appId)
264 .bidirectional(true)
265 .src(src)
266 .dst(dst)
267 .signalType(OduSignalType.ODU4)
268 .build();
269
270 return intent;
271 }
272
273 private class MockPath extends DefaultLink implements Path {
274 List<Link> links;
275
276 protected MockPath(ConnectPoint src, ConnectPoint dst, List<Link> links) {
277 super(providerId, src, dst, Type.INDIRECT, State.ACTIVE);
278 this.links = links;
279 }
280
281 @Override
282 public List<Link> links() {
283 return links;
284 }
285
286 @Override
287 public double cost() {
288 return 0;
289 }
290 }
291}