Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 1 | /* |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [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 | |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 17 | package org.onosproject.simplefabric.impl; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; |
| 22 | import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; |
| 23 | import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 24 | import org.onlab.packet.ARP; |
| 25 | import org.onlab.packet.Ethernet; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IPv6; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 27 | import org.onlab.packet.Ip4Address; |
| 28 | import org.onlab.packet.Ip6Address; |
| 29 | import org.onlab.packet.IpAddress; |
| 30 | import org.onlab.packet.IpPrefix; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 31 | import org.onlab.packet.MacAddress; |
| 32 | import org.onlab.packet.VlanId; |
| 33 | import org.onlab.packet.ndp.NeighborSolicitation; |
| 34 | import org.onosproject.app.ApplicationService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 35 | import org.onosproject.component.ComponentService; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 36 | import org.onosproject.core.ApplicationId; |
| 37 | import org.onosproject.core.CoreService; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 38 | import org.onosproject.event.ListenerRegistry; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.Host; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 41 | import org.onosproject.net.config.ConfigFactory; |
| 42 | import org.onosproject.net.config.NetworkConfigEvent; |
| 43 | import org.onosproject.net.config.NetworkConfigListener; |
| 44 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 45 | import org.onosproject.net.config.NetworkConfigService; |
| 46 | import org.onosproject.net.config.basics.SubjectFactories; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 47 | import org.onosproject.net.device.DeviceEvent; |
| 48 | import org.onosproject.net.device.DeviceListener; |
| 49 | import org.onosproject.net.device.DeviceService; |
| 50 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 51 | import org.onosproject.net.flow.TrafficTreatment; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 52 | import org.onosproject.net.host.HostEvent; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 53 | import org.onosproject.net.host.HostListener; |
| 54 | import org.onosproject.net.host.HostService; |
| 55 | import org.onosproject.net.intf.Interface; |
| 56 | import org.onosproject.net.intf.InterfaceEvent; |
| 57 | import org.onosproject.net.intf.InterfaceListener; |
| 58 | import org.onosproject.net.intf.InterfaceService; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 59 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 60 | import org.onosproject.net.packet.OutboundPacket; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 61 | import org.onosproject.net.packet.PacketService; |
| 62 | import org.osgi.service.component.annotations.Activate; |
| 63 | import org.osgi.service.component.annotations.Component; |
| 64 | import org.osgi.service.component.annotations.Deactivate; |
| 65 | import org.osgi.service.component.annotations.Reference; |
| 66 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 67 | import org.onosproject.simplefabric.api.FabricNetwork; |
| 68 | import org.onosproject.simplefabric.api.FabricRoute; |
| 69 | import org.onosproject.simplefabric.api.FabricSubnet; |
Jian Li | c7efc1d | 2018-08-23 16:37:34 +0900 | [diff] [blame] | 70 | import org.onosproject.simplefabric.api.SimpleFabricEvent; |
| 71 | import org.onosproject.simplefabric.api.SimpleFabricListener; |
| 72 | import org.onosproject.simplefabric.api.SimpleFabricService; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 73 | import org.slf4j.Logger; |
| 74 | import org.slf4j.LoggerFactory; |
| 75 | |
| 76 | import java.io.OutputStream; |
| 77 | import java.io.PrintStream; |
| 78 | import java.nio.ByteBuffer; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 79 | import java.util.Collection; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 80 | import java.util.HashSet; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 81 | import java.util.Map; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 82 | import java.util.Set; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 83 | |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 84 | import static org.onosproject.simplefabric.api.Constants.ALLOW_ETH_ADDRESS_SELECTOR; |
| 85 | import static org.onosproject.simplefabric.api.Constants.ALLOW_IPV6; |
| 86 | import static org.onosproject.simplefabric.api.Constants.APP_ID; |
| 87 | import static org.onosproject.simplefabric.api.Constants.IDLE_INTERVAL_MSEC; |
| 88 | import static org.onosproject.simplefabric.api.Constants.REACTIVE_ALLOW_LINK_CP; |
| 89 | import static org.onosproject.simplefabric.api.Constants.REACTIVE_HASHED_PATH_SELECTION; |
| 90 | import static org.onosproject.simplefabric.api.Constants.REACTIVE_MATCH_IP_PROTO; |
| 91 | import static org.onosproject.simplefabric.api.Constants.REACTIVE_SINGLE_TO_SINGLE; |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 92 | import static org.onosproject.simplefabric.util.RouteTools.createBinaryString; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 93 | |
| 94 | |
| 95 | /** |
| 96 | * Reactive routing configuration manager. |
| 97 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 98 | @Component(immediate = true, service = SimpleFabricService.class) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 99 | public class SimpleFabricManager extends ListenerRegistry<SimpleFabricEvent, SimpleFabricListener> |
| 100 | implements SimpleFabricService { |
| 101 | |
| 102 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 103 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 105 | protected CoreService coreService; |
| 106 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 108 | protected ApplicationService applicationService; |
| 109 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 111 | protected NetworkConfigService configService; |
| 112 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 114 | protected NetworkConfigRegistry registry; |
| 115 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 117 | protected DeviceService deviceService; |
| 118 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 120 | protected InterfaceService interfaceService; |
| 121 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 123 | protected HostService hostService; |
| 124 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 126 | protected PacketService packetService; |
| 127 | |
| 128 | // compoents to be activated within SimpleFabric |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 130 | protected ComponentService componentService; |
| 131 | |
| 132 | // SimpleFabric variables |
| 133 | private ApplicationId appId = null; |
| 134 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 135 | // fabric networks |
| 136 | private Set<FabricNetwork> fabricNetworks = new HashSet<>(); |
| 137 | private Set<Interface> networkInterfaces = new HashSet<>(); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 138 | |
| 139 | // Subnet table |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 140 | private Set<FabricSubnet> fabricSubnets = new HashSet<>(); |
| 141 | private InvertedRadixTree<FabricSubnet> ip4SubnetTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 142 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 143 | private InvertedRadixTree<FabricSubnet> ip6SubnetTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 144 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
| 145 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 146 | // Fabric Route table |
| 147 | private Set<FabricRoute> fabricRoutes = new HashSet<>(); |
| 148 | private InvertedRadixTree<FabricRoute> ip4BorderRouteTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 149 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 150 | private InvertedRadixTree<FabricRoute> ip6BorderRouteTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 151 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
| 152 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 153 | // Virtual gateway |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 154 | private Map<IpAddress, MacAddress> virtualGatewayIpMacMap = Maps.newConcurrentMap(); |
| 155 | |
| 156 | // Refresh monitor thread |
| 157 | private Object refreshMonitor = new Object(); |
| 158 | private boolean doRefresh = false; |
| 159 | private boolean doFlush = false; |
| 160 | private InternalRefreshThread refreshThread; |
| 161 | |
| 162 | // Listener for Service Events |
| 163 | private final InternalNetworkConfigListener configListener = new InternalNetworkConfigListener(); |
| 164 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 165 | private final InternalHostListener hostListener = new InternalHostListener(); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 166 | |
| 167 | private ConfigFactory<ApplicationId, SimpleFabricConfig> simpleFabricConfigFactory = |
| 168 | new ConfigFactory<ApplicationId, SimpleFabricConfig>( |
| 169 | SubjectFactories.APP_SUBJECT_FACTORY, |
| 170 | SimpleFabricConfig.class, SimpleFabricConfig.KEY) { |
| 171 | @Override |
| 172 | public SimpleFabricConfig createConfig() { |
| 173 | return new SimpleFabricConfig(); |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | @Activate |
| 178 | public void activate() { |
| 179 | log.info("simple fabric starting"); |
| 180 | |
| 181 | if (appId == null) { |
| 182 | appId = coreService.registerApplication(APP_ID); |
| 183 | } |
| 184 | |
| 185 | // initial refresh |
| 186 | refresh(); |
| 187 | |
| 188 | configService.addListener(configListener); |
| 189 | registry.registerConfigFactory(simpleFabricConfigFactory); |
| 190 | deviceService.addListener(deviceListener); |
| 191 | hostService.addListener(hostListener); |
| 192 | |
| 193 | componentService.activate(appId, SimpleFabricNeighbour.class.getName()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 194 | componentService.activate(appId, SimpleFabricRouting.class.getName()); |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 195 | if (ALLOW_ETH_ADDRESS_SELECTOR) { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 196 | componentService.activate(appId, SimpleFabricForwarding.class.getName()); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | refreshThread = new InternalRefreshThread(); |
| 200 | refreshThread.start(); |
| 201 | |
| 202 | log.info("simple fabric started"); |
| 203 | } |
| 204 | |
| 205 | @Deactivate |
| 206 | public void deactivate() { |
| 207 | log.info("simple fabric stopping"); |
| 208 | |
| 209 | componentService.deactivate(appId, SimpleFabricNeighbour.class.getName()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 210 | componentService.deactivate(appId, SimpleFabricRouting.class.getName()); |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 211 | if (ALLOW_ETH_ADDRESS_SELECTOR) { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 212 | componentService.deactivate(appId, SimpleFabricForwarding.class.getName()); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | deviceService.removeListener(deviceListener); |
| 216 | hostService.removeListener(hostListener); |
| 217 | registry.unregisterConfigFactory(simpleFabricConfigFactory); |
| 218 | configService.removeListener(configListener); |
| 219 | |
| 220 | refreshThread.stop(); |
| 221 | refreshThread = null; |
| 222 | |
| 223 | log.info("simple fabric stopped"); |
| 224 | } |
| 225 | |
| 226 | // Set up from configuration |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 227 | // returns found isDirty and refresh listeners are called (true) or not (false) |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 228 | private boolean refresh() { |
| 229 | log.debug("simple fabric refresh"); |
| 230 | boolean dirty = false; |
| 231 | |
| 232 | SimpleFabricConfig config = configService.getConfig(coreService.registerApplication(APP_ID), |
| 233 | SimpleFabricConfig.class); |
| 234 | if (config == null) { |
Yuta HIGUCHI | c2bf02a | 2018-03-29 08:40:35 -0700 | [diff] [blame] | 235 | log.debug("No simple fabric config available!"); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 239 | // fabricNetworks |
| 240 | Set<FabricNetwork> newFabricNetworks = new HashSet<>(); |
| 241 | Set<Interface> newInterfaces = new HashSet<>(); |
| 242 | for (FabricNetwork newFabricNetworkConfig : config.fabricNetworks()) { |
| 243 | FabricNetwork newFabricNetwork = DefaultFabricNetwork.of(newFabricNetworkConfig); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 244 | |
| 245 | // fill up interfaces and Hosts with active port only |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 246 | for (String ifaceName : newFabricNetworkConfig.interfaceNames()) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 247 | Interface iface = getInterfaceByName(ifaceName); |
| 248 | if (iface != null && deviceService.isAvailable(iface.connectPoint().deviceId())) { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 249 | newFabricNetwork.addInterface(iface); |
| 250 | newInterfaces.add(iface); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | for (Host host : hostService.getHosts()) { |
| 254 | // consider host with ip only |
| 255 | if (!host.ipAddresses().isEmpty()) { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 256 | Interface iface = findAvailableDeviceHostInterface(host); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 257 | if (iface != null && newFabricNetwork.contains(iface)) { |
| 258 | newFabricNetwork.addHost(host); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 262 | newFabricNetwork.setDirty(true); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 263 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 264 | // update newFabricNetwork's isDirty flags if same entry already exists |
| 265 | for (FabricNetwork prevFabricNetwork : fabricNetworks) { |
| 266 | if (prevFabricNetwork.equals(newFabricNetwork)) { |
| 267 | newFabricNetwork.setDirty(prevFabricNetwork.isDirty()); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 268 | break; |
| 269 | } |
| 270 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 271 | newFabricNetworks.add(newFabricNetwork); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 272 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 273 | if (!fabricNetworks.equals(newFabricNetworks)) { |
| 274 | fabricNetworks = newFabricNetworks; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 275 | dirty = true; |
| 276 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 277 | if (!networkInterfaces.equals(newInterfaces)) { |
| 278 | networkInterfaces = newInterfaces; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 279 | dirty = true; |
| 280 | } |
| 281 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 282 | // default Fabric Subnets |
| 283 | Set<FabricSubnet> newFabricSubnets = config.fabricSubnets(); |
| 284 | InvertedRadixTree<FabricSubnet> newIp4SubnetTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 285 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 286 | InvertedRadixTree<FabricSubnet> newIp6SubnetTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 287 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
| 288 | Map<IpAddress, MacAddress> newVirtualGatewayIpMacMap = Maps.newConcurrentMap(); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 289 | for (FabricSubnet subnet : newFabricSubnets) { |
| 290 | if (subnet.prefix().isIp4()) { |
| 291 | newIp4SubnetTable.put(createBinaryString(subnet.prefix()), subnet); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 292 | } else { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 293 | newIp6SubnetTable.put(createBinaryString(subnet.prefix()), subnet); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 294 | } |
| 295 | newVirtualGatewayIpMacMap.put(subnet.gatewayIp(), subnet.gatewayMac()); |
| 296 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 297 | if (!fabricSubnets.equals(newFabricSubnets)) { |
| 298 | fabricSubnets = newFabricSubnets; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 299 | ip4SubnetTable = newIp4SubnetTable; |
| 300 | ip6SubnetTable = newIp6SubnetTable; |
| 301 | dirty = true; |
| 302 | } |
| 303 | if (!virtualGatewayIpMacMap.equals(newVirtualGatewayIpMacMap)) { |
| 304 | virtualGatewayIpMacMap = newVirtualGatewayIpMacMap; |
| 305 | dirty = true; |
| 306 | } |
| 307 | |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 308 | // fabricRoutes config handling |
| 309 | Set<FabricRoute> newFabricRoutes = config.fabricRoutes(); |
| 310 | if (!fabricRoutes.equals(newFabricRoutes)) { |
| 311 | InvertedRadixTree<FabricRoute> newIp4BorderRouteTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 312 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 313 | InvertedRadixTree<FabricRoute> newIp6BorderRouteTable = |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 314 | new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 315 | for (FabricRoute route : newFabricRoutes) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 316 | if (route.prefix().isIp4()) { |
| 317 | newIp4BorderRouteTable.put(createBinaryString(route.prefix()), route); |
| 318 | } else { |
| 319 | newIp6BorderRouteTable.put(createBinaryString(route.prefix()), route); |
| 320 | } |
| 321 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 322 | fabricRoutes = newFabricRoutes; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 323 | ip4BorderRouteTable = newIp4BorderRouteTable; |
| 324 | ip6BorderRouteTable = newIp6BorderRouteTable; |
| 325 | dirty = true; |
| 326 | } |
| 327 | |
| 328 | // notify to SimpleFabric listeners |
| 329 | if (dirty) { |
| 330 | log.info("simple fabric refresh; notify events"); |
| 331 | process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_UPDATED, "updated")); |
| 332 | } |
| 333 | return dirty; |
| 334 | } |
| 335 | |
| 336 | private Interface getInterfaceByName(String interfaceName) { |
| 337 | Interface intf = interfaceService.getInterfaces().stream() |
| 338 | .filter(iface -> iface.name().equals(interfaceName)) |
| 339 | .findFirst() |
| 340 | .orElse(null); |
| 341 | if (intf == null) { |
| 342 | log.warn("simple fabric unknown interface name: {}", interfaceName); |
| 343 | } |
| 344 | return intf; |
| 345 | } |
| 346 | |
| 347 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 348 | public ApplicationId appId() { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 349 | if (appId == null) { |
| 350 | appId = coreService.registerApplication(APP_ID); |
| 351 | } |
| 352 | return appId; |
| 353 | } |
| 354 | |
| 355 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 356 | public Collection<FabricNetwork> fabricNetworks() { |
| 357 | return ImmutableSet.copyOf(fabricNetworks); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 361 | public Set<FabricSubnet> defaultFabricSubnets() { |
| 362 | return ImmutableSet.copyOf(fabricSubnets); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 366 | public Set<FabricRoute> fabricRoutes() { |
| 367 | return ImmutableSet.copyOf(fabricRoutes); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 371 | public boolean isVirtualGatewayMac(MacAddress mac) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 372 | return virtualGatewayIpMacMap.containsValue(mac); |
| 373 | } |
| 374 | |
| 375 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 376 | public boolean isFabricNetworkInterface(Interface intf) { |
| 377 | return networkInterfaces.contains(intf); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 381 | public MacAddress vMacForIp(IpAddress ip) { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 382 | return virtualGatewayIpMacMap.get(ip); |
| 383 | } |
| 384 | |
| 385 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 386 | public FabricNetwork fabricNetwork(ConnectPoint port, VlanId vlanId) { |
| 387 | for (FabricNetwork fabricNetwork : fabricNetworks) { |
| 388 | if (fabricNetwork.contains(port, vlanId)) { |
| 389 | return fabricNetwork; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | return null; |
| 393 | } |
| 394 | |
| 395 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 396 | public FabricNetwork fabricNetwork(String name) { |
| 397 | for (FabricNetwork fabricNetwork : fabricNetworks) { |
| 398 | if (fabricNetwork.name().equals(name)) { |
| 399 | return fabricNetwork; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | return null; |
| 403 | } |
| 404 | |
| 405 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 406 | public FabricSubnet fabricSubnet(IpAddress ip) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 407 | if (ip.isIp4()) { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 408 | return ip4SubnetTable.getValueForLongestKeyPrefixing( |
| 409 | createBinaryString(IpPrefix.valueOf(ip, Ip4Address.BIT_LENGTH))); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 410 | } else { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 411 | return ip6SubnetTable.getValueForLongestKeyPrefixing( |
| 412 | createBinaryString(IpPrefix.valueOf(ip, Ip6Address.BIT_LENGTH))); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 413 | } |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 417 | public FabricRoute fabricRoute(IpAddress ip) { |
| 418 | // ASSUME: ipAddress is out of fabricSubnet |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 419 | if (ip.isIp4()) { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 420 | return ip4BorderRouteTable.getValueForLongestKeyPrefixing( |
| 421 | createBinaryString(IpPrefix.valueOf(ip, Ip4Address.BIT_LENGTH))); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 422 | } else { |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 423 | return ip6BorderRouteTable.getValueForLongestKeyPrefixing( |
| 424 | createBinaryString(IpPrefix.valueOf(ip, Ip6Address.BIT_LENGTH))); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 425 | } |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
| 429 | @Override |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 430 | public Interface hostInterface(Host host) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 431 | return interfaceService.getInterfaces().stream() |
| 432 | .filter(iface -> iface.connectPoint().equals(host.location()) && |
| 433 | iface.vlan().equals(host.vlan())) |
| 434 | .findFirst() |
| 435 | .orElse(null); |
| 436 | } |
| 437 | |
Lee Yongjae | 6dc7e4f | 2017-12-06 16:17:51 +0900 | [diff] [blame] | 438 | private Interface findAvailableDeviceHostInterface(Host host) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 439 | return interfaceService.getInterfaces().stream() |
| 440 | .filter(iface -> iface.connectPoint().equals(host.location()) && |
| 441 | iface.vlan().equals(host.vlan())) |
| 442 | .filter(iface -> deviceService.isAvailable(iface.connectPoint().deviceId())) |
| 443 | .findFirst() |
| 444 | .orElse(null); |
| 445 | } |
| 446 | |
| 447 | @Override |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 448 | public boolean requestMac(IpAddress ip) { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 449 | FabricSubnet fabricSubnet = fabricSubnet(ip); |
| 450 | if (fabricSubnet == null) { |
| 451 | log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 452 | return false; |
| 453 | } |
Jian Li | da0b485 | 2018-08-29 20:40:44 +0900 | [diff] [blame] | 454 | FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName()); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 455 | if (fabricNetwork == null) { |
| 456 | log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}", |
Jian Li | da0b485 | 2018-08-29 20:40:44 +0900 | [diff] [blame] | 457 | fabricSubnet.networkName(), ip); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 458 | return false; |
| 459 | } |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 460 | log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip); |
| 461 | for (Interface iface : fabricNetwork.interfaces()) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 462 | Ethernet neighbourReq; |
| 463 | if (ip.isIp4()) { |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 464 | neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(), |
| 465 | fabricSubnet.gatewayIp().toOctets(), |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 466 | ip.toOctets(), |
| 467 | iface.vlan().toShort()); |
| 468 | } else { |
| 469 | byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets()); |
| 470 | neighbourReq = NeighborSolicitation.buildNdpSolicit( |
| 471 | ip.toOctets(), |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 472 | fabricSubnet.gatewayIp().toOctets(), |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 473 | soliciteIp, |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 474 | fabricSubnet.gatewayMac().toBytes(), |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 475 | IPv6.getMCastMacAddress(soliciteIp), |
| 476 | iface.vlan()); |
| 477 | } |
| 478 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 479 | .setOutput(iface.connectPoint().port()).build(); |
| 480 | OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(), |
| 481 | treatment, ByteBuffer.wrap(neighbourReq.serialize())); |
| 482 | packetService.emit(packet); |
| 483 | } |
| 484 | return true; |
| 485 | } |
| 486 | |
| 487 | @Override |
| 488 | public void dumpToStream(String subject, OutputStream out) { |
| 489 | SimpleFabricEvent event = new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_DUMP, subject, out); |
| 490 | dump(event.subject(), event.out()); // dump in itself |
| 491 | process(event); // dump in sub modules |
| 492 | } |
| 493 | |
| 494 | // Dump handler |
| 495 | protected void dump(String subject, PrintStream out) { |
Ray Milkey | 2ff6716 | 2018-01-22 10:14:19 -0800 | [diff] [blame] | 496 | if ("show".equals(subject)) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 497 | out.println("Static Configuration Flag:"); |
Jian Li | 8df54a9 | 2018-08-23 17:01:31 +0900 | [diff] [blame] | 498 | out.println(" ALLOW_IPV6=" + ALLOW_IPV6); |
| 499 | out.println(" ALLOW_ETH_ADDRESS_SELECTOR=" + ALLOW_ETH_ADDRESS_SELECTOR); |
| 500 | out.println(" REACTIVE_SINGLE_TO_SINGLE=" + REACTIVE_SINGLE_TO_SINGLE); |
| 501 | out.println(" REACTIVE_ALLOW_LINK_CP=" + REACTIVE_ALLOW_LINK_CP); |
| 502 | out.println(" REACTIVE_HASHED_PATH_SELECTION=" + REACTIVE_HASHED_PATH_SELECTION); |
| 503 | out.println(" REACTIVE_MATCH_IP_PROTO=" + REACTIVE_MATCH_IP_PROTO); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 504 | out.println(""); |
| 505 | out.println("SimpleFabricAppId:"); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 506 | out.println(" " + appId()); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 507 | out.println(""); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 508 | out.println("fabricNetworks:"); |
| 509 | for (FabricNetwork fabricNetwork : fabricNetworks()) { |
| 510 | out.println(" " + fabricNetwork); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 511 | } |
| 512 | out.println(""); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 513 | out.println("fabricSubnets:"); |
| 514 | for (FabricSubnet fabricIpSubnet : defaultFabricSubnets()) { |
| 515 | out.println(" " + fabricIpSubnet); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 516 | } |
| 517 | out.println(""); |
Jian Li | e2d8751 | 2018-08-23 17:33:05 +0900 | [diff] [blame] | 518 | out.println("fabricRoutes:"); |
| 519 | for (FabricRoute route : fabricRoutes()) { |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 520 | out.println(" " + route); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // Refresh action thread and notifier |
| 526 | |
| 527 | private class InternalRefreshThread extends Thread { |
Yuta HIGUCHI | c2bf02a | 2018-03-29 08:40:35 -0700 | [diff] [blame] | 528 | @Override |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 529 | public void run() { |
| 530 | while (true) { |
| 531 | boolean doRefreshMarked = false; |
| 532 | boolean doFlushMarked = false; |
| 533 | synchronized (refreshMonitor) { |
| 534 | if (!doRefresh && !doFlush) { |
| 535 | try { |
| 536 | refreshMonitor.wait(IDLE_INTERVAL_MSEC); |
| 537 | } catch (InterruptedException e) { |
Ray Milkey | 5c7d488 | 2018-02-05 14:50:39 -0800 | [diff] [blame] | 538 | log.warn("run thread interrupted", e); |
| 539 | Thread.currentThread().interrupt(); |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | doRefreshMarked = doRefresh; |
| 543 | doRefresh = false; |
| 544 | doFlushMarked = doFlush; |
| 545 | doFlush = false; |
| 546 | } |
| 547 | if (doRefreshMarked) { |
| 548 | try { |
| 549 | refresh(); |
| 550 | } catch (Exception e) { |
| 551 | log.warn("simple fabric refresh failed: exception={}", e); |
| 552 | } |
| 553 | } |
| 554 | if (doFlushMarked) { |
| 555 | try { |
| 556 | log.info("simple fabric flush execute"); |
| 557 | process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_FLUSH, "flush")); |
| 558 | } catch (Exception e) { |
| 559 | log.warn("simple fabric flush failed: exception={}", e); |
| 560 | } |
| 561 | } |
| 562 | if (!doRefreshMarked && !doFlushMarked) { |
| 563 | try { |
| 564 | if (!refresh()) { |
| 565 | process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_IDLE, "idle")); |
| 566 | } |
| 567 | } catch (Exception e) { |
| 568 | log.warn("simple fabric idle failed: exception={}", e); |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public void triggerRefresh() { |
| 577 | synchronized (refreshMonitor) { |
| 578 | doRefresh = true; |
| 579 | refreshMonitor.notifyAll(); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public void triggerFlush() { |
| 585 | synchronized (refreshMonitor) { |
| 586 | doFlush = true; |
| 587 | refreshMonitor.notifyAll(); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | // Service Listeners |
| 592 | |
| 593 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 594 | @Override |
| 595 | public void event(NetworkConfigEvent event) { |
| 596 | switch (event.type()) { |
| 597 | case CONFIG_REGISTERED: |
| 598 | case CONFIG_UNREGISTERED: |
| 599 | case CONFIG_ADDED: |
| 600 | case CONFIG_UPDATED: |
| 601 | case CONFIG_REMOVED: |
| 602 | if (event.configClass().equals(SimpleFabricConfig.class)) { |
| 603 | triggerRefresh(); |
| 604 | } |
| 605 | break; |
| 606 | default: |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | private class InternalDeviceListener implements DeviceListener { |
| 613 | @Override |
| 614 | public void event(DeviceEvent event) { |
| 615 | switch (event.type()) { |
| 616 | case DEVICE_ADDED: |
| 617 | case DEVICE_AVAILABILITY_CHANGED: |
| 618 | case DEVICE_REMOVED: |
| 619 | case DEVICE_SUSPENDED: |
| 620 | case DEVICE_UPDATED: |
| 621 | case PORT_ADDED: |
| 622 | case PORT_REMOVED: |
| 623 | case PORT_UPDATED: |
| 624 | // case PORT_STATS_UPDATED: IGNORED |
| 625 | triggerRefresh(); |
| 626 | break; |
| 627 | default: |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | private class InternalHostListener implements HostListener { |
| 634 | @Override |
| 635 | public void event(HostEvent event) { |
| 636 | Host host = event.subject(); |
| 637 | Host prevHost = event.prevSubject(); |
| 638 | switch (event.type()) { |
| 639 | case HOST_MOVED: |
| 640 | case HOST_REMOVED: |
| 641 | case HOST_ADDED: |
| 642 | case HOST_UPDATED: |
| 643 | triggerRefresh(); |
| 644 | break; |
| 645 | default: |
| 646 | break; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | private class InternalInterfaceListener implements InterfaceListener { |
| 652 | @Override |
| 653 | public void event(InterfaceEvent event) { |
| 654 | Interface iface = event.subject(); |
| 655 | Interface prevIface = event.prevSubject(); |
| 656 | switch (event.type()) { |
| 657 | case INTERFACE_ADDED: |
| 658 | case INTERFACE_REMOVED: |
| 659 | case INTERFACE_UPDATED: |
| 660 | triggerRefresh(); |
| 661 | break; |
| 662 | default: |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | } |
| 669 | |