Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 23 | import org.onlab.graph.Weight; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 24 | import org.onlab.util.Bandwidth; |
| 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.DefaultApplicationId; |
| 27 | import org.onosproject.core.IdGenerator; |
| 28 | import org.onosproject.net.CltSignalType; |
| 29 | import org.onosproject.net.ConnectPoint; |
| 30 | import org.onosproject.net.DefaultAnnotations; |
| 31 | import org.onosproject.net.DefaultLink; |
| 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.Link; |
| 34 | import org.onosproject.net.OduSignalType; |
| 35 | import org.onosproject.net.Path; |
| 36 | import org.onosproject.net.PortNumber; |
| 37 | import org.onosproject.net.intent.Intent; |
| 38 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 39 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 40 | import org.onosproject.net.provider.ProviderId; |
| 41 | import org.onosproject.newoptical.api.OpticalConnectivityId; |
| 42 | |
| 43 | import java.time.Duration; |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 44 | import java.util.Collections; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 45 | import java.util.List; |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 46 | import java.util.Set; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 47 | import java.util.stream.Collectors; |
| 48 | import java.util.stream.Stream; |
| 49 | |
| 50 | import static org.junit.Assert.assertEquals; |
| 51 | import static org.junit.Assert.assertFalse; |
| 52 | import static org.junit.Assert.assertNotNull; |
| 53 | import static org.junit.Assert.assertTrue; |
| 54 | |
| 55 | /** |
| 56 | * Test class for OpticalConnectivity. |
| 57 | */ |
| 58 | public 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 Vachuska | 2323596 | 2017-02-03 11:44:15 -0800 | [diff] [blame] | 75 | Intent.unbindIdGenerator(idGenerator); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 76 | 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 Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 102 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 103 | OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 104 | Collections.emptySet(), Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 105 | |
| 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 Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 140 | // 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 Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 149 | Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2); |
| 150 | |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 151 | Bandwidth bandwidth = Bandwidth.bps(100); |
| 152 | Duration latency = Duration.ofMillis(10); |
| 153 | |
| 154 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 155 | OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 156 | plinks, Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 157 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 158 | assertTrue(oc1.isAllRealizingLinkNotEstablished()); |
| 159 | assertFalse(oc1.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 160 | |
| 161 | // Sets link realized by connIntent1 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 162 | OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 163 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 164 | assertFalse(oc2.isAllRealizingLinkNotEstablished()); |
| 165 | assertFalse(oc2.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 166 | |
| 167 | // Sets link realized by connIntent2 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 168 | OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 169 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 170 | assertFalse(oc3.isAllRealizingLinkNotEstablished()); |
| 171 | assertTrue(oc3.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 172 | } |
| 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 Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 210 | Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2); |
| 211 | |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 212 | Bandwidth bandwidth = Bandwidth.bps(100); |
| 213 | Duration latency = Duration.ofMillis(10); |
| 214 | |
| 215 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 216 | OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 217 | plinks, Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 218 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 219 | assertTrue(oc1.isAllRealizingLinkNotEstablished()); |
| 220 | assertFalse(oc1.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 221 | |
| 222 | // Sets link realized by circuitIntent1 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 223 | OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 224 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 225 | assertFalse(oc2.isAllRealizingLinkNotEstablished()); |
| 226 | assertFalse(oc2.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 227 | |
| 228 | // Sets link realized by circuitIntent2 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 229 | OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 230 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 231 | assertFalse(oc3.isAllRealizingLinkNotEstablished()); |
| 232 | assertTrue(oc3.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | } |
Andrey Komarov | 2398d96 | 2016-09-26 15:11:23 +0300 | [diff] [blame] | 292 | |
| 293 | @Override |
| 294 | public Weight weight() { |
| 295 | return null; |
| 296 | } |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 297 | } |
| 298 | } |