Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -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 | package org.onosproject.incubator.net.virtual.impl; |
| 17 | |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
Yoonseon Han | ffcc32f | 2017-05-03 14:42:17 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 26 | import org.onlab.osgi.DefaultServiceDirectory; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 27 | import org.onlab.osgi.ServiceDirectory; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 28 | import org.onlab.packet.IpAddress; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.packet.VlanId; |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 33 | import org.onosproject.incubator.net.tunnel.TunnelId; |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 34 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 35 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 36 | import org.onosproject.incubator.net.virtual.TenantId; |
| 37 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 38 | import org.onosproject.incubator.net.virtual.VirtualHost; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 39 | import org.onosproject.incubator.net.virtual.VirtualLink; |
| 40 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
| 41 | import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService; |
| 42 | import org.onosproject.incubator.net.virtual.VirtualNetworkEvent; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 43 | import org.onosproject.incubator.net.virtual.VirtualNetworkIntent; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 44 | import org.onosproject.incubator.net.virtual.VirtualNetworkListener; |
| 45 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
| 46 | import org.onosproject.incubator.net.virtual.VirtualNetworkStore; |
| 47 | import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; |
| 48 | import org.onosproject.incubator.net.virtual.VirtualPort; |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 49 | import org.onosproject.incubator.net.virtual.VnetService; |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 50 | import org.onosproject.incubator.net.virtual.event.VirtualEvent; |
| 51 | import org.onosproject.incubator.net.virtual.event.VirtualListenerRegistryManager; |
yoonseon | 6b972c3 | 2016-12-06 16:45:03 -0800 | [diff] [blame] | 52 | import org.onosproject.incubator.net.virtual.provider.VirtualNetworkProvider; |
| 53 | import org.onosproject.incubator.net.virtual.provider.VirtualNetworkProviderRegistry; |
| 54 | import org.onosproject.incubator.net.virtual.provider.VirtualNetworkProviderService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 55 | import org.onosproject.net.ConnectPoint; |
| 56 | import org.onosproject.net.DeviceId; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 57 | import org.onosproject.net.HostId; |
| 58 | import org.onosproject.net.HostLocation; |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 59 | import org.onosproject.net.Link; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 60 | import org.onosproject.net.PortNumber; |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 61 | import org.onosproject.net.device.DeviceService; |
Claudine Chiu | 70222ad | 2016-11-17 22:29:20 -0500 | [diff] [blame] | 62 | import org.onosproject.net.flow.FlowRuleService; |
yoonseon | 86bebed | 2017-02-03 15:23:57 -0800 | [diff] [blame] | 63 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 64 | import org.onosproject.net.group.GroupService; |
Claudine Chiu | 30a8a2a | 2016-07-14 17:09:04 -0400 | [diff] [blame] | 65 | import org.onosproject.net.host.HostService; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 66 | import org.onosproject.net.intent.IntentEvent; |
| 67 | import org.onosproject.net.intent.IntentListener; |
| 68 | import org.onosproject.net.intent.IntentService; |
| 69 | import org.onosproject.net.intent.IntentState; |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 70 | import org.onosproject.net.link.LinkService; |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 71 | import org.onosproject.net.packet.PacketService; |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 72 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
| 73 | import org.onosproject.net.provider.AbstractProviderService; |
Claudine Chiu | 45920dd | 2016-07-28 19:19:46 +0000 | [diff] [blame] | 74 | import org.onosproject.net.topology.PathService; |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 75 | import org.onosproject.net.topology.TopologyService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 76 | import org.slf4j.Logger; |
| 77 | import org.slf4j.LoggerFactory; |
| 78 | |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 79 | import java.util.Map; |
Claudine Chiu | e7f6b91 | 2017-02-24 14:13:30 -0500 | [diff] [blame] | 80 | import java.util.Objects; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 81 | import java.util.Set; |
| 82 | |
| 83 | import static com.google.common.base.Preconditions.checkNotNull; |
| 84 | |
| 85 | /** |
| 86 | * Implementation of the virtual network service. |
| 87 | */ |
| 88 | @Component(immediate = true) |
| 89 | @Service |
| 90 | public class VirtualNetworkManager |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 91 | extends AbstractListenerProviderRegistry<VirtualNetworkEvent, |
| 92 | VirtualNetworkListener, VirtualNetworkProvider, VirtualNetworkProviderService> |
| 93 | implements VirtualNetworkService, VirtualNetworkAdminService, |
| 94 | VirtualNetworkProviderRegistry { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 95 | |
| 96 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 97 | |
| 98 | private static final String TENANT_NULL = "Tenant ID cannot be null"; |
| 99 | private static final String NETWORK_NULL = "Network ID cannot be null"; |
| 100 | private static final String DEVICE_NULL = "Device ID cannot be null"; |
| 101 | private static final String LINK_POINT_NULL = "Link end-point cannot be null"; |
| 102 | |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 103 | private static final String VIRTUAL_NETWORK_APP_ID_STRING = |
| 104 | "org.onosproject.virtual-network"; |
| 105 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 107 | protected VirtualNetworkStore store; |
| 108 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 110 | protected IntentService intentService; |
| 111 | |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 113 | protected CoreService coreService; |
| 114 | |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 115 | private final InternalVirtualIntentListener intentListener = |
| 116 | new InternalVirtualIntentListener(); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 117 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 118 | private VirtualNetworkStoreDelegate delegate = this::post; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 119 | |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 120 | private ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 121 | private ApplicationId appId; |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 122 | |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 123 | // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 124 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 125 | /** |
| 126 | * Only used for Junit test methods outside of this package. |
| 127 | * |
| 128 | * @param store virtual network store |
| 129 | */ |
| 130 | public void setStore(VirtualNetworkStore store) { |
| 131 | this.store = store; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Only used for Junit test methods outside of this package. |
| 136 | * |
| 137 | * @param intentService intent service |
| 138 | */ |
| 139 | |
| 140 | public void setIntentService(IntentService intentService) { |
| 141 | this.intentService = intentService; |
| 142 | } |
| 143 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 144 | @Activate |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 145 | public void activate() { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 146 | eventDispatcher.addSink(VirtualNetworkEvent.class, listenerRegistry); |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 147 | eventDispatcher.addSink(VirtualEvent.class, |
| 148 | VirtualListenerRegistryManager.getInstance()); |
Yoonseon Han | b14461b | 2017-03-07 14:08:01 +0900 | [diff] [blame] | 149 | store.setDelegate(delegate); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 150 | intentService.addListener(intentListener); |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 151 | appId = coreService.registerApplication(VIRTUAL_NETWORK_APP_ID_STRING); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 152 | log.info("Started"); |
| 153 | } |
| 154 | |
| 155 | @Deactivate |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 156 | public void deactivate() { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 157 | store.unsetDelegate(delegate); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 158 | eventDispatcher.removeSink(VirtualNetworkEvent.class); |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 159 | eventDispatcher.removeSink(VirtualEvent.class); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 160 | intentService.removeListener(intentListener); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 161 | log.info("Stopped"); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void registerTenantId(TenantId tenantId) { |
| 166 | checkNotNull(tenantId, TENANT_NULL); |
| 167 | store.addTenantId(tenantId); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void unregisterTenantId(TenantId tenantId) { |
| 172 | checkNotNull(tenantId, TENANT_NULL); |
| 173 | store.removeTenantId(tenantId); |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public Set<TenantId> getTenantIds() { |
| 178 | return store.getTenantIds(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public VirtualNetwork createVirtualNetwork(TenantId tenantId) { |
| 183 | checkNotNull(tenantId, TENANT_NULL); |
| 184 | return store.addNetwork(tenantId); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public void removeVirtualNetwork(NetworkId networkId) { |
| 189 | checkNotNull(networkId, NETWORK_NULL); |
| 190 | store.removeNetwork(networkId); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public VirtualDevice createVirtualDevice(NetworkId networkId, DeviceId deviceId) { |
| 195 | checkNotNull(networkId, NETWORK_NULL); |
| 196 | checkNotNull(deviceId, DEVICE_NULL); |
| 197 | return store.addDevice(networkId, deviceId); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void removeVirtualDevice(NetworkId networkId, DeviceId deviceId) { |
| 202 | checkNotNull(networkId, NETWORK_NULL); |
| 203 | checkNotNull(deviceId, DEVICE_NULL); |
| 204 | store.removeDevice(networkId, deviceId); |
| 205 | } |
| 206 | |
| 207 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 208 | public VirtualHost createVirtualHost(NetworkId networkId, HostId hostId, |
| 209 | MacAddress mac, VlanId vlan, |
| 210 | HostLocation location, Set<IpAddress> ips) { |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 211 | checkNotNull(networkId, NETWORK_NULL); |
| 212 | checkNotNull(hostId, DEVICE_NULL); |
| 213 | return store.addHost(networkId, hostId, mac, vlan, location, ips); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void removeVirtualHost(NetworkId networkId, HostId hostId) { |
| 218 | checkNotNull(networkId, NETWORK_NULL); |
| 219 | checkNotNull(hostId, DEVICE_NULL); |
| 220 | store.removeHost(networkId, hostId); |
| 221 | } |
| 222 | |
| 223 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 224 | public VirtualLink createVirtualLink(NetworkId networkId, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 225 | ConnectPoint src, ConnectPoint dst) { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 226 | checkNotNull(networkId, NETWORK_NULL); |
| 227 | checkNotNull(src, LINK_POINT_NULL); |
| 228 | checkNotNull(dst, LINK_POINT_NULL); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 229 | ConnectPoint physicalSrc = mapVirtualToPhysicalPort(networkId, src); |
| 230 | checkNotNull(physicalSrc, LINK_POINT_NULL); |
| 231 | ConnectPoint physicalDst = mapVirtualToPhysicalPort(networkId, dst); |
| 232 | checkNotNull(physicalDst, LINK_POINT_NULL); |
| 233 | |
| 234 | VirtualNetworkProvider provider = getProvider(DefaultVirtualLink.PID); |
| 235 | Link.State state = Link.State.INACTIVE; |
| 236 | if (provider != null) { |
| 237 | boolean traversable = provider.isTraversable(physicalSrc, physicalDst); |
| 238 | state = traversable ? Link.State.ACTIVE : Link.State.INACTIVE; |
| 239 | } |
| 240 | return store.addLink(networkId, src, dst, state, null); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Maps the virtual connect point to a physical connect point. |
| 245 | * |
| 246 | * @param networkId network identifier |
| 247 | * @param virtualCp virtual connect point |
| 248 | * @return physical connect point |
| 249 | */ |
| 250 | private ConnectPoint mapVirtualToPhysicalPort(NetworkId networkId, |
| 251 | ConnectPoint virtualCp) { |
| 252 | Set<VirtualPort> ports = store.getPorts(networkId, virtualCp.deviceId()); |
| 253 | for (VirtualPort port : ports) { |
| 254 | if (port.number().equals(virtualCp.port())) { |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 255 | return new ConnectPoint(port.realizedBy().deviceId(), |
| 256 | port.realizedBy().port()); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | return null; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 262 | /** |
| 263 | * Maps the physical connect point to a virtual connect point. |
| 264 | * |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 265 | * @param networkId network identifier |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 266 | * @param physicalCp physical connect point |
| 267 | * @return virtual connect point |
| 268 | */ |
| 269 | private ConnectPoint mapPhysicalToVirtualToPort(NetworkId networkId, |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 270 | ConnectPoint physicalCp) { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 271 | Set<VirtualPort> ports = store.getPorts(networkId, null); |
| 272 | for (VirtualPort port : ports) { |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 273 | if (port.realizedBy().deviceId().equals(physicalCp.elementId()) && |
| 274 | port.realizedBy().port().equals(physicalCp.port())) { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 275 | return new ConnectPoint(port.element().id(), port.number()); |
| 276 | } |
| 277 | } |
| 278 | return null; |
| 279 | } |
| 280 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 281 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 282 | public void removeVirtualLink(NetworkId networkId, ConnectPoint src, |
| 283 | ConnectPoint dst) { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 284 | checkNotNull(networkId, NETWORK_NULL); |
| 285 | checkNotNull(src, LINK_POINT_NULL); |
| 286 | checkNotNull(dst, LINK_POINT_NULL); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 287 | store.removeLink(networkId, src, dst); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId, |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 292 | PortNumber portNumber, ConnectPoint realizedBy) { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 293 | checkNotNull(networkId, NETWORK_NULL); |
| 294 | checkNotNull(deviceId, DEVICE_NULL); |
| 295 | checkNotNull(portNumber, "Port description cannot be null"); |
| 296 | return store.addPort(networkId, deviceId, portNumber, realizedBy); |
| 297 | } |
| 298 | |
| 299 | @Override |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 300 | public void bindVirtualPort(NetworkId networkId, DeviceId deviceId, |
| 301 | PortNumber portNumber, ConnectPoint realizedBy) { |
| 302 | checkNotNull(networkId, NETWORK_NULL); |
| 303 | checkNotNull(deviceId, DEVICE_NULL); |
| 304 | checkNotNull(portNumber, "Port description cannot be null"); |
| 305 | checkNotNull(realizedBy, "Physical port description cannot be null"); |
| 306 | |
| 307 | store.bindPort(networkId, deviceId, portNumber, realizedBy); |
| 308 | } |
| 309 | |
| 310 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 311 | public void removeVirtualPort(NetworkId networkId, DeviceId deviceId, |
| 312 | PortNumber portNumber) { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 313 | checkNotNull(networkId, NETWORK_NULL); |
| 314 | checkNotNull(deviceId, DEVICE_NULL); |
| 315 | checkNotNull(portNumber, "Port number cannot be null"); |
| 316 | store.removePort(networkId, deviceId, portNumber); |
| 317 | } |
| 318 | |
| 319 | @Override |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 320 | public ServiceDirectory getServiceDirectory() { |
| 321 | return serviceDirectory; |
| 322 | } |
| 323 | |
| 324 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 325 | public Set<VirtualNetwork> getVirtualNetworks(TenantId tenantId) { |
| 326 | checkNotNull(tenantId, TENANT_NULL); |
| 327 | return store.getNetworks(tenantId); |
| 328 | } |
| 329 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 330 | /** |
| 331 | * Returns the virtual network matching the network identifier. |
| 332 | * |
| 333 | * @param networkId network identifier |
| 334 | * @return virtual network |
| 335 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 336 | private VirtualNetwork getVirtualNetwork(NetworkId networkId) { |
| 337 | checkNotNull(networkId, NETWORK_NULL); |
| 338 | return store.getNetwork(networkId); |
| 339 | } |
| 340 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 341 | @Override |
| 342 | public Set<VirtualDevice> getVirtualDevices(NetworkId networkId) { |
| 343 | checkNotNull(networkId, NETWORK_NULL); |
| 344 | return store.getDevices(networkId); |
| 345 | } |
| 346 | |
| 347 | @Override |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 348 | public Set<VirtualHost> getVirtualHosts(NetworkId networkId) { |
| 349 | checkNotNull(networkId, NETWORK_NULL); |
| 350 | return store.getHosts(networkId); |
| 351 | } |
| 352 | |
| 353 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 354 | public Set<VirtualLink> getVirtualLinks(NetworkId networkId) { |
| 355 | checkNotNull(networkId, NETWORK_NULL); |
| 356 | return store.getLinks(networkId); |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) { |
| 361 | checkNotNull(networkId, NETWORK_NULL); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 362 | return store.getPorts(networkId, deviceId); |
| 363 | } |
| 364 | |
Yoonseon Han | ffcc32f | 2017-05-03 14:42:17 -0700 | [diff] [blame] | 365 | @Override |
| 366 | public Set<DeviceId> getPhysicalDevices(NetworkId networkId, |
| 367 | VirtualDevice virtualDevice) { |
| 368 | checkNotNull(networkId, "Network ID cannot be null"); |
| 369 | checkNotNull(virtualDevice, "Virtual device cannot be null"); |
| 370 | Set<VirtualPort> virtualPortSet = |
| 371 | getVirtualPorts(networkId, virtualDevice.id()); |
| 372 | Set<DeviceId> physicalDeviceSet = Sets.newConcurrentHashSet(); |
| 373 | |
| 374 | virtualPortSet.forEach(virtualPort -> { |
| 375 | if (virtualPort.realizedBy() != null) { |
| 376 | physicalDeviceSet.add(virtualPort.realizedBy().deviceId()); |
| 377 | } |
| 378 | }); |
| 379 | |
| 380 | return physicalDeviceSet; |
| 381 | } |
| 382 | |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 383 | private final Map<ServiceKey, VnetService> networkServices = Maps.newConcurrentMap(); |
| 384 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 385 | @Override |
Yoonseon Han | b14461b | 2017-03-07 14:08:01 +0900 | [diff] [blame] | 386 | @SuppressWarnings("unchecked") |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 387 | public <T> T get(NetworkId networkId, Class<T> serviceClass) { |
| 388 | checkNotNull(networkId, NETWORK_NULL); |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 389 | ServiceKey serviceKey = networkServiceKey(networkId, serviceClass); |
| 390 | VnetService service = lookup(serviceKey); |
| 391 | if (service == null) { |
| 392 | service = create(serviceKey); |
| 393 | } |
| 394 | return (T) service; |
| 395 | } |
| 396 | |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 397 | @Override |
| 398 | public ApplicationId getVirtualNetworkApplicationId(NetworkId networkId) { |
| 399 | return appId; |
| 400 | } |
| 401 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 402 | /** |
| 403 | * Returns the Vnet service matching the service key. |
| 404 | * |
| 405 | * @param serviceKey service key |
| 406 | * @return vnet service |
| 407 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 408 | private VnetService lookup(ServiceKey serviceKey) { |
| 409 | return networkServices.get(serviceKey); |
| 410 | } |
| 411 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 412 | /** |
| 413 | * Creates a new service key using the specified network identifier and service class. |
| 414 | * |
| 415 | * @param networkId network identifier |
| 416 | * @param serviceClass service class |
| 417 | * @param <T> type of service |
| 418 | * @return service key |
| 419 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 420 | private <T> ServiceKey networkServiceKey(NetworkId networkId, Class<T> serviceClass) { |
| 421 | return new ServiceKey(networkId, serviceClass); |
| 422 | } |
| 423 | |
| 424 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 425 | /** |
| 426 | * Create a new vnet service instance. |
| 427 | * |
| 428 | * @param serviceKey service key |
| 429 | * @return vnet service |
| 430 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 431 | private VnetService create(ServiceKey serviceKey) { |
| 432 | VirtualNetwork network = getVirtualNetwork(serviceKey.networkId()); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 433 | checkNotNull(network, NETWORK_NULL); |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 434 | |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 435 | VnetService service; |
| 436 | if (serviceKey.serviceClass.equals(DeviceService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 437 | service = new VirtualNetworkDeviceManager(this, network.id()); |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 438 | } else if (serviceKey.serviceClass.equals(LinkService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 439 | service = new VirtualNetworkLinkManager(this, network.id()); |
Brian Stanke | 8e9f8d1 | 2016-06-08 14:48:33 -0400 | [diff] [blame] | 440 | } else if (serviceKey.serviceClass.equals(TopologyService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 441 | service = new VirtualNetworkTopologyManager(this, network.id()); |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 442 | } else if (serviceKey.serviceClass.equals(IntentService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 443 | service = new VirtualNetworkIntentManager(this, network.id()); |
Claudine Chiu | 30a8a2a | 2016-07-14 17:09:04 -0400 | [diff] [blame] | 444 | } else if (serviceKey.serviceClass.equals(HostService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 445 | service = new VirtualNetworkHostManager(this, network.id()); |
Claudine Chiu | 45920dd | 2016-07-28 19:19:46 +0000 | [diff] [blame] | 446 | } else if (serviceKey.serviceClass.equals(PathService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 447 | service = new VirtualNetworkPathManager(this, network.id()); |
Claudine Chiu | 70222ad | 2016-11-17 22:29:20 -0500 | [diff] [blame] | 448 | } else if (serviceKey.serviceClass.equals(FlowRuleService.class)) { |
yoonseon | c6a6927 | 2017-01-12 18:22:20 -0800 | [diff] [blame] | 449 | service = new VirtualNetworkFlowRuleManager(this, network.id()); |
yoonseon | 322c9c3 | 2016-12-07 16:47:02 -0800 | [diff] [blame] | 450 | } else if (serviceKey.serviceClass.equals(PacketService.class)) { |
| 451 | service = new VirtualNetworkPacketManager(this, network.id()); |
yoonseon | dc3210d | 2017-01-25 16:03:10 -0800 | [diff] [blame] | 452 | } else if (serviceKey.serviceClass.equals(GroupService.class)) { |
| 453 | service = new VirtualNetworkGroupManager(this, network.id()); |
yoonseon | 86bebed | 2017-02-03 15:23:57 -0800 | [diff] [blame] | 454 | } else if (serviceKey.serviceClass.equals(FlowObjectiveService.class)) { |
| 455 | service = new VirtualNetworkFlowObjectiveManager(this, network.id()); |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 456 | } else { |
| 457 | return null; |
| 458 | } |
| 459 | networkServices.put(serviceKey, service); |
| 460 | return service; |
| 461 | } |
| 462 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 463 | /** |
| 464 | * Service key class. |
| 465 | */ |
Claudine Chiu | 9a18f49 | 2017-02-27 15:57:06 -0500 | [diff] [blame] | 466 | private static class ServiceKey { |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 467 | final NetworkId networkId; |
| 468 | final Class serviceClass; |
| 469 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 470 | /** |
| 471 | * Constructor for service key. |
| 472 | * |
| 473 | * @param networkId network identifier |
| 474 | * @param serviceClass service class |
| 475 | */ |
Yoonseon Han | b14461b | 2017-03-07 14:08:01 +0900 | [diff] [blame] | 476 | ServiceKey(NetworkId networkId, Class serviceClass) { |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 477 | |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 478 | checkNotNull(networkId, NETWORK_NULL); |
| 479 | this.networkId = networkId; |
| 480 | this.serviceClass = serviceClass; |
| 481 | } |
| 482 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 483 | /** |
| 484 | * Returns the network identifier. |
| 485 | * |
| 486 | * @return network identifier |
| 487 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 488 | public NetworkId networkId() { |
| 489 | return networkId; |
| 490 | } |
| 491 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 492 | /** |
| 493 | * Returns the service class. |
| 494 | * |
| 495 | * @return service class |
| 496 | */ |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 497 | public Class serviceClass() { |
| 498 | return serviceClass; |
| 499 | } |
Claudine Chiu | e7f6b91 | 2017-02-24 14:13:30 -0500 | [diff] [blame] | 500 | |
| 501 | @Override |
| 502 | public int hashCode() { |
| 503 | return Objects.hash(networkId, serviceClass); |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public boolean equals(Object obj) { |
| 508 | if (this == obj) { |
| 509 | return true; |
| 510 | } |
| 511 | if (obj instanceof ServiceKey) { |
| 512 | ServiceKey that = (ServiceKey) obj; |
| 513 | return Objects.equals(this.networkId, that.networkId) && |
| 514 | Objects.equals(this.serviceClass, that.serviceClass); |
| 515 | } |
| 516 | return false; |
| 517 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 520 | /** |
| 521 | * Internal intent event listener. |
| 522 | */ |
| 523 | private class InternalVirtualIntentListener implements IntentListener { |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 524 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 525 | @Override |
| 526 | public void event(IntentEvent event) { |
| 527 | |
| 528 | // Ignore intent events that are not relevant. |
| 529 | if (!isRelevant(event)) { |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | VirtualNetworkIntent intent = (VirtualNetworkIntent) event.subject(); |
| 534 | |
| 535 | switch (event.type()) { |
| 536 | case INSTALL_REQ: |
| 537 | store.addOrUpdateIntent(intent, IntentState.INSTALL_REQ); |
| 538 | break; |
| 539 | case INSTALLED: |
| 540 | store.addOrUpdateIntent(intent, IntentState.INSTALLED); |
| 541 | break; |
| 542 | case WITHDRAW_REQ: |
| 543 | store.addOrUpdateIntent(intent, IntentState.WITHDRAW_REQ); |
| 544 | break; |
| 545 | case WITHDRAWN: |
| 546 | store.addOrUpdateIntent(intent, IntentState.WITHDRAWN); |
| 547 | break; |
| 548 | case FAILED: |
| 549 | store.addOrUpdateIntent(intent, IntentState.FAILED); |
| 550 | break; |
| 551 | case CORRUPT: |
| 552 | store.addOrUpdateIntent(intent, IntentState.CORRUPT); |
| 553 | break; |
| 554 | case PURGED: |
| 555 | store.removeIntent(intent.key()); |
| 556 | default: |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public boolean isRelevant(IntentEvent event) { |
| 563 | if (event.subject() instanceof VirtualNetworkIntent) { |
| 564 | return true; |
| 565 | } |
| 566 | return false; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 571 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 572 | protected VirtualNetworkProviderService |
| 573 | createProviderService(VirtualNetworkProvider provider) { |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 574 | return new InternalVirtualNetworkProviderService(provider); |
| 575 | } |
| 576 | |
yoonseon | 6b972c3 | 2016-12-06 16:45:03 -0800 | [diff] [blame] | 577 | |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 578 | /** |
| 579 | * Service issued to registered virtual network providers so that they |
| 580 | * can interact with the core. |
| 581 | */ |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 582 | private class InternalVirtualNetworkProviderService |
| 583 | extends AbstractProviderService<VirtualNetworkProvider> |
| 584 | implements VirtualNetworkProviderService { |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 585 | /** |
| 586 | * Constructor. |
| 587 | * @param provider virtual network provider |
| 588 | */ |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 589 | InternalVirtualNetworkProviderService(VirtualNetworkProvider provider) { |
| 590 | super(provider); |
| 591 | } |
Brian Stanke | 4d57988 | 2016-04-22 13:28:46 -0400 | [diff] [blame] | 592 | |
| 593 | @Override |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 594 | public void topologyChanged(Set<Set<ConnectPoint>> clusters) { |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 595 | Set<TenantId> tenantIds = getTenantIds(); |
| 596 | tenantIds.forEach(tenantId -> { |
| 597 | Set<VirtualNetwork> virtualNetworks = getVirtualNetworks(tenantId); |
| 598 | |
| 599 | virtualNetworks.forEach(virtualNetwork -> { |
| 600 | Set<VirtualLink> virtualLinks = getVirtualLinks(virtualNetwork.id()); |
| 601 | |
| 602 | virtualLinks.forEach(virtualLink -> { |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 603 | if (isVirtualLinkInCluster(virtualNetwork.id(), |
| 604 | virtualLink, clusters)) { |
| 605 | store.updateLink(virtualLink, virtualLink.tunnelId(), |
| 606 | Link.State.ACTIVE); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 607 | } else { |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 608 | store.updateLink(virtualLink, virtualLink.tunnelId(), |
| 609 | Link.State.INACTIVE); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 610 | } |
| 611 | }); |
| 612 | }); |
| 613 | }); |
| 614 | } |
| 615 | |
| 616 | /** |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 617 | * Determines if the virtual link (both source and destination connect point) |
| 618 | * is in a cluster. |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 619 | * |
| 620 | * @param networkId virtual network identifier |
| 621 | * @param virtualLink virtual link |
| 622 | * @param clusters topology clusters |
| 623 | * @return true if the virtual link is in a cluster. |
| 624 | */ |
| 625 | private boolean isVirtualLinkInCluster(NetworkId networkId, VirtualLink virtualLink, |
| 626 | Set<Set<ConnectPoint>> clusters) { |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 627 | ConnectPoint srcPhysicalCp = |
| 628 | mapVirtualToPhysicalPort(networkId, virtualLink.src()); |
| 629 | ConnectPoint dstPhysicalCp = |
| 630 | mapVirtualToPhysicalPort(networkId, virtualLink.dst()); |
Brian Stanke | fb61df4 | 2016-07-25 11:47:51 -0400 | [diff] [blame] | 631 | |
| 632 | final boolean[] foundSrc = {false}; |
| 633 | final boolean[] foundDst = {false}; |
| 634 | clusters.forEach(connectPoints -> { |
| 635 | connectPoints.forEach(connectPoint -> { |
| 636 | if (connectPoint.equals(srcPhysicalCp)) { |
| 637 | foundSrc[0] = true; |
| 638 | } else if (connectPoint.equals(dstPhysicalCp)) { |
| 639 | foundDst[0] = true; |
| 640 | } |
| 641 | }); |
| 642 | if (foundSrc[0] && foundDst[0]) { |
| 643 | return; |
| 644 | } |
| 645 | }); |
| 646 | return foundSrc[0] && foundDst[0]; |
| 647 | } |
| 648 | |
| 649 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 650 | public void tunnelUp(NetworkId networkId, ConnectPoint src, |
| 651 | ConnectPoint dst, TunnelId tunnelId) { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 652 | ConnectPoint srcVirtualCp = mapPhysicalToVirtualToPort(networkId, src); |
| 653 | ConnectPoint dstVirtualCp = mapPhysicalToVirtualToPort(networkId, dst); |
| 654 | if ((srcVirtualCp == null) || (dstVirtualCp == null)) { |
| 655 | log.error("Src or dst virtual connection point was not found."); |
| 656 | } |
| 657 | |
| 658 | VirtualLink virtualLink = store.getLink(networkId, srcVirtualCp, dstVirtualCp); |
| 659 | if (virtualLink != null) { |
| 660 | store.updateLink(virtualLink, tunnelId, Link.State.ACTIVE); |
| 661 | } |
Brian Stanke | 4d57988 | 2016-04-22 13:28:46 -0400 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | @Override |
yoonseon | 214963b | 2016-11-21 15:41:07 -0800 | [diff] [blame] | 665 | public void tunnelDown(NetworkId networkId, ConnectPoint src, |
| 666 | ConnectPoint dst, TunnelId tunnelId) { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 667 | ConnectPoint srcVirtualCp = mapPhysicalToVirtualToPort(networkId, src); |
| 668 | ConnectPoint dstVirtualCp = mapPhysicalToVirtualToPort(networkId, dst); |
| 669 | if ((srcVirtualCp == null) || (dstVirtualCp == null)) { |
| 670 | log.error("Src or dst virtual connection point was not found."); |
| 671 | } |
Brian Stanke | 4d57988 | 2016-04-22 13:28:46 -0400 | [diff] [blame] | 672 | |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 673 | VirtualLink virtualLink = store.getLink(networkId, srcVirtualCp, dstVirtualCp); |
| 674 | if (virtualLink != null) { |
| 675 | store.updateLink(virtualLink, tunnelId, Link.State.INACTIVE); |
| 676 | } |
Brian Stanke | 4d57988 | 2016-04-22 13:28:46 -0400 | [diff] [blame] | 677 | } |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 678 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 679 | } |