Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
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 | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 17 | package org.onosproject.routing.fibinstaller; |
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; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ethernet; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.IpPrefix; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 27 | import org.onlab.util.Tools; |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 28 | import org.onosproject.app.ApplicationService; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.CoreService; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 32 | import org.onosproject.net.DeviceId; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 33 | import org.onosproject.net.config.ConfigFactory; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 34 | import org.onosproject.net.config.NetworkConfigEvent; |
| 35 | import org.onosproject.net.config.NetworkConfigListener; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 36 | import org.onosproject.net.config.NetworkConfigRegistry; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 37 | import org.onosproject.net.config.NetworkConfigService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.basics.McastConfig; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 39 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 40 | import org.onosproject.net.device.DeviceService; |
| 41 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 42 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.flow.criteria.Criteria; |
| 46 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 47 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 48 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 51 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 52 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 53 | import org.onosproject.net.flowobjective.NextObjective; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 55 | import org.onosproject.net.intf.Interface; |
| 56 | import org.onosproject.net.intf.InterfaceService; |
| 57 | import org.onosproject.routeservice.ResolvedRoute; |
| 58 | import org.onosproject.routeservice.Route; |
| 59 | import org.onosproject.routeservice.RouteEvent; |
| 60 | import org.onosproject.routeservice.RouteListener; |
| 61 | import org.onosproject.routeservice.RouteService; |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 62 | import org.onosproject.routing.InterfaceProvisionRequest; |
Jonathan Hart | f4bd048 | 2017-01-27 15:11:18 -0800 | [diff] [blame] | 63 | import org.onosproject.routing.NextHop; |
| 64 | import org.onosproject.routing.NextHopGroupKey; |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 65 | import org.onosproject.routing.Router; |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 66 | import org.onosproject.routing.RouterInfo; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 67 | import org.onosproject.routing.RoutingService; |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 68 | import org.onosproject.routing.config.RoutersConfig; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 69 | import org.onosproject.routing.config.RoutingConfiguration; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 70 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 71 | import org.osgi.service.component.annotations.Activate; |
| 72 | import org.osgi.service.component.annotations.Component; |
| 73 | import org.osgi.service.component.annotations.Deactivate; |
| 74 | import org.osgi.service.component.annotations.Modified; |
| 75 | import org.osgi.service.component.annotations.Reference; |
| 76 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 77 | import org.slf4j.Logger; |
| 78 | import org.slf4j.LoggerFactory; |
| 79 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 80 | import java.util.Dictionary; |
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; |
| 83 | |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 84 | import static org.onosproject.routing.fibinstaller.OsgiPropertyConstants.ROUTE_TO_NEXT_HOP; |
| 85 | import static org.onosproject.routing.fibinstaller.OsgiPropertyConstants.ROUTE_TO_NEXT_HOP_DEFAULT; |
| 86 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Programs routes to a single OpenFlow switch. |
| 89 | */ |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 90 | @Component( |
| 91 | immediate = true, |
| 92 | property = { |
| 93 | ROUTE_TO_NEXT_HOP + ":Boolean= " + ROUTE_TO_NEXT_HOP_DEFAULT |
| 94 | } |
| 95 | ) |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 96 | public class FibInstaller { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 97 | |
| 98 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 99 | private static final String APP_NAME = "org.onosproject.fibinstaller"; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 100 | |
| 101 | private static final int PRIORITY_OFFSET = 100; |
| 102 | private static final int PRIORITY_MULTIPLIER = 5; |
| 103 | |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 104 | // FIXME: This should be eliminated when we have an API in SR that |
| 105 | // programs the fabric switches for VR |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 106 | public static final short ASSIGNED_VLAN = 4094; |
| 107 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 109 | protected CoreService coreService; |
| 110 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 112 | protected RouteService routeService; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 113 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 115 | protected InterfaceService interfaceService; |
| 116 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 118 | protected NetworkConfigService networkConfigService; |
| 119 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 120 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 121 | protected NetworkConfigRegistry networkConfigRegistry; |
| 122 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 123 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 124 | protected ComponentConfigService componentConfigService; |
| 125 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 126 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 127 | protected FlowObjectiveService flowObjectiveService; |
| 128 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 129 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 130 | protected DeviceService deviceService; |
| 131 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 132 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 133 | protected ApplicationService applicationService; |
| 134 | |
Ray Milkey | 8e40651 | 2018-10-24 15:56:50 -0700 | [diff] [blame] | 135 | /** Install a /32 or /128 route to each next hop. */ |
| 136 | private boolean routeToNextHop = ROUTE_TO_NEXT_HOP_DEFAULT; |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 137 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 138 | // Device id of data-plane switch - should be learned from config |
| 139 | private DeviceId deviceId; |
| 140 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 141 | private Router interfaceManager; |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 142 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 143 | private ApplicationId coreAppId; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 144 | private ApplicationId routerAppId; |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 145 | private ApplicationId fibAppId; |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 146 | |
| 147 | // Reference count for how many times a next hop is used by a route |
| 148 | private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create(); |
| 149 | |
| 150 | // Mapping from prefix to its current next hop |
| 151 | private final Map<IpPrefix, IpAddress> prefixToNextHop = Maps.newHashMap(); |
| 152 | |
| 153 | // Mapping from next hop IP to next hop object containing group info |
| 154 | private final Map<IpAddress, Integer> nextHops = Maps.newHashMap(); |
| 155 | |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 156 | private final InternalRouteListener routeListener = new InternalRouteListener(); |
| 157 | private final InternalNetworkConfigListener configListener = new InternalNetworkConfigListener(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 158 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 159 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
| 160 | new ConfigFactory<ApplicationId, McastConfig>(SubjectFactories.APP_SUBJECT_FACTORY, |
| 161 | McastConfig.class, "multicast") { |
| 162 | @Override |
| 163 | public McastConfig createConfig() { |
| 164 | return new McastConfig(); |
| 165 | } |
| 166 | }; |
| 167 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 168 | @Activate |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 169 | protected void activate(ComponentContext context) { |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 170 | componentConfigService.registerProperties(getClass()); |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 171 | modified(context); |
| 172 | |
Jonathan Hart | 60e7f51 | 2017-02-10 10:24:24 -0800 | [diff] [blame] | 173 | RoutingConfiguration.register(networkConfigRegistry); |
| 174 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 175 | coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME); |
Jonathan Hart | 9ad777f | 2016-02-19 12:44:36 -0800 | [diff] [blame] | 176 | routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID); |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 177 | fibAppId = coreService.registerApplication(APP_NAME); |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 178 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 179 | networkConfigRegistry.registerConfigFactory(mcastConfigFactory); |
| 180 | |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 181 | networkConfigService.addListener(configListener); |
Jonathan Hart | f8cd052 | 2016-10-25 07:09:55 -0700 | [diff] [blame] | 182 | |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 183 | processRouterConfig(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 184 | |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 185 | applicationService.registerDeactivateHook(fibAppId, () -> 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() { |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 192 | networkConfigService.removeListener(configListener); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 193 | |
Jonathan Hart | 60e7f51 | 2017-02-10 10:24:24 -0800 | [diff] [blame] | 194 | RoutingConfiguration.unregister(networkConfigRegistry); |
| 195 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 196 | componentConfigService.unregisterProperties(getClass(), false); |
| 197 | |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 198 | log.info("Stopped"); |
| 199 | } |
| 200 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 201 | @Modified |
| 202 | protected void modified(ComponentContext context) { |
| 203 | Dictionary<?, ?> properties = context.getProperties(); |
| 204 | if (properties == null) { |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | String strRouteToNextHop = Tools.get(properties, "routeToNextHop"); |
| 209 | routeToNextHop = Boolean.parseBoolean(strRouteToNextHop); |
| 210 | |
| 211 | log.info("routeToNextHop set to {}", routeToNextHop); |
| 212 | } |
| 213 | |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 214 | private void processRouterConfig() { |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 215 | Set<RoutersConfig.Router> routerConfigs = |
Jonathan Hart | 60e7f51 | 2017-02-10 10:24:24 -0800 | [diff] [blame] | 216 | RoutingConfiguration.getRouterConfigurations(networkConfigService, routerAppId); |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 217 | if (routerConfigs.isEmpty()) { |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 218 | log.info("Router config not available"); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 219 | return; |
| 220 | } |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 221 | RoutersConfig.Router routerConfig = routerConfigs.stream().findFirst().get(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 222 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 223 | if (interfaceManager == null) { |
| 224 | deviceId = routerConfig.controlPlaneConnectPoint().deviceId(); |
Jonathan Hart | f8cd052 | 2016-10-25 07:09:55 -0700 | [diff] [blame] | 225 | log.info("Router device ID is {}", deviceId); |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 226 | |
Jonathan Hart | f8cd052 | 2016-10-25 07:09:55 -0700 | [diff] [blame] | 227 | routeService.addListener(routeListener); |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 228 | |
| 229 | interfaceManager = createRouter(RouterInfo.from(routerConfig)); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 230 | } else { |
Charles Chan | c6d227e | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 231 | interfaceManager.changeConfiguration(RouterInfo.from(routerConfig), false); |
gaurav | a2e61a5 | 2016-05-05 03:39:31 +0530 | [diff] [blame] | 232 | } |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 233 | } |
| 234 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 235 | /** |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 236 | * Removes filtering objectives and routes before deactivate. |
| 237 | */ |
| 238 | private void cleanUp() { |
| 239 | //remove the route listener |
| 240 | routeService.removeListener(routeListener); |
| 241 | |
| 242 | //clean up the routes. |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 243 | prefixToNextHop.entrySet().stream() |
| 244 | .map(e -> new Route(Route.Source.UNDEFINED, e.getKey(), e.getValue())) |
| 245 | .forEach(this::deleteRoute); |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 246 | |
| 247 | if (interfaceManager != null) { |
| 248 | interfaceManager.cleanup(); |
| 249 | } |
| 250 | } |
| 251 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 252 | private Router createRouter(RouterInfo info) { |
| 253 | return new Router( |
| 254 | info, |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 255 | interfaceService, |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 256 | deviceService, |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 257 | this::provisionInterface, |
Charles Chan | c6d227e | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 258 | this::unprovisionInterface, |
| 259 | false); |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 262 | private void updateRoute(ResolvedRoute route) { |
| 263 | addNextHop(route); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 264 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 265 | Integer nextId; |
| 266 | synchronized (this) { |
| 267 | nextId = nextHops.get(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 270 | flowObjectiveService.forward(deviceId, |
| 271 | generateRibForwardingObj(route.prefix(), nextId).add()); |
| 272 | log.trace("Sending forwarding objective {} -> nextId:{}", route, nextId); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 275 | private synchronized void deleteRoute(ResolvedRoute route) { |
Jonathan Hart | 10dbafd | 2017-05-18 15:53:03 -0700 | [diff] [blame] | 276 | deleteRoute(route.route()); |
Jonathan Hart | f2e7a34 | 2017-03-20 15:43:21 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | private void deleteRoute(Route route) { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 280 | //Integer nextId = nextHops.get(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 281 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 282 | /* Group group = deleteNextHop(route.prefix()); |
| 283 | if (group == null) { |
| 284 | log.warn("Group not found when deleting {}", route); |
| 285 | return; |
| 286 | }*/ |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 287 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 288 | flowObjectiveService.forward(deviceId, |
| 289 | generateRibForwardingObj(route.prefix(), null).remove()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix, |
| 293 | Integer nextId) { |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 294 | TrafficSelector selector = buildIpSelectorFromIpPrefix(prefix).build(); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 295 | int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; |
| 296 | |
| 297 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 298 | .fromApp(fibAppId) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 299 | .makePermanent() |
| 300 | .withSelector(selector) |
| 301 | .withPriority(priority) |
| 302 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 303 | |
| 304 | if (nextId == null) { |
| 305 | // Route withdraws are not specified with next hops. Generating |
| 306 | // dummy treatment as there is no equivalent nextId info. |
| 307 | fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build()); |
| 308 | } else { |
| 309 | fwdBuilder.nextStep(nextId); |
| 310 | } |
| 311 | return fwdBuilder; |
| 312 | } |
| 313 | |
Vinayak Tejankar | 3a409c6 | 2017-01-12 02:20:53 +0530 | [diff] [blame] | 314 | /** |
| 315 | * Method to build IPv4 or IPv6 selector. |
| 316 | * |
| 317 | * @param prefixToMatch the prefix to match |
| 318 | * @return the traffic selector builder |
| 319 | */ |
| 320 | private TrafficSelector.Builder buildIpSelectorFromIpPrefix(IpPrefix prefixToMatch) { |
| 321 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 322 | // If the prefix is IPv4 |
| 323 | if (prefixToMatch.isIp4()) { |
| 324 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 325 | selectorBuilder.matchIPDst(prefixToMatch); |
| 326 | return selectorBuilder; |
| 327 | } |
| 328 | // If the prefix is IPv6 |
| 329 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 330 | selectorBuilder.matchIPv6Dst(prefixToMatch); |
| 331 | return selectorBuilder; |
| 332 | } |
| 333 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 334 | private synchronized void addNextHop(ResolvedRoute route) { |
| 335 | prefixToNextHop.put(route.prefix(), route.nextHop()); |
| 336 | if (nextHopsCount.count(route.nextHop()) == 0) { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 337 | // There was no next hop in the multiset |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 338 | Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 339 | if (egressIntf == null) { |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 340 | log.warn("no egress interface found for {}", route); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 341 | return; |
| 342 | } |
| 343 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 344 | NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 345 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 346 | NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 347 | |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 348 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 349 | .setEthSrc(egressIntf.mac()) |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 350 | .setEthDst(nextHop.mac()); |
| 351 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 352 | TrafficSelector.Builder metabuilder = null; |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 353 | if (!egressIntf.vlan().equals(VlanId.NONE)) { |
| 354 | treatment.pushVlan() |
| 355 | .setVlanId(egressIntf.vlan()) |
| 356 | .setVlanPcp((byte) 0); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 357 | } else { |
| 358 | // untagged outgoing port may require internal vlan in some pipelines |
| 359 | metabuilder = DefaultTrafficSelector.builder(); |
| 360 | metabuilder.matchVlanId(VlanId.vlanId(ASSIGNED_VLAN)); |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | treatment.setOutput(egressIntf.connectPoint().port()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 364 | |
| 365 | int nextId = flowObjectiveService.allocateNextId(); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 366 | NextObjective.Builder nextBuilder = DefaultNextObjective.builder() |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 367 | .withId(nextId) |
Jonathan Hart | ca47cd7 | 2015-12-13 12:31:09 -0800 | [diff] [blame] | 368 | .addTreatment(treatment.build()) |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 369 | .withType(NextObjective.Type.SIMPLE) |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 370 | .fromApp(fibAppId); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 371 | if (metabuilder != null) { |
| 372 | nextBuilder.withMeta(metabuilder.build()); |
| 373 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 374 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 375 | NextObjective nextObjective = nextBuilder.add(); // TODO add callbacks |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 376 | flowObjectiveService.next(deviceId, nextObjective); |
| 377 | |
| 378 | nextHops.put(nextHop.ip(), nextId); |
| 379 | |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 380 | if (routeToNextHop) { |
| 381 | // Install route to next hop |
| 382 | ForwardingObjective fob = |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 383 | generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add(); |
Jonathan Hart | b940190 | 2016-02-02 18:46:01 -0800 | [diff] [blame] | 384 | flowObjectiveService.forward(deviceId, fob); |
| 385 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 388 | nextHopsCount.add(route.nextHop()); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /*private synchronized Group deleteNextHop(IpPrefix prefix) { |
| 392 | IpAddress nextHopIp = prefixToNextHop.remove(prefix); |
| 393 | NextHop nextHop = nextHops.get(nextHopIp); |
| 394 | if (nextHop == null) { |
| 395 | log.warn("No next hop found when removing prefix {}", prefix); |
| 396 | return null; |
| 397 | } |
| 398 | |
| 399 | Group group = groupService.getGroup(deviceId, |
| 400 | new DefaultGroupKey(appKryo. |
| 401 | serialize(nextHop.group()))); |
| 402 | |
| 403 | // FIXME disabling group deletes for now until we verify the logic is OK |
| 404 | if (nextHopsCount.remove(nextHopIp, 1) <= 1) { |
| 405 | // There was one or less next hops, so there are now none |
| 406 | |
| 407 | log.debug("removing group for next hop {}", nextHop); |
| 408 | |
| 409 | nextHops.remove(nextHopIp); |
| 410 | |
| 411 | groupService.removeGroup(deviceId, |
| 412 | new DefaultGroupKey(appKryo.build().serialize(nextHop.group())), |
| 413 | appId); |
| 414 | } |
| 415 | |
| 416 | return group; |
| 417 | }*/ |
| 418 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 419 | private void provisionInterface(InterfaceProvisionRequest intf) { |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 420 | updateInterfaceFilters(intf, true); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 421 | } |
| 422 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 423 | private void unprovisionInterface(InterfaceProvisionRequest intf) { |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 424 | updateInterfaceFilters(intf, false); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Installs or removes flow objectives relating to an interface. |
| 429 | * |
| 430 | * @param intf interface to update objectives for |
| 431 | * @param install true to install the objectives, false to remove them |
| 432 | */ |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 433 | private void updateInterfaceFilters(InterfaceProvisionRequest intf, boolean install) { |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 434 | updateFilteringObjective(intf, install); |
| 435 | updateMcastFilteringObjective(intf, install); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Installs or removes unicast filtering objectives relating to an interface. |
| 440 | * |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 441 | * @param routerIntf interface to update objectives for |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 442 | * @param install true to install the objectives, false to remove them |
| 443 | */ |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 444 | private void updateFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) { |
| 445 | Interface intf = routerIntf.intf(); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 446 | VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? |
| 447 | VlanId.vlanId(ASSIGNED_VLAN) : |
| 448 | egressVlan(); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 449 | |
| 450 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 451 | // first add filter for the interface |
| 452 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
| 453 | .addCondition(Criteria.matchEthDst(intf.mac())) |
| 454 | .addCondition(Criteria.matchVlanId(intf.vlan())); |
| 455 | fob.withPriority(PRIORITY_OFFSET); |
| 456 | if (intf.vlan() == VlanId.NONE) { |
| 457 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 458 | .pushVlan().setVlanId(assignedVlan).build(); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 459 | fob.withMeta(tt); |
| 460 | } |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 461 | fob.permit().fromApp(fibAppId); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 462 | sendFilteringObjective(install, fob, intf); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 463 | |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 464 | // then add the same mac/vlan filters for control-plane connect point |
| 465 | fob.withKey(Criteria.matchInPort(routerIntf.controlPlaneConnectPoint().port())); |
| 466 | sendFilteringObjective(install, fob, intf); |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 469 | /** |
| 470 | * Installs or removes multicast filtering objectives relating to an interface. |
| 471 | * |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 472 | * @param routerIntf interface to update objectives for |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 473 | * @param install true to install the objectives, false to remove them |
| 474 | */ |
Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 475 | private void updateMcastFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) { |
| 476 | Interface intf = routerIntf.intf(); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 477 | VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? |
| 478 | VlanId.vlanId(ASSIGNED_VLAN) : |
| 479 | egressVlan(); |
| 480 | |
| 481 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 482 | // first add filter for the interface |
| 483 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
| 484 | .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, |
| 485 | MacAddress.IPV4_MULTICAST_MASK)) |
| 486 | .addCondition(Criteria.matchVlanId(ingressVlan())); |
| 487 | fob.withPriority(PRIORITY_OFFSET); |
| 488 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
| 489 | .pushVlan().setVlanId(assignedVlan).build(); |
| 490 | fob.withMeta(tt); |
| 491 | |
Jonathan Hart | e732704 | 2017-02-02 13:11:25 -0800 | [diff] [blame] | 492 | fob.permit().fromApp(fibAppId); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 493 | sendFilteringObjective(install, fob, intf); |
| 494 | } |
| 495 | |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 496 | private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, |
| 497 | Interface intf) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 498 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 499 | ObjectiveContext context = new DefaultObjectiveContext( |
| 500 | (objective) -> log.info("Installed filter for interface {}", intf), |
| 501 | (objective, error) -> |
| 502 | log.error("Failed to install filter for interface {}: {}", intf, error)); |
gaurav | 164cf6d | 2016-03-25 21:43:04 +0530 | [diff] [blame] | 503 | |
Jonathan Hart | f04b7d9 | 2016-03-29 09:39:11 -0700 | [diff] [blame] | 504 | FilteringObjective filter = install ? fob.add(context) : fob.remove(context); |
| 505 | |
| 506 | flowObjectiveService.filter(deviceId, filter); |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 509 | private VlanId ingressVlan() { |
| 510 | McastConfig mcastConfig = |
| 511 | networkConfigService.getConfig(coreAppId, McastConfig.class); |
| 512 | return (mcastConfig != null) ? mcastConfig.ingressVlan() : VlanId.NONE; |
| 513 | } |
| 514 | |
| 515 | private VlanId egressVlan() { |
| 516 | McastConfig mcastConfig = |
| 517 | networkConfigService.getConfig(coreAppId, McastConfig.class); |
| 518 | return (mcastConfig != null) ? mcastConfig.egressVlan() : VlanId.NONE; |
| 519 | } |
| 520 | |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 521 | /** |
| 522 | * Listener for route changes. |
| 523 | */ |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 524 | private class InternalRouteListener implements RouteListener { |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 525 | @Override |
Jonathan Hart | a2eb9ff | 2016-04-13 21:27:06 -0700 | [diff] [blame] | 526 | public void event(RouteEvent event) { |
| 527 | ResolvedRoute route = event.subject(); |
| 528 | switch (event.type()) { |
| 529 | case ROUTE_ADDED: |
| 530 | case ROUTE_UPDATED: |
| 531 | updateRoute(route); |
| 532 | break; |
| 533 | case ROUTE_REMOVED: |
| 534 | deleteRoute(route); |
| 535 | break; |
| 536 | default: |
| 537 | break; |
| 538 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 542 | /** |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 543 | * Listener for network config events. |
| 544 | */ |
| 545 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 546 | @Override |
| 547 | public void event(NetworkConfigEvent event) { |
Jonathan Hart | 25bd668 | 2016-06-03 10:45:47 -0700 | [diff] [blame] | 548 | if (event.configClass().equals(RoutingService.ROUTER_CONFIG_CLASS)) { |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 549 | switch (event.type()) { |
| 550 | case CONFIG_ADDED: |
| 551 | case CONFIG_UPDATED: |
Jonathan Hart | 7fc5a72 | 2017-01-26 15:54:12 -0800 | [diff] [blame] | 552 | processRouterConfig(); |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 553 | break; |
| 554 | case CONFIG_REGISTERED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 555 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 556 | case CONFIG_UNREGISTERED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 557 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 558 | case CONFIG_REMOVED: |
gaurav | 2511889 | 2016-08-24 05:35:03 +0530 | [diff] [blame] | 559 | cleanUp(); |
| 560 | break; |
Jonathan Hart | b3fa42c | 2016-01-13 09:50:43 -0800 | [diff] [blame] | 561 | default: |
| 562 | break; |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
Jonathan Hart | df20709 | 2015-12-10 11:19:25 -0800 | [diff] [blame] | 567 | } |