Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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.store.virtual.impl; |
| 17 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
| 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; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Service; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 29 | import org.onlab.util.KryoNamespace; |
| 30 | import org.onosproject.core.CoreService; |
| 31 | import org.onosproject.core.IdGenerator; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 32 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 33 | import org.onosproject.incubator.net.virtual.DefaultVirtualDevice; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 34 | import org.onosproject.incubator.net.virtual.DefaultVirtualHost; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 35 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 36 | import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 37 | import org.onosproject.incubator.net.virtual.DefaultVirtualPort; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 38 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 39 | import org.onosproject.incubator.net.virtual.TenantId; |
| 40 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 41 | import org.onosproject.incubator.net.virtual.VirtualHost; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 42 | import org.onosproject.incubator.net.virtual.VirtualLink; |
| 43 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
| 44 | import org.onosproject.incubator.net.virtual.VirtualNetworkEvent; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 45 | import org.onosproject.incubator.net.virtual.VirtualNetworkIntent; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 46 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 47 | import org.onosproject.incubator.net.virtual.VirtualNetworkStore; |
| 48 | import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; |
| 49 | import org.onosproject.incubator.net.virtual.VirtualPort; |
| 50 | import org.onosproject.net.ConnectPoint; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 51 | import org.onosproject.net.Device; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 52 | import org.onosproject.net.DeviceId; |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 53 | import org.onosproject.net.HostId; |
| 54 | import org.onosproject.net.HostLocation; |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 55 | import org.onosproject.net.Link; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 56 | import org.onosproject.net.PortNumber; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 57 | import org.onosproject.net.intent.Intent; |
| 58 | import org.onosproject.net.intent.IntentData; |
| 59 | import org.onosproject.net.intent.IntentState; |
| 60 | import org.onosproject.net.intent.Key; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 61 | import org.onosproject.store.AbstractStore; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 62 | import org.onosproject.store.serializers.KryoNamespaces; |
| 63 | import org.onosproject.store.service.ConsistentMap; |
| 64 | import org.onosproject.store.service.DistributedSet; |
| 65 | import org.onosproject.store.service.MapEvent; |
| 66 | import org.onosproject.store.service.MapEventListener; |
| 67 | import org.onosproject.store.service.Serializer; |
| 68 | import org.onosproject.store.service.SetEvent; |
| 69 | import org.onosproject.store.service.SetEventListener; |
| 70 | import org.onosproject.store.service.StorageService; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 71 | import org.onosproject.store.service.WallClockTimestamp; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 72 | import org.slf4j.Logger; |
| 73 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 74 | import java.util.HashSet; |
| 75 | import java.util.Map; |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 76 | import java.util.Optional; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 77 | import java.util.Set; |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 78 | import java.util.concurrent.atomic.AtomicBoolean; |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 79 | import java.util.function.BiFunction; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 80 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 81 | import static com.google.common.base.Preconditions.checkNotNull; |
| 82 | import static com.google.common.base.Preconditions.checkState; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 83 | import static org.slf4j.LoggerFactory.getLogger; |
| 84 | |
| 85 | /** |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 86 | * Implementation of the virtual network store. |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 87 | */ |
| 88 | @Component(immediate = true) |
| 89 | @Service |
| 90 | public class DistributedVirtualNetworkStore |
| 91 | extends AbstractStore<VirtualNetworkEvent, VirtualNetworkStoreDelegate> |
| 92 | implements VirtualNetworkStore { |
| 93 | |
| 94 | private final Logger log = getLogger(getClass()); |
| 95 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 96 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 97 | protected StorageService storageService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 98 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 100 | protected CoreService coreService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 101 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 102 | private IdGenerator idGenerator; |
| 103 | |
| 104 | // Track tenants by ID |
| 105 | private DistributedSet<TenantId> tenantIdSet; |
| 106 | |
| 107 | // Listener for tenant events |
| 108 | private final SetEventListener<TenantId> setListener = new InternalSetListener(); |
| 109 | |
| 110 | // Track virtual networks by network Id |
| 111 | private ConsistentMap<NetworkId, VirtualNetwork> networkIdVirtualNetworkConsistentMap; |
| 112 | private Map<NetworkId, VirtualNetwork> networkIdVirtualNetworkMap; |
| 113 | |
| 114 | // Listener for virtual network events |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 115 | private final MapEventListener<NetworkId, VirtualNetwork> virtualNetworkMapListener = |
| 116 | new InternalMapListener<>((mapEventType, virtualNetwork) -> { |
| 117 | VirtualNetworkEvent.Type eventType = |
sangyun-han | 3c3e99e | 2017-02-08 15:30:53 +0900 | [diff] [blame] | 118 | mapEventType.equals(MapEvent.Type.INSERT) |
| 119 | ? VirtualNetworkEvent.Type.NETWORK_ADDED : |
| 120 | mapEventType.equals(MapEvent.Type.UPDATE) |
| 121 | ? VirtualNetworkEvent.Type.NETWORK_UPDATED : |
| 122 | mapEventType.equals(MapEvent.Type.REMOVE) |
| 123 | ? VirtualNetworkEvent.Type.NETWORK_REMOVED : null; |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 124 | return eventType == null ? null : new VirtualNetworkEvent(eventType, virtualNetwork.id()); |
| 125 | }); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 126 | |
sangyun-han | 3c3e99e | 2017-02-08 15:30:53 +0900 | [diff] [blame] | 127 | // Listener for virtual device events |
| 128 | private final MapEventListener<DeviceId, VirtualDevice> virtualDeviceMapListener = |
| 129 | new InternalMapListener<>((mapEventType, virtualDevice) -> { |
| 130 | VirtualNetworkEvent.Type eventType = |
| 131 | mapEventType.equals(MapEvent.Type.INSERT) |
| 132 | ? VirtualNetworkEvent.Type.VIRTUAL_DEVICE_ADDED : |
| 133 | mapEventType.equals(MapEvent.Type.UPDATE) |
| 134 | ? VirtualNetworkEvent.Type.VIRTUAL_DEVICE_UPDATED : |
| 135 | mapEventType.equals(MapEvent.Type.REMOVE) |
| 136 | ? VirtualNetworkEvent.Type.VIRTUAL_DEVICE_REMOVED : null; |
| 137 | return eventType == null ? null : |
| 138 | new VirtualNetworkEvent(eventType, virtualDevice.networkId(), virtualDevice); |
| 139 | }); |
| 140 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 141 | // Track virtual network IDs by tenant Id |
| 142 | private ConsistentMap<TenantId, Set<NetworkId>> tenantIdNetworkIdSetConsistentMap; |
| 143 | private Map<TenantId, Set<NetworkId>> tenantIdNetworkIdSetMap; |
| 144 | |
| 145 | // Track virtual devices by device Id |
| 146 | private ConsistentMap<DeviceId, VirtualDevice> deviceIdVirtualDeviceConsistentMap; |
| 147 | private Map<DeviceId, VirtualDevice> deviceIdVirtualDeviceMap; |
| 148 | |
| 149 | // Track device IDs by network Id |
| 150 | private ConsistentMap<NetworkId, Set<DeviceId>> networkIdDeviceIdSetConsistentMap; |
| 151 | private Map<NetworkId, Set<DeviceId>> networkIdDeviceIdSetMap; |
| 152 | |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 153 | // Track virtual hosts by host Id |
| 154 | private ConsistentMap<HostId, VirtualHost> hostIdVirtualHostConsistentMap; |
| 155 | private Map<HostId, VirtualHost> hostIdVirtualHostMap; |
| 156 | |
| 157 | // Track host IDs by network Id |
| 158 | private ConsistentMap<NetworkId, Set<HostId>> networkIdHostIdSetConsistentMap; |
| 159 | private Map<NetworkId, Set<HostId>> networkIdHostIdSetMap; |
| 160 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 161 | // Track virtual links by network Id |
| 162 | private ConsistentMap<NetworkId, Set<VirtualLink>> networkIdVirtualLinkSetConsistentMap; |
| 163 | private Map<NetworkId, Set<VirtualLink>> networkIdVirtualLinkSetMap; |
| 164 | |
| 165 | // Track virtual ports by network Id |
| 166 | private ConsistentMap<NetworkId, Set<VirtualPort>> networkIdVirtualPortSetConsistentMap; |
| 167 | private Map<NetworkId, Set<VirtualPort>> networkIdVirtualPortSetMap; |
| 168 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 169 | // Track intent key to intent data |
| 170 | private ConsistentMap<Key, IntentData> intentKeyIntentDataConsistentMap; |
| 171 | private Map<Key, IntentData> intentKeyIntentDataMap; |
| 172 | |
| 173 | // Track intent ID to TunnelIds |
| 174 | private ConsistentMap<Key, Set<TunnelId>> intentKeyTunnelIdSetConsistentMap; |
| 175 | private Map<Key, Set<TunnelId>> intentKeyTunnelIdSetMap; |
| 176 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 177 | private static final Serializer SERIALIZER = Serializer |
| 178 | .using(new KryoNamespace.Builder().register(KryoNamespaces.API) |
| 179 | .register(TenantId.class) |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 180 | .register(NetworkId.class) |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 181 | .register(VirtualNetwork.class) |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 182 | .register(DefaultVirtualNetwork.class) |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 183 | .register(VirtualDevice.class) |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 184 | .register(DefaultVirtualDevice.class) |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 185 | .register(VirtualHost.class) |
| 186 | .register(DefaultVirtualHost.class) |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 187 | .register(VirtualLink.class) |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 188 | .register(DefaultVirtualLink.class) |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 189 | .register(VirtualPort.class) |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 190 | .register(DefaultVirtualPort.class) |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 191 | .register(Device.class) |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 192 | .register(TunnelId.class) |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 193 | .register(IntentData.class) |
| 194 | .register(VirtualNetworkIntent.class) |
| 195 | .register(WallClockTimestamp.class) |
HIGUCHI Yuta | 03666a3 | 2016-05-18 11:49:09 -0700 | [diff] [blame] | 196 | .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID) |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 197 | .build()); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Distributed network store service activate method. |
| 201 | */ |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 202 | @Activate |
| 203 | public void activate() { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 204 | idGenerator = coreService.getIdGenerator(VirtualNetworkService.VIRTUAL_NETWORK_TOPIC); |
| 205 | |
| 206 | tenantIdSet = storageService.<TenantId>setBuilder() |
| 207 | .withSerializer(SERIALIZER) |
| 208 | .withName("onos-tenantId") |
| 209 | .withRelaxedReadConsistency() |
| 210 | .build() |
| 211 | .asDistributedSet(); |
| 212 | tenantIdSet.addListener(setListener); |
| 213 | |
| 214 | networkIdVirtualNetworkConsistentMap = storageService.<NetworkId, VirtualNetwork>consistentMapBuilder() |
| 215 | .withSerializer(SERIALIZER) |
| 216 | .withName("onos-networkId-virtualnetwork") |
| 217 | .withRelaxedReadConsistency() |
| 218 | .build(); |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 219 | networkIdVirtualNetworkConsistentMap.addListener(virtualNetworkMapListener); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 220 | networkIdVirtualNetworkMap = networkIdVirtualNetworkConsistentMap.asJavaMap(); |
| 221 | |
| 222 | tenantIdNetworkIdSetConsistentMap = storageService.<TenantId, Set<NetworkId>>consistentMapBuilder() |
| 223 | .withSerializer(SERIALIZER) |
| 224 | .withName("onos-tenantId-networkIds") |
| 225 | .withRelaxedReadConsistency() |
| 226 | .build(); |
| 227 | tenantIdNetworkIdSetMap = tenantIdNetworkIdSetConsistentMap.asJavaMap(); |
| 228 | |
| 229 | deviceIdVirtualDeviceConsistentMap = storageService.<DeviceId, VirtualDevice>consistentMapBuilder() |
| 230 | .withSerializer(SERIALIZER) |
| 231 | .withName("onos-deviceId-virtualdevice") |
| 232 | .withRelaxedReadConsistency() |
| 233 | .build(); |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 234 | deviceIdVirtualDeviceConsistentMap.addListener(virtualDeviceMapListener); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 235 | deviceIdVirtualDeviceMap = deviceIdVirtualDeviceConsistentMap.asJavaMap(); |
| 236 | |
| 237 | networkIdDeviceIdSetConsistentMap = storageService.<NetworkId, Set<DeviceId>>consistentMapBuilder() |
| 238 | .withSerializer(SERIALIZER) |
| 239 | .withName("onos-networkId-deviceIds") |
| 240 | .withRelaxedReadConsistency() |
| 241 | .build(); |
| 242 | networkIdDeviceIdSetMap = networkIdDeviceIdSetConsistentMap.asJavaMap(); |
| 243 | |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 244 | hostIdVirtualHostConsistentMap = storageService.<HostId, VirtualHost>consistentMapBuilder() |
| 245 | .withSerializer(SERIALIZER) |
| 246 | .withName("onos-hostId-virtualhost") |
| 247 | .withRelaxedReadConsistency() |
| 248 | .build(); |
| 249 | hostIdVirtualHostMap = hostIdVirtualHostConsistentMap.asJavaMap(); |
| 250 | |
| 251 | networkIdHostIdSetConsistentMap = storageService.<NetworkId, Set<HostId>>consistentMapBuilder() |
| 252 | .withSerializer(SERIALIZER) |
| 253 | .withName("onos-networkId-hostIds") |
| 254 | .withRelaxedReadConsistency() |
| 255 | .build(); |
| 256 | networkIdHostIdSetMap = networkIdHostIdSetConsistentMap.asJavaMap(); |
| 257 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 258 | networkIdVirtualLinkSetConsistentMap = storageService.<NetworkId, Set<VirtualLink>>consistentMapBuilder() |
| 259 | .withSerializer(SERIALIZER) |
| 260 | .withName("onos-networkId-virtuallinks") |
| 261 | .withRelaxedReadConsistency() |
| 262 | .build(); |
| 263 | networkIdVirtualLinkSetMap = networkIdVirtualLinkSetConsistentMap.asJavaMap(); |
| 264 | |
| 265 | networkIdVirtualPortSetConsistentMap = storageService.<NetworkId, Set<VirtualPort>>consistentMapBuilder() |
| 266 | .withSerializer(SERIALIZER) |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 267 | .withName("onos-networkId-virtualports") |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 268 | .withRelaxedReadConsistency() |
| 269 | .build(); |
| 270 | networkIdVirtualPortSetMap = networkIdVirtualPortSetConsistentMap.asJavaMap(); |
| 271 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 272 | intentKeyTunnelIdSetConsistentMap = storageService.<Key, Set<TunnelId>>consistentMapBuilder() |
| 273 | .withSerializer(SERIALIZER) |
| 274 | .withName("onos-intentKey-tunnelIds") |
| 275 | .withRelaxedReadConsistency() |
| 276 | .build(); |
| 277 | intentKeyTunnelIdSetMap = intentKeyTunnelIdSetConsistentMap.asJavaMap(); |
| 278 | |
| 279 | intentKeyIntentDataConsistentMap = storageService.<Key, IntentData>consistentMapBuilder() |
| 280 | .withSerializer(SERIALIZER) |
| 281 | .withName("onos-intentKey-intentData") |
| 282 | .withRelaxedReadConsistency() |
| 283 | .build(); |
| 284 | intentKeyIntentDataMap = intentKeyIntentDataConsistentMap.asJavaMap(); |
| 285 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 286 | log.info("Started"); |
| 287 | } |
| 288 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 289 | /** |
| 290 | * Distributed network store service deactivate method. |
| 291 | */ |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 292 | @Deactivate |
| 293 | public void deactivate() { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 294 | tenantIdSet.removeListener(setListener); |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 295 | networkIdVirtualNetworkConsistentMap.removeListener(virtualNetworkMapListener); |
| 296 | deviceIdVirtualDeviceConsistentMap.removeListener(virtualDeviceMapListener); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 297 | log.info("Stopped"); |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | public void addTenantId(TenantId tenantId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 302 | tenantIdSet.add(tenantId); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public void removeTenantId(TenantId tenantId) { |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 307 | //Remove all the virtual networks of this tenant |
| 308 | Set<VirtualNetwork> networkIdSet = getNetworks(tenantId); |
| 309 | if (networkIdSet != null) { |
| 310 | networkIdSet.forEach(virtualNetwork -> removeNetwork(virtualNetwork.id())); |
| 311 | } |
| 312 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 313 | tenantIdSet.remove(tenantId); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public Set<TenantId> getTenantIds() { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 318 | return ImmutableSet.copyOf(tenantIdSet); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public VirtualNetwork addNetwork(TenantId tenantId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 323 | |
| 324 | checkState(tenantIdSet.contains(tenantId), "The tenant has not been registered. " + tenantId.id()); |
| 325 | VirtualNetwork virtualNetwork = new DefaultVirtualNetwork(genNetworkId(), tenantId); |
| 326 | //TODO update both maps in one transaction. |
| 327 | networkIdVirtualNetworkMap.put(virtualNetwork.id(), virtualNetwork); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 328 | |
| 329 | Set<NetworkId> networkIdSet = tenantIdNetworkIdSetMap.get(tenantId); |
| 330 | if (networkIdSet == null) { |
| 331 | networkIdSet = new HashSet<>(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 332 | } |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 333 | networkIdSet.add(virtualNetwork.id()); |
| 334 | tenantIdNetworkIdSetMap.put(tenantId, networkIdSet); |
| 335 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 336 | return virtualNetwork; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 339 | /** |
| 340 | * Returns a new network identifier from a virtual network block of identifiers. |
| 341 | * |
| 342 | * @return NetworkId network identifier |
| 343 | */ |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 344 | private NetworkId genNetworkId() { |
Kenji HIKICHI | cfdf91b | 2016-05-25 13:04:45 +0900 | [diff] [blame] | 345 | NetworkId networkId; |
| 346 | do { |
| 347 | networkId = NetworkId.networkId(idGenerator.getNewId()); |
| 348 | } while (!networkId.isVirtualNetworkId()); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 349 | |
Kenji HIKICHI | cfdf91b | 2016-05-25 13:04:45 +0900 | [diff] [blame] | 350 | return networkId; |
| 351 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 352 | |
| 353 | @Override |
| 354 | public void removeNetwork(NetworkId networkId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 355 | // Make sure that the virtual network exists before attempting to remove it. |
| 356 | if (networkExists(networkId)) { |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 357 | //Remove all the devices of this network |
| 358 | Set<VirtualDevice> deviceSet = getDevices(networkId); |
| 359 | if (deviceSet != null) { |
| 360 | deviceSet.forEach(virtualDevice -> removeDevice(networkId, virtualDevice.id())); |
| 361 | } |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 362 | //TODO update both maps in one transaction. |
| 363 | |
| 364 | VirtualNetwork virtualNetwork = networkIdVirtualNetworkMap.remove(networkId); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 365 | if (virtualNetwork == null) { |
| 366 | return; |
| 367 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 368 | TenantId tenantId = virtualNetwork.tenantId(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 369 | |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 370 | Set<NetworkId> networkIdSet = new HashSet<>(); |
| 371 | tenantIdNetworkIdSetMap.get(tenantId).forEach(networkId1 -> { |
| 372 | if (networkId1.id().equals(networkId.id())) { |
| 373 | networkIdSet.add(networkId1); |
| 374 | } |
| 375 | }); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 376 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 377 | tenantIdNetworkIdSetMap.compute(virtualNetwork.tenantId(), (id, existingNetworkIds) -> { |
| 378 | if (existingNetworkIds == null || existingNetworkIds.isEmpty()) { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 379 | return new HashSet<>(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 380 | } else { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 381 | return new HashSet<>(Sets.difference(existingNetworkIds, networkIdSet)); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 382 | } |
| 383 | }); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Returns if the network identifier exists. |
| 389 | * |
| 390 | * @param networkId network identifier |
| 391 | * @return true if the network identifier exists, false otherwise. |
| 392 | */ |
| 393 | private boolean networkExists(NetworkId networkId) { |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 394 | checkNotNull(networkId, "The network identifier cannot be null."); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 395 | return (networkIdVirtualNetworkMap.containsKey(networkId)); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public VirtualDevice addDevice(NetworkId networkId, DeviceId deviceId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 400 | checkState(networkExists(networkId), "The network has not been added."); |
| 401 | Set<DeviceId> deviceIdSet = networkIdDeviceIdSetMap.get(networkId); |
| 402 | if (deviceIdSet == null) { |
| 403 | deviceIdSet = new HashSet<>(); |
| 404 | } |
| 405 | VirtualDevice virtualDevice = new DefaultVirtualDevice(networkId, deviceId); |
| 406 | //TODO update both maps in one transaction. |
| 407 | deviceIdVirtualDeviceMap.put(deviceId, virtualDevice); |
| 408 | deviceIdSet.add(deviceId); |
| 409 | networkIdDeviceIdSetMap.put(networkId, deviceIdSet); |
| 410 | return virtualDevice; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void removeDevice(NetworkId networkId, DeviceId deviceId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 415 | checkState(networkExists(networkId), "The network has not been added."); |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 416 | //Remove all the virtual ports of the this device |
| 417 | Set<VirtualPort> virtualPorts = getPorts(networkId, deviceId); |
| 418 | if (virtualPorts != null) { |
| 419 | virtualPorts.forEach(virtualPort -> removePort(networkId, deviceId, virtualPort.number())); |
| 420 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 421 | //TODO update both maps in one transaction. |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 422 | |
| 423 | Set<DeviceId> deviceIdSet = new HashSet<>(); |
| 424 | networkIdDeviceIdSetMap.get(networkId).forEach(deviceId1 -> { |
| 425 | if (deviceId1.equals(deviceId)) { |
| 426 | deviceIdSet.add(deviceId1); |
| 427 | } |
| 428 | }); |
| 429 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 430 | if (deviceIdSet != null) { |
| 431 | networkIdDeviceIdSetMap.compute(networkId, (id, existingDeviceIds) -> { |
| 432 | if (existingDeviceIds == null || existingDeviceIds.isEmpty()) { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 433 | return new HashSet<>(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 434 | } else { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 435 | return new HashSet<>(Sets.difference(existingDeviceIds, deviceIdSet)); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 436 | } |
| 437 | }); |
| 438 | |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 439 | deviceIdVirtualDeviceMap.remove(deviceId); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 440 | } |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public VirtualHost addHost(NetworkId networkId, HostId hostId, MacAddress mac, |
| 445 | VlanId vlan, HostLocation location, Set<IpAddress> ips) { |
| 446 | checkState(networkExists(networkId), "The network has not been added."); |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 447 | checkState(virtualPortExists(networkId, location.deviceId(), location.port()), |
| 448 | "The virtual port has not been created."); |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 449 | Set<HostId> hostIdSet = networkIdHostIdSetMap.get(networkId); |
| 450 | if (hostIdSet == null) { |
| 451 | hostIdSet = new HashSet<>(); |
| 452 | } |
| 453 | VirtualHost virtualhost = new DefaultVirtualHost(networkId, hostId, mac, vlan, location, ips); |
| 454 | //TODO update both maps in one transaction. |
| 455 | hostIdVirtualHostMap.put(hostId, virtualhost); |
| 456 | hostIdSet.add(hostId); |
| 457 | networkIdHostIdSetMap.put(networkId, hostIdSet); |
| 458 | return virtualhost; |
| 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public void removeHost(NetworkId networkId, HostId hostId) { |
| 463 | checkState(networkExists(networkId), "The network has not been added."); |
| 464 | //TODO update both maps in one transaction. |
| 465 | |
| 466 | Set<HostId> hostIdSet = new HashSet<>(); |
| 467 | networkIdHostIdSetMap.get(networkId).forEach(hostId1 -> { |
| 468 | if (hostId1.equals(hostId)) { |
| 469 | hostIdSet.add(hostId1); |
| 470 | } |
| 471 | }); |
| 472 | |
| 473 | if (hostIdSet != null) { |
| 474 | networkIdHostIdSetMap.compute(networkId, (id, existingHostIds) -> { |
| 475 | if (existingHostIds == null || existingHostIds.isEmpty()) { |
| 476 | return new HashSet<>(); |
| 477 | } else { |
| 478 | return new HashSet<>(Sets.difference(existingHostIds, hostIdSet)); |
| 479 | } |
| 480 | }); |
| 481 | |
| 482 | hostIdVirtualHostMap.remove(hostId); |
| 483 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 486 | /** |
| 487 | * Returns if the given virtual port exists. |
| 488 | * |
| 489 | * @param networkId network identifier |
| 490 | * @param deviceId virtual device Id |
| 491 | * @param portNumber virtual port number |
| 492 | * @return true if the virtual port exists, false otherwise. |
| 493 | */ |
| 494 | private boolean virtualPortExists(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) { |
| 495 | Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId); |
| 496 | if (virtualPortSet != null) { |
| 497 | return virtualPortSet.stream().anyMatch( |
| 498 | p -> p.element().id().equals(deviceId) && |
| 499 | p.number().equals(portNumber)); |
| 500 | } else { |
| 501 | return false; |
| 502 | } |
| 503 | } |
| 504 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 505 | @Override |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 506 | public VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, |
| 507 | Link.State state, TunnelId realizedBy) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 508 | checkState(networkExists(networkId), "The network has not been added."); |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 509 | checkState(virtualPortExists(networkId, src.deviceId(), src.port()), |
| 510 | "The source virtual port has not been added."); |
| 511 | checkState(virtualPortExists(networkId, dst.deviceId(), dst.port()), |
| 512 | "The destination virtual port has not been added."); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 513 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); |
| 514 | if (virtualLinkSet == null) { |
| 515 | virtualLinkSet = new HashSet<>(); |
| 516 | } |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 517 | // validate that the link does not already exist in this network |
| 518 | checkState(getLink(networkId, src, dst) == null, "The virtual link already exists"); |
| 519 | |
| 520 | VirtualLink virtualLink = DefaultVirtualLink.builder() |
| 521 | .networkId(networkId) |
| 522 | .src(src) |
| 523 | .dst(dst) |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 524 | .state(state) |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 525 | .tunnelId(realizedBy) |
| 526 | .build(); |
| 527 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 528 | virtualLinkSet.add(virtualLink); |
| 529 | networkIdVirtualLinkSetMap.put(networkId, virtualLinkSet); |
| 530 | return virtualLink; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | @Override |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 534 | public void updateLink(VirtualLink virtualLink, TunnelId tunnelId, Link.State state) { |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 535 | checkState(networkExists(virtualLink.networkId()), "The network has not been added."); |
| 536 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(virtualLink.networkId()); |
| 537 | if (virtualLinkSet == null) { |
| 538 | virtualLinkSet = new HashSet<>(); |
| 539 | } |
| 540 | virtualLinkSet.remove(virtualLink); |
| 541 | |
| 542 | VirtualLink newVirtualLink = DefaultVirtualLink.builder() |
| 543 | .networkId(virtualLink.networkId()) |
| 544 | .src(virtualLink.src()) |
| 545 | .dst(virtualLink.dst()) |
| 546 | .tunnelId(tunnelId) |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 547 | .state(state) |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 548 | .build(); |
| 549 | |
| 550 | virtualLinkSet.add(newVirtualLink); |
| 551 | networkIdVirtualLinkSetMap.put(newVirtualLink.networkId(), virtualLinkSet); |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public VirtualLink removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 556 | checkState(networkExists(networkId), "The network has not been added."); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 557 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 558 | final VirtualLink virtualLink = getLink(networkId, src, dst); |
| 559 | if (virtualLink == null) { |
| 560 | return null; |
| 561 | } |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 562 | Set<VirtualLink> virtualLinkSet = new HashSet<>(); |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 563 | virtualLinkSet.add(virtualLink); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 564 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 565 | if (virtualLinkSet != null) { |
| 566 | networkIdVirtualLinkSetMap.compute(networkId, (id, existingVirtualLinks) -> { |
| 567 | if (existingVirtualLinks == null || existingVirtualLinks.isEmpty()) { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 568 | return new HashSet<>(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 569 | } else { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 570 | return new HashSet<>(Sets.difference(existingVirtualLinks, virtualLinkSet)); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 571 | } |
| 572 | }); |
| 573 | } |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 574 | return virtualLink; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Override |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 578 | public VirtualPort addPort(NetworkId networkId, DeviceId deviceId, |
| 579 | PortNumber portNumber, ConnectPoint realizedBy) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 580 | checkState(networkExists(networkId), "The network has not been added."); |
| 581 | Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 582 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 583 | if (virtualPortSet == null) { |
| 584 | virtualPortSet = new HashSet<>(); |
| 585 | } |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 586 | |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 587 | VirtualDevice device = deviceIdVirtualDeviceMap.get(deviceId); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 588 | checkNotNull(device, "The device has not been created for deviceId: " + deviceId); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 589 | |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 590 | checkState(!virtualPortExists(networkId, deviceId, portNumber), |
| 591 | "The requested Port Number has been added."); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 592 | |
| 593 | VirtualPort virtualPort = new DefaultVirtualPort(networkId, device, |
| 594 | portNumber, realizedBy); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 595 | virtualPortSet.add(virtualPort); |
| 596 | networkIdVirtualPortSetMap.put(networkId, virtualPortSet); |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 597 | notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_ADDED, |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 598 | networkId, device, virtualPort)); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 599 | return virtualPort; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | @Override |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 603 | public void bindPort(NetworkId networkId, DeviceId deviceId, |
| 604 | PortNumber portNumber, ConnectPoint realizedBy) { |
| 605 | |
| 606 | Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap |
| 607 | .get(networkId); |
| 608 | |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 609 | Optional<VirtualPort> virtualPortOptional = virtualPortSet.stream().filter( |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 610 | p -> p.element().id().equals(deviceId) && |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 611 | p.number().equals(portNumber)).findFirst(); |
| 612 | checkState(virtualPortOptional.isPresent(), "The virtual port has not been added."); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 613 | |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 614 | VirtualDevice device = deviceIdVirtualDeviceMap.get(deviceId); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 615 | checkNotNull(device, "The device has not been created for deviceId: " |
| 616 | + deviceId); |
| 617 | |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 618 | VirtualPort vPort = virtualPortOptional.get(); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 619 | virtualPortSet.remove(vPort); |
| 620 | vPort = new DefaultVirtualPort(networkId, device, portNumber, realizedBy); |
| 621 | virtualPortSet.add(vPort); |
| 622 | networkIdVirtualPortSetMap.put(networkId, virtualPortSet); |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 623 | notifyDelegate(new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_UPDATED, |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 624 | networkId, device, vPort)); |
Yoonseon Han | 6c60389 | 2016-09-01 11:52:21 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 628 | public void removePort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 629 | checkState(networkExists(networkId), "The network has not been added."); |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 630 | VirtualDevice device = deviceIdVirtualDeviceMap.get(deviceId); |
| 631 | checkNotNull(device, "The device has not been created for deviceId: " |
| 632 | + deviceId); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 633 | |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 634 | if (networkIdVirtualPortSetMap.get(networkId) == null) { |
| 635 | log.warn("No port has been created for NetworkId: {}", networkId); |
| 636 | return; |
| 637 | } |
| 638 | |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 639 | Set<VirtualPort> virtualPortSet = new HashSet<>(); |
| 640 | networkIdVirtualPortSetMap.get(networkId).forEach(port -> { |
| 641 | if (port.element().id().equals(deviceId) && port.number().equals(portNumber)) { |
| 642 | virtualPortSet.add(port); |
| 643 | } |
| 644 | }); |
| 645 | |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 646 | if (!virtualPortSet.isEmpty()) { |
| 647 | AtomicBoolean portRemoved = new AtomicBoolean(false); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 648 | networkIdVirtualPortSetMap.compute(networkId, (id, existingVirtualPorts) -> { |
| 649 | if (existingVirtualPorts == null || existingVirtualPorts.isEmpty()) { |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 650 | return new HashSet<>(); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 651 | } else { |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 652 | portRemoved.set(true); |
HIGUCHI Yuta | c0f5045 | 2016-05-13 19:26:05 -0700 | [diff] [blame] | 653 | return new HashSet<>(Sets.difference(existingVirtualPorts, virtualPortSet)); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 654 | } |
| 655 | }); |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 656 | if (portRemoved.get()) { |
| 657 | virtualPortSet.forEach(virtualPort -> notifyDelegate( |
| 658 | new VirtualNetworkEvent(VirtualNetworkEvent.Type.VIRTUAL_PORT_REMOVED, |
Claudine Chiu | 465a260 | 2017-03-17 18:33:36 -0400 | [diff] [blame] | 659 | networkId, device, virtualPort) |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 660 | )); |
Harold Huang | b7d6b8e | 2017-04-03 17:13:33 +0800 | [diff] [blame] | 661 | |
| 662 | //Remove all the virtual links connected to this virtual port |
| 663 | Set<VirtualLink> existingVirtualLinks = networkIdVirtualLinkSetMap.get(networkId); |
| 664 | if (existingVirtualLinks != null && !existingVirtualLinks.isEmpty()) { |
| 665 | Set<VirtualLink> virtualLinkSet = new HashSet<>(); |
| 666 | ConnectPoint cp = new ConnectPoint(deviceId, portNumber); |
| 667 | existingVirtualLinks.forEach(virtualLink -> { |
| 668 | if (virtualLink.src().equals(cp) || virtualLink.dst().equals(cp)) { |
| 669 | virtualLinkSet.add(virtualLink); |
| 670 | } |
| 671 | }); |
| 672 | virtualLinkSet.forEach(virtualLink -> |
| 673 | removeLink(networkId, virtualLink.src(), virtualLink.dst())); |
| 674 | } |
| 675 | |
| 676 | //Remove all the hosts connected to this virtual port |
| 677 | Set<HostId> hostIdSet = new HashSet<>(); |
| 678 | hostIdVirtualHostMap.forEach((hostId, virtualHost) -> { |
| 679 | if (virtualHost.location().deviceId().equals(deviceId) && |
| 680 | virtualHost.location().port().equals(portNumber)) { |
| 681 | hostIdSet.add(hostId); |
| 682 | } |
| 683 | }); |
| 684 | hostIdSet.forEach(hostId -> removeHost(networkId, hostId)); |
Claudine Chiu | 7f872a7 | 2016-12-16 13:51:39 -0500 | [diff] [blame] | 685 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 686 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | @Override |
| 690 | public Set<VirtualNetwork> getNetworks(TenantId tenantId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 691 | Set<NetworkId> networkIdSet = tenantIdNetworkIdSetMap.get(tenantId); |
| 692 | Set<VirtualNetwork> virtualNetworkSet = new HashSet<>(); |
| 693 | if (networkIdSet != null) { |
| 694 | networkIdSet.forEach(networkId -> virtualNetworkSet.add(networkIdVirtualNetworkMap.get(networkId))); |
| 695 | } |
| 696 | return ImmutableSet.copyOf(virtualNetworkSet); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | @Override |
Brian Stanke | 8691428 | 2016-05-25 15:36:50 -0400 | [diff] [blame] | 700 | public VirtualNetwork getNetwork(NetworkId networkId) { |
| 701 | return networkIdVirtualNetworkMap.get(networkId); |
| 702 | } |
| 703 | |
| 704 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 705 | public Set<VirtualDevice> getDevices(NetworkId networkId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 706 | checkState(networkExists(networkId), "The network has not been added."); |
| 707 | Set<DeviceId> deviceIdSet = networkIdDeviceIdSetMap.get(networkId); |
| 708 | Set<VirtualDevice> virtualDeviceSet = new HashSet<>(); |
| 709 | if (deviceIdSet != null) { |
| 710 | deviceIdSet.forEach(deviceId -> virtualDeviceSet.add(deviceIdVirtualDeviceMap.get(deviceId))); |
| 711 | } |
| 712 | return ImmutableSet.copyOf(virtualDeviceSet); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | @Override |
Brian Stanke | 7a81b53 | 2016-06-14 15:43:51 -0400 | [diff] [blame] | 716 | public Set<VirtualHost> getHosts(NetworkId networkId) { |
| 717 | checkState(networkExists(networkId), "The network has not been added."); |
| 718 | Set<HostId> hostIdSet = networkIdHostIdSetMap.get(networkId); |
| 719 | Set<VirtualHost> virtualHostSet = new HashSet<>(); |
| 720 | if (hostIdSet != null) { |
| 721 | hostIdSet.forEach(hostId -> virtualHostSet.add(hostIdVirtualHostMap.get(hostId))); |
| 722 | } |
| 723 | return ImmutableSet.copyOf(virtualHostSet); |
| 724 | } |
| 725 | |
| 726 | @Override |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 727 | public Set<VirtualLink> getLinks(NetworkId networkId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 728 | checkState(networkExists(networkId), "The network has not been added."); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 729 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); |
| 730 | if (virtualLinkSet == null) { |
| 731 | virtualLinkSet = new HashSet<>(); |
| 732 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 733 | return ImmutableSet.copyOf(virtualLinkSet); |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 736 | @Override |
| 737 | public VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 738 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); |
| 739 | if (virtualLinkSet == null) { |
| 740 | return null; |
| 741 | } |
| 742 | |
| 743 | VirtualLink virtualLink = null; |
| 744 | for (VirtualLink link : virtualLinkSet) { |
| 745 | if (link.src().equals(src) && link.dst().equals(dst)) { |
| 746 | virtualLink = link; |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | return virtualLink; |
| 751 | } |
| 752 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 753 | @Override |
| 754 | public Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId) { |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 755 | checkState(networkExists(networkId), "The network has not been added."); |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 756 | Set<VirtualPort> virtualPortSet = networkIdVirtualPortSetMap.get(networkId); |
| 757 | if (virtualPortSet == null) { |
| 758 | virtualPortSet = new HashSet<>(); |
| 759 | } |
| 760 | |
Brian Stanke | 612cebf | 2016-05-02 10:21:33 -0400 | [diff] [blame] | 761 | if (deviceId == null) { |
| 762 | return ImmutableSet.copyOf(virtualPortSet); |
| 763 | } |
| 764 | |
Brian Stanke | 5df1447 | 2016-03-11 19:34:38 -0500 | [diff] [blame] | 765 | Set<VirtualPort> portSet = new HashSet<>(); |
| 766 | virtualPortSet.forEach(virtualPort -> { |
| 767 | if (virtualPort.element().id().equals(deviceId)) { |
| 768 | portSet.add(virtualPort); |
| 769 | } |
| 770 | }); |
| 771 | return ImmutableSet.copyOf(portSet); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 772 | } |
| 773 | |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 774 | @Override |
| 775 | public synchronized void addOrUpdateIntent(Intent intent, IntentState state) { |
| 776 | checkNotNull(intent, "Intent cannot be null"); |
| 777 | IntentData intentData = removeIntent(intent.key()); |
| 778 | if (intentData == null) { |
| 779 | intentData = new IntentData(intent, state, new WallClockTimestamp(System.currentTimeMillis())); |
| 780 | } else { |
| 781 | intentData = new IntentData(intent, state, intentData.version()); |
| 782 | } |
| 783 | intentKeyIntentDataMap.put(intent.key(), intentData); |
| 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public IntentData removeIntent(Key intentKey) { |
| 788 | checkNotNull(intentKey, "Intent key cannot be null"); |
| 789 | return intentKeyIntentDataMap.remove(intentKey); |
| 790 | } |
| 791 | |
| 792 | @Override |
| 793 | public void addTunnelId(Intent intent, TunnelId tunnelId) { |
| 794 | // Add the tunnelId to the intent key set map |
| 795 | Set<TunnelId> tunnelIdSet = intentKeyTunnelIdSetMap.remove(intent.key()); |
| 796 | if (tunnelIdSet == null) { |
| 797 | tunnelIdSet = new HashSet<>(); |
| 798 | } |
| 799 | tunnelIdSet.add(tunnelId); |
| 800 | intentKeyTunnelIdSetMap.put(intent.key(), tunnelIdSet); |
| 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public Set<TunnelId> getTunnelIds(Intent intent) { |
| 805 | Set<TunnelId> tunnelIdSet = intentKeyTunnelIdSetMap.get(intent.key()); |
| 806 | return tunnelIdSet == null ? new HashSet<TunnelId>() : ImmutableSet.copyOf(tunnelIdSet); |
| 807 | } |
| 808 | |
| 809 | @Override |
| 810 | public void removeTunnelId(Intent intent, TunnelId tunnelId) { |
| 811 | Set<TunnelId> tunnelIdSet = new HashSet<>(); |
| 812 | intentKeyTunnelIdSetMap.get(intent.key()).forEach(tunnelId1 -> { |
| 813 | if (tunnelId1.equals(tunnelId)) { |
| 814 | tunnelIdSet.add(tunnelId); |
| 815 | } |
| 816 | }); |
| 817 | |
| 818 | if (!tunnelIdSet.isEmpty()) { |
| 819 | intentKeyTunnelIdSetMap.compute(intent.key(), (key, existingTunnelIds) -> { |
| 820 | if (existingTunnelIds == null || existingTunnelIds.isEmpty()) { |
| 821 | return new HashSet<>(); |
| 822 | } else { |
| 823 | return new HashSet<>(Sets.difference(existingTunnelIds, tunnelIdSet)); |
| 824 | } |
| 825 | }); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public Set<Intent> getIntents() { |
| 831 | Set<Intent> intents = new HashSet<>(); |
| 832 | intentKeyIntentDataMap.values().forEach(intentData -> intents.add(intentData.intent())); |
| 833 | return ImmutableSet.copyOf(intents); |
| 834 | } |
| 835 | |
| 836 | @Override |
| 837 | public Intent getIntent(Key key) { |
| 838 | IntentData intentData = intentKeyIntentDataMap.get(key); |
| 839 | return intentData == null ? null : intentData.intent(); |
| 840 | } |
| 841 | |
| 842 | @Override |
| 843 | public Set<IntentData> getIntentData() { |
| 844 | return ImmutableSet.copyOf(intentKeyIntentDataMap.values()); |
| 845 | } |
| 846 | |
| 847 | @Override |
| 848 | public IntentData getIntentData(Key key) { |
| 849 | IntentData intentData = intentKeyIntentDataMap.get(key); |
| 850 | return intentData == null ? null : new IntentData(intentData); |
| 851 | } |
| 852 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 853 | /** |
| 854 | * Listener class to map listener set events to the virtual network events. |
| 855 | */ |
| 856 | private class InternalSetListener implements SetEventListener<TenantId> { |
| 857 | @Override |
| 858 | public void event(SetEvent<TenantId> event) { |
| 859 | VirtualNetworkEvent.Type type = null; |
| 860 | switch (event.type()) { |
| 861 | case ADD: |
| 862 | type = VirtualNetworkEvent.Type.TENANT_REGISTERED; |
| 863 | break; |
| 864 | case REMOVE: |
| 865 | type = VirtualNetworkEvent.Type.TENANT_UNREGISTERED; |
| 866 | break; |
| 867 | default: |
| 868 | log.error("Unsupported event type: " + event.type()); |
| 869 | } |
| 870 | notifyDelegate(new VirtualNetworkEvent(type, null)); |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Listener class to map listener map events to the virtual network events. |
| 876 | */ |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 877 | private class InternalMapListener<K, V> implements MapEventListener<K, V> { |
| 878 | |
| 879 | private final BiFunction<MapEvent.Type, V, VirtualNetworkEvent> createEvent; |
| 880 | |
| 881 | InternalMapListener(BiFunction<MapEvent.Type, V, VirtualNetworkEvent> createEvent) { |
| 882 | this.createEvent = createEvent; |
| 883 | } |
| 884 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 885 | @Override |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 886 | public void event(MapEvent<K, V> event) { |
| 887 | checkNotNull(event.key()); |
| 888 | VirtualNetworkEvent vnetEvent = null; |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 889 | switch (event.type()) { |
| 890 | case INSERT: |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 891 | vnetEvent = createEvent.apply(event.type(), event.newValue().value()); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 892 | break; |
| 893 | case UPDATE: |
| 894 | if ((event.oldValue().value() != null) && (event.newValue().value() == null)) { |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 895 | vnetEvent = createEvent.apply(MapEvent.Type.REMOVE, event.oldValue().value()); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 896 | } else { |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 897 | vnetEvent = createEvent.apply(event.type(), event.newValue().value()); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 898 | } |
| 899 | break; |
| 900 | case REMOVE: |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 901 | if (event.oldValue() != null) { |
| 902 | vnetEvent = createEvent.apply(event.type(), event.oldValue().value()); |
| 903 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 904 | break; |
| 905 | default: |
| 906 | log.error("Unsupported event type: " + event.type()); |
| 907 | } |
Claudine Chiu | 945828d | 2016-11-21 12:47:07 -0500 | [diff] [blame] | 908 | if (vnetEvent != null) { |
| 909 | notifyDelegate(vnetEvent); |
| 910 | } |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 911 | } |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 912 | } |
| 913 | } |