Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [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.driver.optical.protection; |
| 18 | |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 19 | import org.onosproject.core.CoreService; |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.FilteredConnectPoint; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.LinkKey; |
| 25 | import org.onosproject.net.Port; |
| 26 | import org.onosproject.net.PortNumber; |
| 27 | import org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription; |
| 28 | import org.onosproject.net.behaviour.protection.ProtectedTransportEndpointState; |
| 29 | import org.onosproject.net.behaviour.protection.ProtectionConfigBehaviour; |
| 30 | import org.onosproject.net.behaviour.protection.TransportEndpointDescription; |
| 31 | import org.onosproject.net.behaviour.protection.TransportEndpointId; |
| 32 | import org.onosproject.net.behaviour.protection.TransportEndpointState; |
| 33 | import org.onosproject.net.config.NetworkConfigService; |
| 34 | import org.onosproject.net.config.basics.BasicLinkConfig; |
| 35 | import org.onosproject.net.device.DeviceService; |
| 36 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 37 | import org.onosproject.net.flow.DefaultFlowRule; |
| 38 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 39 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 40 | import org.onosproject.net.flow.FlowRule; |
| 41 | import org.onosproject.net.flow.FlowRuleService; |
| 42 | import org.onosproject.net.flow.TrafficSelector; |
| 43 | import org.onosproject.net.flow.TrafficTreatment; |
| 44 | import org.onosproject.net.link.LinkService; |
| 45 | import org.onosproject.net.optical.OpticalAnnotations; |
| 46 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; |
| 48 | |
| 49 | import java.util.ArrayList; |
| 50 | import java.util.HashMap; |
| 51 | import java.util.List; |
| 52 | import java.util.Map; |
| 53 | import java.util.Set; |
| 54 | import java.util.concurrent.CompletableFuture; |
| 55 | |
| 56 | import static org.onosproject.net.LinkKey.linkKey; |
| 57 | |
| 58 | /** |
| 59 | * Implementations of the protection behaviours for Oplink Optical Protection Switch (OPS). |
| 60 | * - Oplink OPS has 3 logical bi-directional ports (6 uni-directional physical ports): |
| 61 | * - port 1 is primary port for network side |
| 62 | * - port 2 is secondary port for network side. |
| 63 | * - port 3 is connected to the client side port; |
| 64 | * - Traffic protection |
| 65 | * - Traffic(Optical light) from client port is broadcasted (50/50 split) to |
| 66 | * both primary and secondary ports all the time. |
| 67 | * - In fault free condition, traffic from primary port is bridged to client port and |
| 68 | * in the case of primary port fails (LOS), traffic is bridged from secondary port to client port. |
| 69 | * - User initiated switch (to primary or secondary) is also supported. |
| 70 | */ |
| 71 | public class OplinkSwitchProtection extends AbstractHandlerBehaviour implements ProtectionConfigBehaviour { |
| 72 | |
| 73 | private static final int VIRTUAL_PORT = 0; |
| 74 | private static final int PRIMARY_PORT = 1; |
| 75 | private static final int SECONDARY_PORT = 2; |
| 76 | private static final int CLIENT_PORT = 3; |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 77 | private static final int FLOWRULE_PRIORITY = 88; |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 78 | private static final String PRIMARY_ID = "primary_port"; |
| 79 | private static final String SECONDARY_ID = "secondary_port"; |
| 80 | private static final String OPLINK_FINGERPRINT = "OplinkOPS"; |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 81 | private static final String APP_ID = "org.onosproject.drivers.optical"; |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 82 | |
| 83 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| 84 | |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 85 | @Override |
| 86 | public CompletableFuture<ConnectPoint> createProtectionEndpoint( |
| 87 | ProtectedTransportEndpointDescription configuration) { |
| 88 | //This OPS device only support one protection group of port 2 and port 3 |
| 89 | |
| 90 | CompletableFuture result = new CompletableFuture<ConnectPoint>(); |
| 91 | |
| 92 | //add flow from client port to virtual port. This set device in auto switch mode |
| 93 | addFlow(PortNumber.portNumber(VIRTUAL_PORT)); |
| 94 | |
Frank Wang | 3a98e0a | 2017-08-11 11:09:30 +0800 | [diff] [blame^] | 95 | //add a virtual link between two virtual ports of this device and peer |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 96 | addLinkToPeer(configuration.peer()); |
| 97 | |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 98 | result.complete(new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT))); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 99 | |
| 100 | return result; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public CompletableFuture<ConnectPoint> updateProtectionEndpoint( |
| 105 | ConnectPoint identifier, ProtectedTransportEndpointDescription configuration) { |
| 106 | |
| 107 | log.warn("Update protection configuration is not supported by this device"); |
| 108 | |
| 109 | CompletableFuture result = new CompletableFuture<ConnectPoint>(); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 110 | result.complete(new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT))); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 111 | |
| 112 | return result; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public CompletableFuture<Boolean> deleteProtectionEndpoint(ConnectPoint identifier) { |
| 117 | //OPS has only one protection group |
| 118 | CompletableFuture result = new CompletableFuture<Boolean>(); |
| 119 | |
| 120 | if (identifier.port().toLong() == VIRTUAL_PORT) { |
Frank Wang | 3a98e0a | 2017-08-11 11:09:30 +0800 | [diff] [blame^] | 121 | //add a link between two virtual ports of this device and peer |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 122 | removeLinkToPeer(getPeerId()); |
| 123 | deleteFlow(); |
| 124 | result.complete(true); |
| 125 | } else { |
| 126 | result.complete(false); |
| 127 | } |
| 128 | |
| 129 | return result; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointDescription>> getProtectionEndpointConfigs() { |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 134 | ConnectPoint cp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT)); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 135 | |
| 136 | Map<ConnectPoint, ProtectedTransportEndpointDescription> protectedGroups = new HashMap<>(); |
| 137 | CompletableFuture result = new CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointDescription>>(); |
| 138 | |
| 139 | protectedGroups.put(cp, getProtectedTransportEndpointDescription()); |
| 140 | result.complete(protectedGroups); |
| 141 | |
| 142 | return result; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointState>> getProtectionEndpointStates() { |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 147 | ConnectPoint cp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT)); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 148 | |
| 149 | Map<ConnectPoint, ProtectedTransportEndpointState> protectedGroups = new HashMap<>(); |
| 150 | CompletableFuture result = new CompletableFuture<Map<ConnectPoint, ProtectedTransportEndpointState>>(); |
| 151 | |
| 152 | protectedGroups.put(cp, getProtectedTransportEndpointState()); |
| 153 | result.complete(protectedGroups); |
| 154 | |
| 155 | return result; |
| 156 | } |
| 157 | |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 158 | @Override |
| 159 | public CompletableFuture<Void> switchWorkingPath(ConnectPoint identifier, int index) { |
MaoLu | 6685877 | 2017-05-11 19:38:01 -0700 | [diff] [blame] | 160 | return switchToManual(identifier, index); |
| 161 | } |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 162 | |
MaoLu | 6685877 | 2017-05-11 19:38:01 -0700 | [diff] [blame] | 163 | @Override |
| 164 | public CompletableFuture<Void> switchToForce(ConnectPoint identifier, int index) { |
| 165 | // TODO |
| 166 | // Currently not supported for openflow device. |
| 167 | CompletableFuture<Void> future = new CompletableFuture<>(); |
| 168 | future.completeExceptionally(new UnsupportedOperationException()); |
| 169 | return future; |
| 170 | } |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 171 | |
MaoLu | 6685877 | 2017-05-11 19:38:01 -0700 | [diff] [blame] | 172 | @Override |
| 173 | public CompletableFuture<Void> switchToManual(ConnectPoint identifier, int index) { |
| 174 | return getProtectionEndpointConfig(identifier) |
| 175 | .thenApply(m -> m.paths().get(index)) |
| 176 | .thenApply(m -> switchDevice(m.output().connectPoint().port())) |
| 177 | .thenApply(m -> null); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public CompletableFuture<Void> switchToAutomatic(ConnectPoint identifier) { |
| 182 | switchDevice(PortNumber.portNumber(VIRTUAL_PORT)); |
| 183 | return CompletableFuture.completedFuture(null); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * port: PRIMARY_PORT - manual switch to primary port. |
| 188 | * SECONDARY_PORT - manual switch to Secondary port. |
| 189 | * VIRTUAL_PORT - automatic switch mode. |
| 190 | */ |
| 191 | private boolean switchDevice(PortNumber port) { |
| 192 | // TODO |
| 193 | // If the flow operations do not go through, the controller would be in an inconsistent state. |
| 194 | // Using listener can be a hack to imitate async API, to workaround the issue. |
| 195 | // But can probably get tricky to do it correctly, ensuring not leaving dangling listener, etc. |
| 196 | deleteFlow(); |
| 197 | addFlow(port); |
| 198 | return true; |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* |
| 202 | * return the protected endpoint description of this devices |
| 203 | */ |
| 204 | private ProtectedTransportEndpointDescription getProtectedTransportEndpointDescription() { |
| 205 | List<TransportEndpointDescription> teds = new ArrayList<>(); |
| 206 | FilteredConnectPoint fcpPrimary = new FilteredConnectPoint( |
| 207 | new ConnectPoint(data().deviceId(), PortNumber.portNumber(PRIMARY_PORT))); |
| 208 | FilteredConnectPoint fcpSecondary = new FilteredConnectPoint( |
| 209 | new ConnectPoint(data().deviceId(), PortNumber.portNumber(SECONDARY_PORT))); |
| 210 | TransportEndpointDescription tedPrimary = TransportEndpointDescription.builder() |
| 211 | .withOutput(fcpPrimary).build(); |
| 212 | TransportEndpointDescription tedSecondary = TransportEndpointDescription.builder() |
| 213 | .withOutput(fcpSecondary).build(); |
| 214 | |
| 215 | teds.add(tedPrimary); |
| 216 | teds.add(tedSecondary); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 217 | return ProtectedTransportEndpointDescription.of(teds, getPeerId(), OPLINK_FINGERPRINT); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* |
| 221 | * get endpoint state attributes |
| 222 | */ |
| 223 | private Map<String, String> getProtectionStateAttributes(PortNumber portNumber) { |
| 224 | Map<String, String> attributes = new HashMap<>(); |
| 225 | |
| 226 | //get status form port annotations, the status is update by hand shaker driver periodically |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 227 | Port port = handler().get(DeviceService.class).getPort(data().deviceId(), portNumber); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 228 | if (port != null) { |
| 229 | String portStatus = port.annotations().value(OpticalAnnotations.INPUT_PORT_STATUS); |
| 230 | attributes.put(OpticalAnnotations.INPUT_PORT_STATUS, portStatus); |
| 231 | } |
| 232 | return attributes; |
| 233 | } |
| 234 | |
MaoLu | a8998df | 2017-03-15 14:20:38 -0700 | [diff] [blame] | 235 | /* |
| 236 | * get activer port number |
| 237 | */ |
| 238 | private int getActivePort() { |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 239 | Port port = handler().get(DeviceService.class) |
| 240 | .getPort(data().deviceId(), PortNumber.portNumber(PRIMARY_PORT)); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 241 | if (port != null) { |
| 242 | if (port.annotations().value(OpticalAnnotations.INPUT_PORT_STATUS) |
| 243 | .equals(OpticalAnnotations.STATUS_IN_SERVICE)) { |
| 244 | return PRIMARY_PORT; |
| 245 | } |
| 246 | } |
| 247 | return SECONDARY_PORT; |
| 248 | } |
| 249 | |
| 250 | /* |
MaoLu | a8998df | 2017-03-15 14:20:38 -0700 | [diff] [blame] | 251 | * get active path index |
| 252 | */ |
| 253 | private int getActiveIndex(List<TransportEndpointState> pathStates) { |
| 254 | long activePort = (long) getActivePort(); |
| 255 | int activeIndex = 0; |
| 256 | for (TransportEndpointState state : pathStates) { |
| 257 | if (state.description().output().connectPoint().port().toLong() == activePort) { |
| 258 | return activeIndex; |
| 259 | } |
| 260 | ++activeIndex; |
| 261 | } |
| 262 | return ProtectedTransportEndpointState.ACTIVE_UNKNOWN; |
| 263 | } |
| 264 | |
| 265 | /* |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 266 | * get protected endpoint state |
| 267 | */ |
| 268 | private ProtectedTransportEndpointState getProtectedTransportEndpointState() { |
| 269 | List<TransportEndpointState> tess = new ArrayList<>(); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 270 | PortNumber portPrimary = PortNumber.portNumber(PRIMARY_PORT); |
| 271 | PortNumber portSecondary = PortNumber.portNumber(SECONDARY_PORT); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 272 | FilteredConnectPoint fcpPrimary = new FilteredConnectPoint( |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 273 | new ConnectPoint(data().deviceId(), portPrimary)); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 274 | FilteredConnectPoint fcpSecondary = new FilteredConnectPoint( |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 275 | new ConnectPoint(data().deviceId(), portSecondary)); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 276 | TransportEndpointDescription tedPrimary = TransportEndpointDescription.builder() |
| 277 | .withOutput(fcpPrimary).build(); |
| 278 | TransportEndpointDescription tedSecondary = TransportEndpointDescription.builder() |
| 279 | .withOutput(fcpSecondary).build(); |
| 280 | |
| 281 | TransportEndpointState tesPrimary = TransportEndpointState.builder() |
| 282 | .withDescription(tedPrimary) |
| 283 | .withId(TransportEndpointId.of(PRIMARY_ID)) |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 284 | .addAttributes(getProtectionStateAttributes(portPrimary)) |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 285 | .build(); |
| 286 | TransportEndpointState tesSecondary = TransportEndpointState.builder() |
| 287 | .withDescription(tedSecondary) |
| 288 | .withId(TransportEndpointId.of(SECONDARY_ID)) |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 289 | .addAttributes(getProtectionStateAttributes((portSecondary))) |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 290 | .build(); |
| 291 | |
| 292 | tess.add(tesPrimary); |
| 293 | tess.add(tesSecondary); |
| 294 | return ProtectedTransportEndpointState.builder() |
| 295 | .withDescription(getProtectedTransportEndpointDescription()) |
| 296 | .withPathStates(tess) |
MaoLu | a8998df | 2017-03-15 14:20:38 -0700 | [diff] [blame] | 297 | .withActivePathIndex(getActiveIndex(tess)) |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 298 | .build(); |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * - Protection switch is controlled by setting up flow on the device |
| 303 | * - There is only one flow on the device at any point |
| 304 | * - A flow from virtual port to client port indicates the device is in auto switch mode |
| 305 | * - A flow from primary port to client port indicates the device is manually switched to primary |
| 306 | * - A flow from secondary port to client port indicates the device is manually switched to secondary |
| 307 | */ |
| 308 | private void addFlow(PortNumber workingPort) { |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 309 | // set working port as flow's input port |
| 310 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 311 | .matchInPort(workingPort) |
| 312 | .build(); |
| 313 | // the flow's output port is always the clinet port |
| 314 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 315 | .setOutput(PortNumber.portNumber(CLIENT_PORT)) |
| 316 | .build(); |
| 317 | FlowRule flowRule = DefaultFlowRule.builder() |
| 318 | .forDevice(data().deviceId()) |
| 319 | .fromApp(handler().get(CoreService.class).getAppId(APP_ID)) |
| 320 | .withPriority(FLOWRULE_PRIORITY) |
| 321 | .withSelector(selector) |
| 322 | .withTreatment(treatment) |
| 323 | .makePermanent() |
| 324 | .build(); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 325 | |
| 326 | // install flow rule |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 327 | handler().get(FlowRuleService.class).applyFlowRules(flowRule); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 328 | } |
| 329 | /* |
| 330 | Delete all the flows to put device in default mode. |
| 331 | */ |
| 332 | private void deleteFlow() { |
| 333 | // remove all the flows. |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 334 | handler().get(FlowRuleService.class).purgeFlowRules(data().deviceId()); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | private void addLinkToPeer(DeviceId peerId) { |
| 338 | |
| 339 | if (peerId == null) { |
| 340 | log.warn("PeerID is null for device {}", data().deviceId()); |
| 341 | return; |
| 342 | } |
| 343 | ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT)); |
| 344 | ConnectPoint srcCp = new ConnectPoint(peerId, PortNumber.portNumber(VIRTUAL_PORT)); |
| 345 | LinkKey link = linkKey(srcCp, dstCp); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 346 | BasicLinkConfig cfg = handler().get(NetworkConfigService.class) |
| 347 | .addConfig(link, BasicLinkConfig.class); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 348 | cfg.type(Link.Type.VIRTUAL); |
| 349 | cfg.apply(); |
| 350 | } |
| 351 | |
| 352 | private void removeLinkToPeer(DeviceId peerId) { |
| 353 | if (peerId == null) { |
| 354 | log.warn("PeerID is null for device {}", data().deviceId()); |
| 355 | return; |
| 356 | } |
| 357 | ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT)); |
| 358 | ConnectPoint srcCp = new ConnectPoint(peerId, PortNumber.portNumber(VIRTUAL_PORT)); |
| 359 | LinkKey link = linkKey(srcCp, dstCp); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 360 | handler().get(NetworkConfigService.class).removeConfig(link, BasicLinkConfig.class); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | private DeviceId getPeerId() { |
| 364 | ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT)); |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 365 | Set<Link> links = handler().get(LinkService.class).getIngressLinks(dstCp); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 366 | |
| 367 | for (Link l : links) { |
| 368 | if (l.type() == Link.Type.VIRTUAL) { |
Frank Wang | 3a98e0a | 2017-08-11 11:09:30 +0800 | [diff] [blame^] | 369 | // this device is the destination and peer is the source. |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 370 | return l.src().deviceId(); |
| 371 | } |
| 372 | } |
| 373 | |
MaoLu | 937cf42 | 2017-03-03 23:31:46 -0800 | [diff] [blame] | 374 | return data().deviceId(); |
Jimmy Jin | 1085239 | 2017-01-24 13:45:13 -0800 | [diff] [blame] | 375 | } |
| 376 | } |