Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 17 | package org.onosproject.routing.impl; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.ConcurrentHashMultiset; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Maps; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 21 | import com.google.common.collect.Multiset; |
| 22 | import org.apache.felix.scr.annotations.Activate; |
| 23 | import org.apache.felix.scr.annotations.Component; |
| 24 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Modified; |
| 26 | import org.apache.felix.scr.annotations.Property; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Reference; |
| 28 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 29 | import org.onlab.packet.Ethernet; |
| 30 | import org.onlab.packet.IpAddress; |
| 31 | import org.onlab.packet.IpPrefix; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 32 | import org.onlab.packet.MacAddress; |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 33 | import org.onlab.packet.VlanId; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 34 | import org.onlab.util.Tools; |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 35 | import org.onosproject.app.ApplicationService; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 36 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 37 | import org.onosproject.core.ApplicationId; |
| 38 | import org.onosproject.core.CoreService; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 39 | import org.onosproject.incubator.net.config.basics.McastConfig; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 40 | import org.onosproject.incubator.net.intf.Interface; |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 41 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
| 42 | import org.onosproject.incubator.net.intf.InterfaceListener; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 43 | import org.onosproject.incubator.net.intf.InterfaceService; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 44 | import org.onosproject.incubator.net.routing.ResolvedRoute; |
| 45 | import org.onosproject.incubator.net.routing.RouteEvent; |
| 46 | import org.onosproject.incubator.net.routing.RouteListener; |
| 47 | import org.onosproject.incubator.net.routing.RouteService; |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 48 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 49 | import org.onosproject.net.DeviceId; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 50 | import org.onosproject.net.config.ConfigFactory; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 51 | import org.onosproject.net.config.NetworkConfigEvent; |
| 52 | import org.onosproject.net.config.NetworkConfigListener; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 53 | import org.onosproject.net.config.NetworkConfigRegistry; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 54 | import org.onosproject.net.config.NetworkConfigService; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 55 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 56 | import org.onosproject.net.device.DeviceEvent; |
| 57 | import org.onosproject.net.device.DeviceListener; |
| 58 | import org.onosproject.net.device.DeviceService; |
| 59 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 60 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 61 | import org.onosproject.net.flow.TrafficSelector; |
| 62 | import org.onosproject.net.flow.TrafficTreatment; |
| 63 | import org.onosproject.net.flow.criteria.Criteria; |
| 64 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 65 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 66 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 67 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 68 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 69 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 70 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 71 | import org.onosproject.net.flowobjective.NextObjective; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 72 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 73 | import org.onosproject.routing.RoutingService; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 74 | import org.onosproject.routing.config.RouterConfig; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 75 | import org.osgi.service.component.ComponentContext; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 76 | import org.slf4j.Logger; |
| 77 | import org.slf4j.LoggerFactory; |
| 78 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 79 | import java.util.Dictionary; |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 80 | import java.util.List; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 81 | import java.util.Map; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 82 | import java.util.Set; |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 83 | import java.util.stream.Collectors; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Programs routes to a single OpenFlow switch. |
| 87 | */ |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 88 | @Component(immediate = true, enabled = false) |
| 89 | public class SingleSwitchFibInstaller { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 90 | |
| 91 | private final Logger log = LoggerFactory.getLogger(getClass()); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 92 | private static final String APP_NAME = "org.onosproject.vrouter"; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 93 | |
| 94 | private static final int PRIORITY_OFFSET = 100; |
| 95 | private static final int PRIORITY_MULTIPLIER = 5; |
| 96 | |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame^] | 97 | // FIXME: This should be eliminated when we have an API in SR that |
| 98 | // programs the fabric switches for VR |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 99 | public static final short ASSIGNED_VLAN = 4094; |
| 100 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected CoreService coreService; |
| 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 105 | protected RouteService routeService; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 108 | protected InterfaceService interfaceService; |
| 109 | |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 111 | protected NetworkConfigService networkConfigService; |
| 112 | |
| 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 114 | protected NetworkConfigRegistry networkConfigRegistry; |
| 115 | |
| 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 117 | protected ComponentConfigService componentConfigService; |
| 118 | |
| 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 120 | protected FlowObjectiveService flowObjectiveService; |
| 121 | |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 123 | protected DeviceService deviceService; |
| 124 | |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 126 | protected ApplicationService applicationService; |
| 127 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 128 | @Property(name = "routeToNextHop", boolValue = false, |
| 129 | label = "Install a /32 route to each next hop") |
| 130 | private boolean routeToNextHop = false; |
| 131 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 132 | // Device id of data-plane switch - should be learned from config |
| 133 | private DeviceId deviceId; |
| 134 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 135 | private ConnectPoint controlPlaneConnectPoint; |
| 136 | |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 137 | private List<String> interfaces; |
| 138 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 139 | private ApplicationId coreAppId; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 140 | private ApplicationId routerAppId; |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 141 | private ApplicationId vrouterAppId; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 142 | |
| 143 | // Reference count for how many times a next hop is used by a route |
| 144 | private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create(); |
| 145 | |
| 146 | // Mapping from prefix to its current next hop |
| 147 | private final Map<IpPrefix, IpAddress> prefixToNextHop = Maps.newHashMap(); |
| 148 | |
| 149 | // Mapping from next hop IP to next hop object containing group info |
| 150 | private final Map<IpAddress, Integer> nextHops = Maps.newHashMap(); |
| 151 | |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 152 | private final InternalDeviceListener deviceListener = new InternalDeviceListener(); |
| 153 | private final InternalInterfaceListener internalInterfaceList = new InternalInterfaceListener(); |
| 154 | private final InternalRouteListener routeListener = new InternalRouteListener(); |
| 155 | private final InternalNetworkConfigListener configListener = new InternalNetworkConfigListener(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 156 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 157 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
| 158 | new ConfigFactory<ApplicationId, McastConfig>(SubjectFactories.APP_SUBJECT_FACTORY, |
| 159 | McastConfig.class, "multicast") { |
| 160 | @Override |
| 161 | public McastConfig createConfig() { |
| 162 | return new McastConfig(); |
| 163 | } |
| 164 | }; |
| 165 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 166 | @Activate |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 167 | protected void activate(ComponentContext context) { |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 168 | componentConfigService.registerProperties(getClass()); |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 169 | modified(context); |
| 170 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 171 | coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME); |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 172 | routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 173 | vrouterAppId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 174 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 175 | networkConfigRegistry.registerConfigFactory(mcastConfigFactory); |
| 176 | |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 177 | networkConfigService.addListener(configListener); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 178 | deviceService.addListener(deviceListener); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 179 | interfaceService.addListener(internalInterfaceList); |
| 180 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 181 | updateConfig(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 182 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 183 | // FIXME: There can be an issue when this component is deactivated before vRouter. |
| 184 | // This will be addressed in CORD-710. |
Jonathan Hart | f8035d3 | 2016-06-16 16:23:26 -0700 | [diff] [blame] | 185 | applicationService.registerDeactivateHook(vrouterAppId, () -> cleanUp()); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 186 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 187 | log.info("Started"); |
| 188 | } |
| 189 | |
| 190 | @Deactivate |
| 191 | protected void deactivate() { |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 192 | // FIXME: This will also remove flows when an instance goes down. |
| 193 | // This is a temporary solution and should be addressed in CORD-710. |
| 194 | cleanUp(); |
| 195 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 196 | deviceService.removeListener(deviceListener); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 197 | interfaceService.removeListener(internalInterfaceList); |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 198 | networkConfigService.removeListener(configListener); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 199 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 200 | componentConfigService.unregisterProperties(getClass(), false); |
| 201 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 202 | log.info("Stopped"); |
| 203 | } |
| 204 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 205 | @Modified |
| 206 | protected void modified(ComponentContext context) { |
| 207 | Dictionary<?, ?> properties = context.getProperties(); |
| 208 | if (properties == null) { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | String strRouteToNextHop = Tools.get(properties, "routeToNextHop"); |
| 213 | routeToNextHop = Boolean.parseBoolean(strRouteToNextHop); |
| 214 | |
| 215 | log.info("routeToNextHop set to {}", routeToNextHop); |
| 216 | } |
| 217 | |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 218 | //remove filtering objectives and routes before deactivate. |
| 219 | private void cleanUp() { |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 220 | //remove the route listener |
| 221 | routeService.removeListener(routeListener); |
| 222 | |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 223 | //clean up the routes. |
| 224 | for (Map.Entry<IpPrefix, IpAddress> routes: prefixToNextHop.entrySet()) { |
Charles Chan | 8fe9f4c | 2016-10-24 16:46:25 -0700 | [diff] [blame] | 225 | deleteRoute(new ResolvedRoute(routes.getKey(), null, null, null)); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 226 | } |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 227 | |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 228 | //clean up the filtering objective for interfaces. |
| 229 | Set<Interface> intfs = getInterfaces(); |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 230 | if (!intfs.isEmpty()) { |
| 231 | processIntfFilters(false, intfs); |
| 232 | } |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 233 | } |
| 234 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 235 | private void updateConfig() { |
| 236 | RouterConfig routerConfig = |
| 237 | networkConfigService.getConfig(routerAppId, RoutingService.ROUTER_CONFIG_CLASS); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 238 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 239 | if (routerConfig == null) { |
| 240 | log.info("Router config not available"); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 241 | return; |
| 242 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 243 | controlPlaneConnectPoint = routerConfig.getControlPlaneConnectPoint(); |
| 244 | log.info("Control Plane Connect Point: {}", controlPlaneConnectPoint); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 245 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 246 | deviceId = routerConfig.getControlPlaneConnectPoint().deviceId(); |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 247 | log.info("Router device ID is {}", deviceId); |
| 248 | |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 249 | interfaces = routerConfig.getInterfaces(); |
| 250 | log.info("Using interfaces: {}", interfaces.isEmpty() ? "all" : interfaces); |
| 251 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 252 | routeService.addListener(routeListener); |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 253 | updateDevice(); |
| 254 | } |
| 255 | |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 256 | //remove the filtering objective for interfaces which are no longer part of vRouter config. |
| 257 | private void removeFilteringObjectives(NetworkConfigEvent event) { |
| 258 | RouterConfig prevRouterConfig = (RouterConfig) event.prevConfig().get(); |
| 259 | List<String> prevInterfaces = prevRouterConfig.getInterfaces(); |
| 260 | |
| 261 | Set<Interface> previntfs = filterInterfaces(prevInterfaces); |
| 262 | //if previous interface list is empty it means filtering objectives are |
| 263 | //installed for all the interfaces. |
| 264 | if (previntfs.isEmpty() && !interfaces.isEmpty()) { |
| 265 | Set<Interface> allIntfs = interfaceService.getInterfaces(); |
| 266 | for (Interface allIntf : allIntfs) { |
| 267 | if (!interfaces.contains(allIntf.name())) { |
| 268 | processIntfFilter(false, allIntf); |
| 269 | } |
| 270 | } |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | //remove the filtering objective for the interfaces which are not |
| 275 | //part of updated interfaces list. |
| 276 | for (Interface prevIntf : previntfs) { |
| 277 | if (!interfaces.contains(prevIntf.name())) { |
| 278 | processIntfFilter(false, prevIntf); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 283 | private void updateDevice() { |
| 284 | if (deviceId != null && deviceService.isAvailable(deviceId)) { |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 285 | Set<Interface> intfs = getInterfaces(); |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 286 | processIntfFilters(true, intfs); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 287 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 288 | } |
| 289 | |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 290 | private Set<Interface> getInterfaces() { |
| 291 | Set<Interface> intfs; |
Charles Chan | 14ed0b6 | 2016-12-03 22:40:36 -0800 | [diff] [blame] | 292 | if (interfaces == null || interfaces.isEmpty()) { |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 293 | intfs = interfaceService.getInterfaces(); |
| 294 | } else { |
| 295 | // TODO need to fix by making interface names globally unique |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 296 | intfs = filterInterfaces(interfaces); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 297 | } |
| 298 | return intfs; |
| 299 | } |
| 300 | |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 301 | private Set<Interface> filterInterfaces(List<String> interfaces) { |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 302 | return interfaceService.getInterfaces().stream() |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 303 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
| 304 | .filter(intf -> interfaces.contains(intf.name())) |
| 305 | .collect(Collectors.toSet()); |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 306 | } |
| 307 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 308 | private void updateRoute(ResolvedRoute route) { |
| 309 | addNextHop(route); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 310 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 311 | Integer nextId; |
| 312 | synchronized (this) { |
| 313 | nextId = nextHops.get(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 316 | flowObjectiveService.forward(deviceId, |
| 317 | generateRibForwardingObj(route.prefix(), nextId).add()); |
| 318 | log.trace("Sending forwarding objective {} -> nextId:{}", route, nextId); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 321 | private synchronized void deleteRoute(ResolvedRoute route) { |
| 322 | //Integer nextId = nextHops.get(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 323 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 324 | /* Group group = deleteNextHop(route.prefix()); |
| 325 | if (group == null) { |
| 326 | log.warn("Group not found when deleting {}", route); |
| 327 | return; |
| 328 | }*/ |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 329 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 330 | flowObjectiveService.forward(deviceId, |
| 331 | generateRibForwardingObj(route.prefix(), null).remove()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix, |
| 335 | Integer nextId) { |
| 336 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 337 | .matchEthType(Ethernet.TYPE_IPV4) |
| 338 | .matchIPDst(prefix) |
| 339 | .build(); |
| 340 | |
| 341 | int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; |
| 342 | |
| 343 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 344 | .fromApp(routerAppId) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 345 | .makePermanent() |
| 346 | .withSelector(selector) |
| 347 | .withPriority(priority) |
| 348 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 349 | |
| 350 | if (nextId == null) { |
| 351 | // Route withdraws are not specified with next hops. Generating |
| 352 | // dummy treatment as there is no equivalent nextId info. |
| 353 | fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); |
| 354 | } else { |
| 355 | fwdBuilder.nextStep(nextId); |
| 356 | } |
| 357 | return fwdBuilder; |
| 358 | } |
| 359 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 360 | private synchronized void addNextHop(ResolvedRoute route) { |
| 361 | prefixToNextHop.put(route.prefix(), route.nextHop()); |
| 362 | if (nextHopsCount.count(route.nextHop()) == 0) { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 363 | // There was no next hop in the multiset |
| 364 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 365 | Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 366 | if (egressIntf == null) { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 367 | log.warn("no egress interface found for {}", route); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 371 | NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 372 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 373 | NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 374 | |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 375 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 376 | .setEthSrc(egressIntf.mac()) |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 377 | .setEthDst(nextHop.mac()); |
| 378 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 379 | TrafficSelector.Builder metabuilder = null; |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 380 | if (!egressIntf.vlan().equals(VlanId.NONE)) { |
| 381 | treatment.pushVlan() |
| 382 | .setVlanId(egressIntf.vlan()) |
| 383 | .setVlanPcp((byte) 0); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 384 | } else { |
| 385 | // untagged outgoing port may require internal vlan in some pipelines |
| 386 | metabuilder = DefaultTrafficSelector.builder(); |
| 387 | metabuilder.matchVlanId(VlanId.vlanId(ASSIGNED_VLAN)); |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | treatment.setOutput(egressIntf.connectPoint().port()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 391 | |
| 392 | int nextId = flowObjectiveService.allocateNextId(); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 393 | NextObjective.Builder nextBuilder = DefaultNextObjective.builder() |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 394 | .withId(nextId) |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 395 | .addTreatment(treatment.build()) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 396 | .withType(NextObjective.Type.SIMPLE) |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 397 | .fromApp(routerAppId); |
| 398 | if (metabuilder != null) { |
| 399 | nextBuilder.withMeta(metabuilder.build()); |
| 400 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 401 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 402 | NextObjective nextObjective = nextBuilder.add(); // TODO add callbacks |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 403 | flowObjectiveService.next(deviceId, nextObjective); |
| 404 | |
| 405 | nextHops.put(nextHop.ip(), nextId); |
| 406 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 407 | if (routeToNextHop) { |
| 408 | // Install route to next hop |
| 409 | ForwardingObjective fob = |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 410 | generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add(); |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 411 | flowObjectiveService.forward(deviceId, fob); |
| 412 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 413 | } |
| 414 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 415 | nextHopsCount.add(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /*private synchronized Group deleteNextHop(IpPrefix prefix) { |
| 419 | IpAddress nextHopIp = prefixToNextHop.remove(prefix); |
| 420 | NextHop nextHop = nextHops.get(nextHopIp); |
| 421 | if (nextHop == null) { |
| 422 | log.warn("No next hop found when removing prefix {}", prefix); |
| 423 | return null; |
| 424 | } |
| 425 | |
| 426 | Group group = groupService.getGroup(deviceId, |
| 427 | new DefaultGroupKey(appKryo. |
| 428 | serialize(nextHop.group()))); |
| 429 | |
| 430 | // FIXME disabling group deletes for now until we verify the logic is OK |
| 431 | if (nextHopsCount.remove(nextHopIp, 1) <= 1) { |
| 432 | // There was one or less next hops, so there are now none |
| 433 | |
| 434 | log.debug("removing group for next hop {}", nextHop); |
| 435 | |
| 436 | nextHops.remove(nextHopIp); |
| 437 | |
| 438 | groupService.removeGroup(deviceId, |
| 439 | new DefaultGroupKey(appKryo.build().serialize(nextHop.group())), |
| 440 | appId); |
| 441 | } |
| 442 | |
| 443 | return group; |
| 444 | }*/ |
| 445 | |
| 446 | private void processIntfFilters(boolean install, Set<Interface> intfs) { |
| 447 | log.info("Processing {} router interfaces", intfs.size()); |
| 448 | for (Interface intf : intfs) { |
| 449 | if (!intf.connectPoint().deviceId().equals(deviceId)) { |
| 450 | // Ignore interfaces if they are not on the router switch |
| 451 | continue; |
| 452 | } |
| 453 | |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 454 | createFilteringObjective(install, intf); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 455 | createMcastFilteringObjective(install, intf); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 456 | } |
| 457 | } |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 458 | |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 459 | //process filtering objective for interface add/remove. |
| 460 | private void processIntfFilter(boolean install, Interface intf) { |
| 461 | |
| 462 | if (!intf.connectPoint().deviceId().equals(deviceId)) { |
| 463 | // Ignore interfaces if they are not on the router switch |
| 464 | return; |
| 465 | } |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 466 | if (!interfaces.contains(intf.name()) && install) { |
| 467 | return; |
| 468 | } |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 469 | |
| 470 | createFilteringObjective(install, intf); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 471 | createMcastFilteringObjective(install, intf); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | //create filtering objective for interface |
| 475 | private void createFilteringObjective(boolean install, Interface intf) { |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 476 | VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? |
| 477 | VlanId.vlanId(ASSIGNED_VLAN) : |
| 478 | egressVlan(); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 479 | |
| 480 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 481 | // first add filter for the interface |
| 482 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
| 483 | .addCondition(Criteria.matchEthDst(intf.mac())) |
| 484 | .addCondition(Criteria.matchVlanId(intf.vlan())); |
| 485 | fob.withPriority(PRIORITY_OFFSET); |
| 486 | if (intf.vlan() == VlanId.NONE) { |
| 487 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 488 | .pushVlan().setVlanId(assignedVlan).build(); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 489 | fob.withMeta(tt); |
| 490 | } |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 491 | fob.permit().fromApp(routerAppId); |
| 492 | sendFilteringObjective(install, fob, intf); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 493 | |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 494 | if (controlPlaneConnectPoint != null) { |
| 495 | // then add the same mac/vlan filters for control-plane connect point |
| 496 | fob.withKey(Criteria.matchInPort(controlPlaneConnectPoint.port())); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 497 | sendFilteringObjective(install, fob, intf); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 501 | //create filtering objective for multicast traffic |
| 502 | private void createMcastFilteringObjective(boolean install, Interface intf) { |
| 503 | VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? |
| 504 | VlanId.vlanId(ASSIGNED_VLAN) : |
| 505 | egressVlan(); |
| 506 | |
| 507 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 508 | // first add filter for the interface |
| 509 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
| 510 | .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, |
| 511 | MacAddress.IPV4_MULTICAST_MASK)) |
| 512 | .addCondition(Criteria.matchVlanId(ingressVlan())); |
| 513 | fob.withPriority(PRIORITY_OFFSET); |
| 514 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
| 515 | .pushVlan().setVlanId(assignedVlan).build(); |
| 516 | fob.withMeta(tt); |
| 517 | |
| 518 | fob.permit().fromApp(routerAppId); |
| 519 | sendFilteringObjective(install, fob, intf); |
| 520 | } |
| 521 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 522 | private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, |
| 523 | Interface intf) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 524 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 525 | ObjectiveContext context = new DefaultObjectiveContext( |
| 526 | (objective) -> log.info("Installed filter for interface {}", intf), |
| 527 | (objective, error) -> |
| 528 | log.error("Failed to install filter for interface {}: {}", intf, error)); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 529 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 530 | FilteringObjective filter = install ? fob.add(context) : fob.remove(context); |
| 531 | |
| 532 | flowObjectiveService.filter(deviceId, filter); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 535 | private VlanId ingressVlan() { |
| 536 | McastConfig mcastConfig = |
| 537 | networkConfigService.getConfig(coreAppId, McastConfig.class); |
| 538 | return (mcastConfig != null) ? mcastConfig.ingressVlan() : VlanId.NONE; |
| 539 | } |
| 540 | |
| 541 | private VlanId egressVlan() { |
| 542 | McastConfig mcastConfig = |
| 543 | networkConfigService.getConfig(coreAppId, McastConfig.class); |
| 544 | return (mcastConfig != null) ? mcastConfig.egressVlan() : VlanId.NONE; |
| 545 | } |
| 546 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 547 | private class InternalRouteListener implements RouteListener { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 548 | @Override |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 549 | public void event(RouteEvent event) { |
| 550 | ResolvedRoute route = event.subject(); |
| 551 | switch (event.type()) { |
| 552 | case ROUTE_ADDED: |
| 553 | case ROUTE_UPDATED: |
| 554 | updateRoute(route); |
| 555 | break; |
| 556 | case ROUTE_REMOVED: |
| 557 | deleteRoute(route); |
| 558 | break; |
| 559 | default: |
| 560 | break; |
| 561 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 565 | /** |
| 566 | * Listener for device events used to trigger driver setup when a device is |
| 567 | * (re)detected. |
| 568 | */ |
| 569 | private class InternalDeviceListener implements DeviceListener { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 570 | @Override |
| 571 | public void event(DeviceEvent event) { |
| 572 | switch (event.type()) { |
| 573 | case DEVICE_ADDED: |
| 574 | case DEVICE_AVAILABILITY_CHANGED: |
| 575 | if (deviceService.isAvailable(event.subject().id())) { |
| 576 | log.info("Device connected {}", event.subject().id()); |
| 577 | if (event.subject().id().equals(deviceId)) { |
Charles Chan | f555a73 | 2016-02-15 15:37:15 -0800 | [diff] [blame] | 578 | updateDevice(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | break; |
| 582 | // TODO other cases |
| 583 | case DEVICE_UPDATED: |
| 584 | case DEVICE_REMOVED: |
| 585 | case DEVICE_SUSPENDED: |
| 586 | case PORT_ADDED: |
| 587 | case PORT_UPDATED: |
| 588 | case PORT_REMOVED: |
| 589 | default: |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | } |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 594 | |
| 595 | /** |
| 596 | * Listener for network config events. |
| 597 | */ |
| 598 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 599 | @Override |
| 600 | public void event(NetworkConfigEvent event) { |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 601 | if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) { |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 602 | switch (event.type()) { |
| 603 | case CONFIG_ADDED: |
| 604 | case CONFIG_UPDATED: |
| 605 | updateConfig(); |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 606 | if (event.prevConfig().isPresent()) { |
| 607 | removeFilteringObjectives(event); |
| 608 | } |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 609 | break; |
| 610 | case CONFIG_REGISTERED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 611 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 612 | case CONFIG_UNREGISTERED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 613 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 614 | case CONFIG_REMOVED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 615 | cleanUp(); |
| 616 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 617 | default: |
| 618 | break; |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | } |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 623 | |
| 624 | private class InternalInterfaceListener implements InterfaceListener { |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 625 | @Override |
| 626 | public void event(InterfaceEvent event) { |
| 627 | Interface intf = event.subject(); |
| 628 | switch (event.type()) { |
| 629 | case INTERFACE_ADDED: |
| 630 | if (intf != null) { |
| 631 | processIntfFilter(true, intf); |
| 632 | } |
| 633 | break; |
| 634 | case INTERFACE_UPDATED: |
| 635 | break; |
| 636 | case INTERFACE_REMOVED: |
| 637 | if (intf != null) { |
| 638 | processIntfFilter(false, intf); |
| 639 | } |
| 640 | break; |
| 641 | default: |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 646 | } |