Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | |
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; |
| 23 | import org.onlab.util.Bandwidth; |
| 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.DefaultApplicationId; |
| 26 | import org.onosproject.core.IdGenerator; |
| 27 | import org.onosproject.net.CltSignalType; |
| 28 | import org.onosproject.net.ConnectPoint; |
| 29 | import org.onosproject.net.DefaultAnnotations; |
| 30 | import org.onosproject.net.DefaultLink; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Link; |
| 33 | import org.onosproject.net.OduSignalType; |
| 34 | import org.onosproject.net.Path; |
| 35 | import org.onosproject.net.PortNumber; |
| 36 | import org.onosproject.net.intent.Intent; |
| 37 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 38 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 39 | import org.onosproject.net.provider.ProviderId; |
| 40 | import org.onosproject.newoptical.api.OpticalConnectivityId; |
| 41 | |
| 42 | import java.time.Duration; |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 43 | import java.util.Collections; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 44 | import java.util.List; |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 45 | import java.util.Set; |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 46 | import java.util.stream.Collectors; |
| 47 | import java.util.stream.Stream; |
| 48 | |
| 49 | import static org.junit.Assert.assertEquals; |
| 50 | import static org.junit.Assert.assertFalse; |
| 51 | import static org.junit.Assert.assertNotNull; |
| 52 | import static org.junit.Assert.assertTrue; |
| 53 | |
| 54 | /** |
| 55 | * Test class for OpticalConnectivity. |
| 56 | */ |
| 57 | public 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 Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 100 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 101 | OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 102 | Collections.emptySet(), Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 103 | |
| 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 Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 147 | Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2); |
| 148 | |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 149 | Bandwidth bandwidth = Bandwidth.bps(100); |
| 150 | Duration latency = Duration.ofMillis(10); |
| 151 | |
| 152 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 153 | OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 154 | plinks, Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 155 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 156 | assertTrue(oc1.isAllRealizingLinkNotEstablished()); |
| 157 | assertFalse(oc1.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 158 | |
| 159 | // Sets link realized by connIntent1 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 160 | OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 161 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 162 | assertFalse(oc2.isAllRealizingLinkNotEstablished()); |
| 163 | assertFalse(oc2.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 164 | |
| 165 | // Sets link realized by connIntent2 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 166 | OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 167 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 168 | assertFalse(oc3.isAllRealizingLinkNotEstablished()); |
| 169 | assertTrue(oc3.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 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 | |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 199 | // 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 Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 208 | Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2); |
| 209 | |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 210 | Bandwidth bandwidth = Bandwidth.bps(100); |
| 211 | Duration latency = Duration.ofMillis(10); |
| 212 | |
| 213 | OpticalConnectivityId cid = OpticalConnectivityId.of(1L); |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 214 | OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, |
| 215 | plinks, Collections.emptySet()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 216 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 217 | assertTrue(oc1.isAllRealizingLinkNotEstablished()); |
| 218 | assertFalse(oc1.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 219 | |
| 220 | // Sets link realized by circuitIntent1 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 221 | OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 222 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 223 | assertFalse(oc2.isAllRealizingLinkNotEstablished()); |
| 224 | assertFalse(oc2.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 225 | |
| 226 | // Sets link realized by circuitIntent2 to be established |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 227 | OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 228 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 229 | assertFalse(oc3.isAllRealizingLinkNotEstablished()); |
| 230 | assertTrue(oc3.isAllRealizingLinkEstablished()); |
Naoki Shiota | 03c29e1 | 2016-05-16 16:58:07 -0700 | [diff] [blame] | 231 | } |
| 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 | } |