Naoki Shiota
Committed by Yuta HIGUCHI

Added unit tests for newoptical package.

Change-Id: I23d7b0ec4241ee620dccb605b529d50288242eb8
...@@ -4,8 +4,13 @@ COMPILE_DEPS = [ ...@@ -4,8 +4,13 @@ COMPILE_DEPS = [
4 '//cli:onos-cli', 4 '//cli:onos-cli',
5 ] 5 ]
6 6
7 +TEST_DEPS = [
8 + '//lib:TEST_ADAPTERS',
9 +]
10 +
7 osgi_jar_with_tests ( 11 osgi_jar_with_tests (
8 deps = COMPILE_DEPS, 12 deps = COMPILE_DEPS,
13 + test_deps = TEST_DEPS,
9 ) 14 )
10 15
11 onos_app ( 16 onos_app (
......
...@@ -89,6 +89,18 @@ ...@@ -89,6 +89,18 @@
89 <version>${project.version}</version> 89 <version>${project.version}</version>
90 </dependency> 90 </dependency>
91 91
92 + <dependency>
93 + <groupId>com.google.guava</groupId>
94 + <artifactId>guava-testlib</artifactId>
95 + <scope>test</scope>
96 + </dependency>
97 +
98 + <dependency>
99 + <groupId>org.onosproject</groupId>
100 + <artifactId>onlab-junit</artifactId>
101 + <scope>test</scope>
102 + </dependency>
103 +
92 </dependencies> 104 </dependencies>
93 105
94 <build> 106 <build>
......
...@@ -151,11 +151,7 @@ public class OpticalPathProvisioner ...@@ -151,11 +151,7 @@ public class OpticalPathProvisioner
151 deviceService = opticalView(deviceService); 151 deviceService = opticalView(deviceService);
152 appId = coreService.registerApplication("org.onosproject.newoptical"); 152 appId = coreService.registerApplication("org.onosproject.newoptical");
153 153
154 - idCounter = storageService.atomicCounterBuilder() 154 + idCounter = storageService.getAtomicCounter(OPTICAL_CONNECTIVITY_ID_COUNTER);
155 - .withName(OPTICAL_CONNECTIVITY_ID_COUNTER)
156 - .withMeteringDisabled()
157 - .build()
158 - .asAtomicCounter();
159 155
160 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry); 156 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
161 157
......
1 +/*
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 +
17 +package org.onosproject.newoptical;
18 +
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onlab.util.Bandwidth;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.core.DefaultApplicationId;
25 +import org.onosproject.core.IdGenerator;
26 +import org.onosproject.net.CltSignalType;
27 +import org.onosproject.net.ConnectPoint;
28 +import org.onosproject.net.DefaultAnnotations;
29 +import org.onosproject.net.DefaultLink;
30 +import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.Link;
32 +import org.onosproject.net.OduSignalType;
33 +import org.onosproject.net.Path;
34 +import org.onosproject.net.PortNumber;
35 +import org.onosproject.net.intent.Intent;
36 +import org.onosproject.net.intent.OpticalCircuitIntent;
37 +import org.onosproject.net.intent.OpticalConnectivityIntent;
38 +import org.onosproject.net.provider.ProviderId;
39 +import org.onosproject.newoptical.api.OpticalConnectivityId;
40 +
41 +import java.time.Duration;
42 +import java.util.List;
43 +import java.util.stream.Collectors;
44 +import java.util.stream.Stream;
45 +
46 +import static org.junit.Assert.assertEquals;
47 +import static org.junit.Assert.assertFalse;
48 +import static org.junit.Assert.assertNotNull;
49 +import static org.junit.Assert.assertTrue;
50 +
51 +/**
52 + * Test class for OpticalConnectivity.
53 + */
54 +public 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 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +
17 +package org.onosproject.newoptical;
18 +
19 +import javafx.util.Pair;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onlab.packet.ChassisId;
24 +import org.onlab.util.Bandwidth;
25 +import org.onlab.util.Frequency;
26 +import org.onosproject.cluster.ClusterServiceAdapter;
27 +import org.onosproject.core.ApplicationId;
28 +import org.onosproject.core.CoreServiceAdapter;
29 +import org.onosproject.core.DefaultApplicationId;
30 +import org.onosproject.core.IdGenerator;
31 +import org.onosproject.event.DefaultEventSinkRegistry;
32 +import org.onosproject.event.Event;
33 +import org.onosproject.event.EventDeliveryService;
34 +import org.onosproject.event.EventSink;
35 +import org.onosproject.mastership.MastershipServiceAdapter;
36 +import org.onosproject.net.ChannelSpacing;
37 +import org.onosproject.net.CltSignalType;
38 +import org.onosproject.net.ConnectPoint;
39 +import org.onosproject.net.DefaultDevice;
40 +import org.onosproject.net.DefaultLink;
41 +import org.onosproject.net.DefaultPath;
42 +import org.onosproject.net.DefaultPort;
43 +import org.onosproject.net.Device;
44 +import org.onosproject.net.DeviceId;
45 +import org.onosproject.net.ElementId;
46 +import org.onosproject.net.Link;
47 +import org.onosproject.net.OchSignal;
48 +import org.onosproject.net.OduSignalType;
49 +import org.onosproject.net.Path;
50 +import org.onosproject.net.Port;
51 +import org.onosproject.net.PortNumber;
52 +import org.onosproject.net.config.NetworkConfigServiceAdapter;
53 +import org.onosproject.net.device.DeviceServiceAdapter;
54 +import org.onosproject.net.intent.Intent;
55 +import org.onosproject.net.intent.IntentEvent;
56 +import org.onosproject.net.intent.IntentListener;
57 +import org.onosproject.net.intent.IntentServiceAdapter;
58 +import org.onosproject.net.intent.Key;
59 +import org.onosproject.net.intent.OpticalConnectivityIntent;
60 +import org.onosproject.net.link.LinkServiceAdapter;
61 +import org.onosproject.net.optical.impl.DefaultOchPort;
62 +import org.onosproject.net.optical.impl.DefaultOduCltPort;
63 +import org.onosproject.net.optical.impl.DefaultOmsPort;
64 +import org.onosproject.net.provider.ProviderId;
65 +import org.onosproject.net.resource.DiscreteResourceId;
66 +import org.onosproject.net.resource.Resource;
67 +import org.onosproject.net.resource.ResourceAllocation;
68 +import org.onosproject.net.resource.ResourceConsumer;
69 +import org.onosproject.net.resource.ResourceId;
70 +import org.onosproject.net.resource.ResourceListener;
71 +import org.onosproject.net.resource.ResourceService;
72 +import org.onosproject.net.topology.LinkWeight;
73 +import org.onosproject.net.topology.PathServiceAdapter;
74 +import org.onosproject.newoptical.api.OpticalConnectivityId;
75 +import org.onosproject.newoptical.api.OpticalPathEvent;
76 +import org.onosproject.newoptical.api.OpticalPathListener;
77 +import org.onosproject.store.service.AtomicCounter;
78 +import org.onosproject.store.service.StorageServiceAdapter;
79 +
80 +import java.time.Duration;
81 +import java.util.ArrayList;
82 +import java.util.Collection;
83 +import java.util.Collections;
84 +import java.util.HashMap;
85 +import java.util.HashSet;
86 +import java.util.List;
87 +import java.util.Map;
88 +import java.util.Optional;
89 +import java.util.Set;
90 +import java.util.stream.Collectors;
91 +import java.util.stream.Stream;
92 +
93 +import static com.google.common.base.Preconditions.checkState;
94 +import static org.junit.Assert.assertEquals;
95 +import static org.junit.Assert.assertNotNull;
96 +import static org.junit.Assert.assertTrue;
97 +import static org.onosproject.net.NetTestTools.injectEventDispatcher;
98 +
99 +/**
100 + * Tests for OpticalPathProvisioner class.
101 + */
102 +public class OpticalPathProvisionerTest {
103 +
104 + private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
105 +
106 + // 7-nodes linear topology containing packet/cross-connect/optical links
107 + private static final ConnectPoint CP11 = createConnectPoint(1, 1);
108 + private static final ConnectPoint CP12 = createConnectPoint(1, 2);
109 + private static final ConnectPoint CP21 = createConnectPoint(2, 1);
110 + private static final ConnectPoint CP22 = createConnectPoint(2, 2); // cross connect port (packet)
111 + private static final ConnectPoint CP31 = createConnectPoint(3, 1); // cross connect port (oductl)
112 + private static final ConnectPoint CP32 = createConnectPoint(3, 2);
113 + private static final ConnectPoint CP41 = createConnectPoint(4, 1);
114 + private static final ConnectPoint CP42 = createConnectPoint(4, 2);
115 + private static final ConnectPoint CP51 = createConnectPoint(5, 1);
116 + private static final ConnectPoint CP52 = createConnectPoint(5, 2); // cross connect port (oductl)
117 + private static final ConnectPoint CP61 = createConnectPoint(6, 1); // cross connect port (packet)
118 + private static final ConnectPoint CP62 = createConnectPoint(6, 2);
119 + private static final ConnectPoint CP71 = createConnectPoint(7, 1);
120 + private static final ConnectPoint CP72 = createConnectPoint(7, 2);
121 +
122 + private static final Link LINK1 = createLink(CP12, CP21, Link.Type.DIRECT);
123 + private static final Link LINK2 = createLink(CP22, CP31, Link.Type.OPTICAL); // cross connect link
124 + private static final Link LINK3 = createLink(CP32, CP41, Link.Type.OPTICAL);
125 + private static final Link LINK4 = createLink(CP42, CP51, Link.Type.OPTICAL);
126 + private static final Link LINK5 = createLink(CP52, CP61, Link.Type.OPTICAL); // cross connect link
127 + private static final Link LINK6 = createLink(CP62, CP71, Link.Type.DIRECT);
128 +
129 + private static final Device DEVICE1 = createDevice(1, Device.Type.SWITCH);
130 + private static final Device DEVICE2 = createDevice(2, Device.Type.SWITCH);
131 + private static final Device DEVICE3 = createDevice(3, Device.Type.ROADM);
132 + private static final Device DEVICE4 = createDevice(4, Device.Type.ROADM);
133 + private static final Device DEVICE5 = createDevice(5, Device.Type.ROADM);
134 + private static final Device DEVICE6 = createDevice(6, Device.Type.SWITCH);
135 + private static final Device DEVICE7 = createDevice(7, Device.Type.SWITCH);
136 +
137 + private static final Port PORT11 = createPacketPort(DEVICE1, CP11);
138 + private static final Port PORT12 = createPacketPort(DEVICE1, CP12);
139 + private static final Port PORT21 = createPacketPort(DEVICE2, CP21);
140 + private static final Port PORT22 = createOduCltPort(DEVICE2, CP22);
141 + private static final Port PORT31 = createOchPort(DEVICE3, CP31);
142 + private static final Port PORT32 = createOmsPort(DEVICE3, CP32);
143 + private static final Port PORT41 = createOmsPort(DEVICE4, CP41);
144 + private static final Port PORT42 = createOmsPort(DEVICE4, CP42);
145 + private static final Port PORT51 = createOmsPort(DEVICE5, CP51);
146 + private static final Port PORT52 = createOchPort(DEVICE5, CP52);
147 + private static final Port PORT61 = createOduCltPort(DEVICE6, CP61);
148 + private static final Port PORT62 = createPacketPort(DEVICE6, CP62);
149 + private static final Port PORT71 = createPacketPort(DEVICE7, CP71);
150 + private static final Port PORT72 = createPacketPort(DEVICE7, CP72);
151 +
152 + protected OpticalPathProvisioner target;
153 + protected TestListener listener = new TestListener();
154 + protected TestDeviceService deviceService;
155 + protected TestLinkService linkService;
156 + protected TestPathService pathService;
157 + protected TestIntentService intentService;
158 + protected IdGenerator idGenerator;
159 +
160 + @Before
161 + public void setUp() {
162 + this.deviceService = new TestDeviceService();
163 + deviceService.devMap.put(deviceIdOf(1), DEVICE1);
164 + deviceService.devMap.put(deviceIdOf(2), DEVICE2);
165 + deviceService.devMap.put(deviceIdOf(3), DEVICE3);
166 + deviceService.devMap.put(deviceIdOf(4), DEVICE4);
167 + deviceService.devMap.put(deviceIdOf(5), DEVICE5);
168 + deviceService.devMap.put(deviceIdOf(6), DEVICE6);
169 + deviceService.devMap.put(deviceIdOf(7), DEVICE7);
170 + deviceService.portMap.put(CP11, PORT11);
171 + deviceService.portMap.put(CP12, PORT12);
172 + deviceService.portMap.put(CP21, PORT21);
173 + deviceService.portMap.put(CP22, PORT22);
174 + deviceService.portMap.put(CP31, PORT31);
175 + deviceService.portMap.put(CP32, PORT32);
176 + deviceService.portMap.put(CP41, PORT41);
177 + deviceService.portMap.put(CP42, PORT42);
178 + deviceService.portMap.put(CP51, PORT51);
179 + deviceService.portMap.put(CP52, PORT52);
180 + deviceService.portMap.put(CP61, PORT61);
181 + deviceService.portMap.put(CP62, PORT62);
182 + deviceService.portMap.put(CP71, PORT71);
183 + deviceService.portMap.put(CP72, PORT72);
184 +
185 + this.linkService = new TestLinkService();
186 + linkService.links.addAll(Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6)
187 + .collect(Collectors.toList()));
188 +
189 + this.pathService = new TestPathService();
190 + this.intentService = new TestIntentService();
191 +
192 + this.target = new OpticalPathProvisioner();
193 + target.coreService = new TestCoreService();
194 + target.intentService = this.intentService;
195 + target.pathService = this.pathService;
196 + target.linkService = this.linkService;
197 + target.mastershipService = new TestMastershipService();
198 + target.clusterService = new TestClusterService();
199 + target.storageService = new TestStorageService();
200 + target.deviceService = this.deviceService;
201 + target.networkConfigService = new TestNetworkConfigService();
202 + target.resourceService = new TestResourceService();
203 + injectEventDispatcher(target, new TestEventDispatcher());
204 + target.addListener(listener);
205 +
206 + target.activate();
207 +
208 + // To overwrite opticalView-ed deviceService
209 + target.deviceService = this.deviceService;
210 +
211 + idGenerator = new IdGenerator() {
212 + int counter = 1;
213 +
214 + @Override
215 + public long getNewId() {
216 + return counter++;
217 + }
218 + };
219 + Intent.bindIdGenerator(idGenerator);
220 + }
221 +
222 + @After
223 + public void tearDown() {
224 + Intent.unbindIdGenerator(idGenerator);
225 + target.removeListener(listener);
226 + target = null;
227 + }
228 +
229 + /**
230 + * Checks setupConnectivity method works.
231 + */
232 + @Test
233 + public void testSetupConnectivity() {
234 + Bandwidth bandwidth = Bandwidth.bps(100);
235 + Duration latency = Duration.ofMillis(10);
236 +
237 + OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
238 + assertNotNull(cid);
239 +
240 + // Checks path computation is called as expected
241 + assertEquals(1, pathService.edges.size());
242 + assertEquals(CP12.deviceId(), pathService.edges.get(0).getKey());
243 + assertEquals(CP71.deviceId(), pathService.edges.get(0).getValue());
244 +
245 + // Checks intents are installed as expected
246 + assertEquals(1, intentService.submitted.size());
247 + assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
248 + OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
249 + assertEquals(CP31, connIntent.getSrc());
250 + assertEquals(CP52, connIntent.getDst());
251 + }
252 +
253 + /**
254 + * Checks setupPath method works.
255 + */
256 + @Test
257 + public void testSetupPath() {
258 + Bandwidth bandwidth = Bandwidth.bps(100);
259 + Duration latency = Duration.ofMillis(10);
260 + List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6)
261 + .collect(Collectors.toList());
262 + Path path = new DefaultPath(PROVIDER_ID, links, 0);
263 +
264 + OpticalConnectivityId cid = target.setupPath(path, bandwidth, latency);
265 + assertNotNull(cid);
266 +
267 + // Checks intents are installed as expected
268 + assertEquals(1, intentService.submitted.size());
269 + assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
270 + OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
271 + assertEquals(CP31, connIntent.getSrc());
272 + assertEquals(CP52, connIntent.getDst());
273 + }
274 +
275 + /**
276 + * Checks removeConnectivity method works.
277 + */
278 + @Test
279 + public void testRemoveConnectivity() {
280 + Bandwidth bandwidth = Bandwidth.bps(100);
281 + Duration latency = Duration.ofMillis(10);
282 +
283 + OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
284 +
285 + // Checks intents are withdrawn
286 + assertTrue(target.removeConnectivity(cid));
287 + assertEquals(1, intentService.withdrawn.size());
288 + assertEquals(OpticalConnectivityIntent.class, intentService.withdrawn.get(0).getClass());
289 + OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.withdrawn.get(0);
290 + assertEquals(CP31, connIntent.getSrc());
291 + assertEquals(CP52, connIntent.getDst());
292 + }
293 +
294 + /**
295 + * Checks getPath method works.
296 + */
297 + @Test
298 + public void testGetPath() {
299 + Bandwidth bandwidth = Bandwidth.bps(100);
300 + Duration latency = Duration.ofMillis(10);
301 + List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6)
302 + .collect(Collectors.toList());
303 +
304 + OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
305 + Optional<List<Link>> path = target.getPath(cid);
306 +
307 + // Checks returned path is as expected
308 + assertTrue(path.isPresent());
309 + assertEquals(links, path.get());
310 + }
311 +
312 + /**
313 + * Checks if PATH_INSTALLED event comes up after intent is installed.
314 + */
315 + @Test
316 + public void testInstalledEvent() {
317 + Bandwidth bandwidth = Bandwidth.bps(100);
318 + Duration latency = Duration.ofMillis(10);
319 +
320 + OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
321 +
322 + intentService.notifyInstalled();
323 +
324 + assertEquals(1, listener.events.size());
325 + assertEquals(OpticalPathEvent.Type.PATH_INSTALLED, listener.events.get(0).type());
326 + assertEquals(cid, listener.events.get(0).subject());
327 + }
328 +
329 + /**
330 + * Checks if PATH_REMOVED event comes up after packet link is removed.
331 + */
332 + @Test
333 + public void testRemovedEvent() {
334 + Bandwidth bandwidth = Bandwidth.bps(100);
335 + Duration latency = Duration.ofMillis(10);
336 +
337 + OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
338 +
339 + intentService.notifyInstalled();
340 +
341 + target.removeConnectivity(cid);
342 +
343 + intentService.notifyWithdrawn();
344 +
345 + assertEquals(2, listener.events.size());
346 + assertEquals(OpticalPathEvent.Type.PATH_REMOVED, listener.events.get(1).type());
347 + assertEquals(cid, listener.events.get(1).subject());
348 + }
349 +
350 + private static ConnectPoint createConnectPoint(long devIdNum, long portIdNum) {
351 + return new ConnectPoint(
352 + deviceIdOf(devIdNum),
353 + PortNumber.portNumber(portIdNum));
354 + }
355 +
356 + private static Link createLink(ConnectPoint src, ConnectPoint dst, Link.Type type) {
357 + return DefaultLink.builder()
358 + .providerId(PROVIDER_ID)
359 + .src(src)
360 + .dst(dst)
361 + .state(Link.State.ACTIVE)
362 + .type(type).build();
363 + }
364 +
365 + private static Device createDevice(long devIdNum, Device.Type type) {
366 + return new DefaultDevice(PROVIDER_ID,
367 + deviceIdOf(devIdNum),
368 + type,
369 + "manufacturer",
370 + "hwVersion",
371 + "swVersion",
372 + "serialNumber",
373 + new ChassisId(1));
374 + }
375 +
376 + private static Port createPacketPort(Device device, ConnectPoint cp) {
377 + return new DefaultPort(device, cp.port(), true);
378 + }
379 +
380 + private static Port createOchPort(Device device, ConnectPoint cp) {
381 + return new DefaultOchPort(new DefaultPort(device, cp.port(), true),
382 + OduSignalType.ODU4,
383 + true,
384 + OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1));
385 + }
386 +
387 + private static Port createOduCltPort(Device device, ConnectPoint cp) {
388 + return new DefaultOduCltPort(new DefaultPort(device, cp.port(), true),
389 + CltSignalType.CLT_100GBE);
390 + }
391 +
392 + private static Port createOmsPort(Device device, ConnectPoint cp) {
393 + return new DefaultOmsPort(new DefaultPort(device, cp.port(), true),
394 + Frequency.ofKHz(3),
395 + Frequency.ofKHz(33),
396 + Frequency.ofKHz(2));
397 + }
398 +
399 + private static DeviceId deviceIdOf(long devIdNum) {
400 + return DeviceId.deviceId(String.format("of:%016d", devIdNum));
401 + }
402 +
403 + private static class TestListener implements OpticalPathListener {
404 + final List<OpticalPathEvent> events = new ArrayList<>();
405 +
406 + @Override
407 + public void event(OpticalPathEvent event) {
408 + events.add(event);
409 + }
410 + }
411 +
412 + private static class TestPathService extends PathServiceAdapter {
413 + List<Pair<DeviceId, DeviceId>> edges = new ArrayList<>();
414 +
415 + @Override
416 + public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
417 + if (!(src instanceof DeviceId && dst instanceof DeviceId)) {
418 + return Collections.emptySet();
419 + }
420 +
421 + edges.add(new Pair<>((DeviceId) src, (DeviceId) dst));
422 +
423 + Set<Path> paths = new HashSet<>();
424 + List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6)
425 + .collect(Collectors.toList());
426 + paths.add(new DefaultPath(PROVIDER_ID, links, 0));
427 +
428 + // returns paths containing single path
429 + return paths;
430 + }
431 +
432 + }
433 +
434 + private static class TestIntentService extends IntentServiceAdapter {
435 + List<Intent> submitted = new ArrayList<>();
436 + List<Intent> withdrawn = new ArrayList<>();
437 + List<IntentListener> listeners = new ArrayList<>();
438 +
439 + @Override
440 + public void submit(Intent intent) {
441 + submitted.add(intent);
442 + }
443 +
444 + @Override
445 + public void withdraw(Intent intent) {
446 + withdrawn.add(intent);
447 + }
448 +
449 + @Override
450 + public void addListener(IntentListener listener) {
451 + listeners.add(listener);
452 + }
453 +
454 + @Override
455 + public Intent getIntent(Key intentKey) {
456 + Intent intent = submitted.stream().filter(i -> i.key().equals(intentKey))
457 + .findAny()
458 + .get();
459 + return intent;
460 + }
461 +
462 + void notifyInstalled() {
463 + submitted.forEach(i -> {
464 + IntentEvent event = new IntentEvent(IntentEvent.Type.INSTALLED, i);
465 + listeners.forEach(l -> l.event(event));
466 + });
467 + }
468 +
469 + void notifyWithdrawn() {
470 + withdrawn.forEach(i -> {
471 + IntentEvent event = new IntentEvent(IntentEvent.Type.WITHDRAWN, i);
472 + listeners.forEach(l -> l.event(event));
473 + });
474 + }
475 +
476 + }
477 +
478 + private static class TestLinkService extends LinkServiceAdapter {
479 + List<Link> links = new ArrayList<>();
480 +
481 + @Override
482 + public Set<Link> getLinks(ConnectPoint connectPoint) {
483 + return links.stream()
484 + .filter(l -> l.src().equals(connectPoint) || l.dst().equals(connectPoint))
485 + .collect(Collectors.toSet());
486 + }
487 +
488 + }
489 +
490 + private static class TestCoreService extends CoreServiceAdapter {
491 + @Override
492 + public ApplicationId registerApplication(String name) {
493 + return new DefaultApplicationId(0, name);
494 + }
495 + }
496 +
497 + private static class TestMastershipService extends MastershipServiceAdapter {
498 +
499 + }
500 +
501 + private static class TestClusterService extends ClusterServiceAdapter {
502 +
503 + }
504 +
505 + private static class TestStorageService extends StorageServiceAdapter {
506 + @Override
507 + public AtomicCounter getAtomicCounter(String name) {
508 + return new MockAtomicCounter();
509 + }
510 + }
511 +
512 + private static class TestDeviceService extends DeviceServiceAdapter {
513 + Map<DeviceId, Device> devMap = new HashMap<>();
514 + Map<ConnectPoint, Port> portMap = new HashMap<>();
515 +
516 + @Override
517 + public Device getDevice(DeviceId deviceId) {
518 + return devMap.get(deviceId);
519 + }
520 +
521 + @Override
522 + public Port getPort(DeviceId deviceId, PortNumber portNumber) {
523 + return portMap.get(new ConnectPoint(deviceId, portNumber));
524 + }
525 + }
526 +
527 + private static class TestNetworkConfigService extends NetworkConfigServiceAdapter {
528 +
529 + }
530 +
531 + private static class TestResourceService implements ResourceService {
532 +
533 + @Override
534 + public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) {
535 + List<ResourceAllocation> allocations = new ArrayList<>();
536 +
537 + resources.forEach(r -> allocations.add(new ResourceAllocation(r, consumer.consumerId())));
538 +
539 + return allocations;
540 + }
541 +
542 + @Override
543 + public boolean release(List<ResourceAllocation> allocations) {
544 + return false;
545 + }
546 +
547 + @Override
548 + public boolean release(ResourceConsumer consumer) {
549 +
550 + return true;
551 + }
552 +
553 + @Override
554 + public void addListener(ResourceListener listener) {
555 +
556 + }
557 +
558 + @Override
559 + public void removeListener(ResourceListener listener) {
560 +
561 + }
562 +
563 + @Override
564 + public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
565 + return null;
566 + }
567 +
568 + @Override
569 + public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) {
570 + return null;
571 + }
572 +
573 + @Override
574 + public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
575 + return null;
576 + }
577 +
578 + @Override
579 + public Set<Resource> getAvailableResources(DiscreteResourceId parent) {
580 + return null;
581 + }
582 +
583 + @Override
584 + public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) {
585 + return null;
586 + }
587 +
588 + @Override
589 + public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) {
590 + return null;
591 + }
592 +
593 + @Override
594 + public Set<Resource> getRegisteredResources(DiscreteResourceId parent) {
595 + return null;
596 + }
597 +
598 + @Override
599 + public boolean isAvailable(Resource resource) {
600 + return true;
601 + }
602 + }
603 +
604 + private static class MockAtomicCounter implements AtomicCounter {
605 + long id = 0;
606 +
607 + @Override
608 + public long incrementAndGet() {
609 + return ++id;
610 + }
611 +
612 + @Override
613 + public long getAndIncrement() {
614 + return id++;
615 + }
616 +
617 + @Override
618 + public long getAndAdd(long delta) {
619 + long oldId = id;
620 + id += delta;
621 + return oldId;
622 + }
623 +
624 + @Override
625 + public long addAndGet(long delta) {
626 + id += delta;
627 + return id;
628 + }
629 +
630 + @Override
631 + public void set(long value) {
632 + id = value;
633 + }
634 +
635 + @Override
636 + public boolean compareAndSet(long expectedValue, long updateValue) {
637 + if (id == expectedValue) {
638 + id = updateValue;
639 + return true;
640 + } else {
641 + return false;
642 + }
643 + }
644 +
645 + @Override
646 + public long get() {
647 + return id;
648 + }
649 +
650 + @Override
651 + public String name() {
652 + return "MockAtomicCounter";
653 + }
654 + }
655 +
656 + // copied from org.onosproject.common.event.impl.TestEventDispatcher
657 + /**
658 + * Implements event delivery system that delivers events synchronously, or
659 + * in-line with the post method invocation.
660 + */
661 + public class TestEventDispatcher extends DefaultEventSinkRegistry
662 + implements EventDeliveryService {
663 +
664 + @Override
665 + @SuppressWarnings("unchecked")
666 + public synchronized void post(Event event) {
667 + EventSink sink = getSink(event.getClass());
668 + checkState(sink != null, "No sink for event %s", event);
669 + sink.process(event);
670 + }
671 +
672 + @Override
673 + public void setDispatchTimeLimit(long millis) {
674 + }
675 +
676 + @Override
677 + public long getDispatchTimeLimit() {
678 + return 0;
679 + }
680 + }
681 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +
17 +package org.onosproject.newoptical;
18 +
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onlab.util.Bandwidth;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.core.DefaultApplicationId;
25 +import org.onosproject.core.IdGenerator;
26 +import org.onosproject.net.CltSignalType;
27 +import org.onosproject.net.ConnectPoint;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.OduSignalType;
30 +import org.onosproject.net.PortNumber;
31 +import org.onosproject.net.intent.Intent;
32 +import org.onosproject.net.intent.Key;
33 +import org.onosproject.net.intent.OpticalCircuitIntent;
34 +import org.onosproject.net.intent.OpticalConnectivityIntent;
35 +
36 +import static org.junit.Assert.*;
37 +
38 +/**
39 + * Test class for PacketLinkRealizedByOptical class.
40 + */
41 +public 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 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +
17 +package org.onosproject.newoptical.api;
18 +
19 +import org.junit.Test;
20 +import com.google.common.testing.EqualsTester;
21 +
22 +import static org.junit.Assert.assertEquals;
23 +import static org.junit.Assert.assertNotNull;
24 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25 +
26 +/**
27 + * Test class for OpticalConnectivityId.
28 + */
29 +public class OpticalConnectivityIdTest {
30 +
31 + /**
32 + * Checks that OpticalConnectivityId class is immutable.
33 + */
34 + @Test
35 + public void testImmutability() {
36 + assertThatClassIsImmutable(OpticalConnectivityId.class);
37 + }
38 +
39 + /**
40 + * Checks the construction of OpticalConnectivityId object.
41 + */
42 + @Test
43 + public void testConstruction() {
44 + OpticalConnectivityId tid = OpticalConnectivityId.of(1L);
45 + assertNotNull(tid);
46 + assertEquals(tid.id().longValue(), 1L);
47 + }
48 +
49 + /**
50 + * Checks the equality of OpticalConnectivityId objects.
51 + */
52 + @Test
53 + public void testEquality() {
54 + OpticalConnectivityId tid1 = OpticalConnectivityId.of(1L);
55 + OpticalConnectivityId tid2 = OpticalConnectivityId.of(1L);
56 + OpticalConnectivityId tid3 = OpticalConnectivityId.of(2L);
57 +
58 + new EqualsTester()
59 + .addEqualityGroup(tid1, tid2)
60 + .addEqualityGroup(tid3)
61 + .testEquals();
62 + }
63 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +
17 +package org.onosproject.newoptical.api;
18 +
19 +import org.junit.Test;
20 +import org.onosproject.event.AbstractEventTest;
21 +
22 +/**
23 + * Test class for OpticalPathEvent class.
24 + */
25 +public class OpticalPathEventTest extends AbstractEventTest {
26 +
27 + @Override
28 + @Test
29 + public void withoutTime() {
30 + OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
31 + long before = System.currentTimeMillis();
32 + OpticalPathEvent event = new OpticalPathEvent(OpticalPathEvent.Type.PATH_INSTALLED, cid);
33 + long after = System.currentTimeMillis();
34 + validateEvent(event, OpticalPathEvent.Type.PATH_INSTALLED, cid, before, after);
35 + }
36 +
37 +}
...\ No newline at end of file ...\ No newline at end of file