sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 43b5354 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Service; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 25 | import org.onlab.packet.Ethernet; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IPv4; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 27 | import org.onlab.packet.Ip4Prefix; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 28 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 30 | import org.onlab.util.KryoNamespace; |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 31 | import org.onosproject.cfg.ComponentConfigService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.core.CoreService; |
| 34 | import org.onosproject.event.Event; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 35 | import org.onosproject.incubator.net.config.basics.McastConfig; |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 37 | import org.onosproject.incubator.net.routing.RouteEvent; |
| 38 | import org.onosproject.incubator.net.routing.RouteListener; |
| 39 | import org.onosproject.incubator.net.routing.RouteService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 40 | import org.onosproject.mastership.MastershipService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 41 | import org.onosproject.net.Device; |
| 42 | import org.onosproject.net.DeviceId; |
| 43 | import org.onosproject.net.Link; |
| 44 | import org.onosproject.net.Port; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 45 | import org.onosproject.net.PortNumber; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 46 | import org.onosproject.net.config.ConfigFactory; |
| 47 | import org.onosproject.net.config.NetworkConfigEvent; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 48 | import org.onosproject.net.config.NetworkConfigListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 49 | import org.onosproject.net.config.NetworkConfigRegistry; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 50 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 51 | import org.onosproject.net.device.DeviceEvent; |
| 52 | import org.onosproject.net.device.DeviceListener; |
| 53 | import org.onosproject.net.device.DeviceService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.TrafficSelector; |
| 55 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 57 | import org.onosproject.net.host.HostEvent; |
| 58 | import org.onosproject.net.host.HostListener; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 59 | import org.onosproject.net.mcast.McastEvent; |
| 60 | import org.onosproject.net.mcast.McastListener; |
| 61 | import org.onosproject.net.mcast.MulticastRouteService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 62 | import org.onosproject.net.topology.TopologyService; |
| 63 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 64 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
| 65 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
| 66 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 67 | import org.onosproject.segmentrouting.config.XConnectConfig; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 68 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
| 69 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 70 | import org.onosproject.segmentrouting.storekey.NeighborSetNextObjectiveStoreKey; |
| 71 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 72 | import org.onosproject.net.host.HostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 73 | import org.onosproject.net.link.LinkEvent; |
| 74 | import org.onosproject.net.link.LinkListener; |
| 75 | import org.onosproject.net.link.LinkService; |
| 76 | import org.onosproject.net.packet.InboundPacket; |
| 77 | import org.onosproject.net.packet.PacketContext; |
| 78 | import org.onosproject.net.packet.PacketProcessor; |
| 79 | import org.onosproject.net.packet.PacketService; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 80 | import org.onosproject.segmentrouting.storekey.SubnetAssignedVidStoreKey; |
| 81 | import org.onosproject.segmentrouting.storekey.SubnetNextObjectiveStoreKey; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 82 | import org.onosproject.segmentrouting.storekey.XConnectStoreKey; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 83 | import org.onosproject.store.serializers.KryoNamespaces; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 84 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 85 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
| 86 | import org.onosproject.store.service.StorageService; |
| 87 | import org.onosproject.store.service.WallClockTimestamp; |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 88 | import org.opencord.cordconfig.CordConfigEvent; |
| 89 | import org.opencord.cordconfig.CordConfigListener; |
| 90 | import org.opencord.cordconfig.CordConfigService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 91 | import org.slf4j.Logger; |
| 92 | import org.slf4j.LoggerFactory; |
| 93 | |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 94 | import java.util.Collections; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 95 | import java.util.HashSet; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 96 | import java.util.List; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 97 | import java.util.Map; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 98 | import java.util.Set; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 99 | import java.util.concurrent.ConcurrentHashMap; |
| 100 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 101 | import java.util.concurrent.Executors; |
| 102 | import java.util.concurrent.ScheduledExecutorService; |
| 103 | import java.util.concurrent.ScheduledFuture; |
| 104 | import java.util.concurrent.TimeUnit; |
| 105 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 106 | import static com.google.common.base.Preconditions.checkState; |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 107 | import static org.onlab.util.Tools.groupedThreads; |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 108 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 109 | /** |
| 110 | * Segment routing manager. |
| 111 | */ |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 112 | @Service |
| 113 | @Component(immediate = true) |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 114 | public class SegmentRoutingManager implements SegmentRoutingService { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 115 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 116 | private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 117 | |
| 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 119 | private ComponentConfigService compCfgService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 120 | |
| 121 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 122 | CoreService coreService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 123 | |
| 124 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 125 | PacketService packetService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 126 | |
| 127 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 128 | HostService hostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 129 | |
| 130 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 131 | DeviceService deviceService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 132 | |
| 133 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 134 | FlowObjectiveService flowObjectiveService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 135 | |
| 136 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 137 | LinkService linkService; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 138 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 139 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 140 | MastershipService mastershipService; |
| 141 | |
| 142 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 143 | StorageService storageService; |
| 144 | |
| 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 146 | MulticastRouteService multicastRouteService; |
| 147 | |
| 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 149 | TopologyService topologyService; |
| 150 | |
| 151 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 152 | CordConfigService cordConfigService; |
| 153 | |
| 154 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 155 | RouteService routeService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 156 | |
| 157 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 158 | public NetworkConfigRegistry cfgService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 159 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 160 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 161 | public InterfaceService interfaceService; |
| 162 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 163 | ArpHandler arpHandler = null; |
| 164 | IcmpHandler icmpHandler = null; |
| 165 | IpHandler ipHandler = null; |
| 166 | RoutingRulePopulator routingRulePopulator = null; |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 167 | public ApplicationId appId; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 168 | protected DeviceConfiguration deviceConfiguration = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 169 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 170 | DefaultRoutingHandler defaultRoutingHandler = null; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 171 | private TunnelHandler tunnelHandler = null; |
| 172 | private PolicyHandler policyHandler = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 173 | private InternalPacketProcessor processor = null; |
| 174 | private InternalLinkListener linkListener = null; |
| 175 | private InternalDeviceListener deviceListener = null; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 176 | private AppConfigHandler appCfgHandler = null; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 177 | XConnectHandler xConnectHandler = null; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 178 | private McastHandler mcastHandler = null; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 179 | HostHandler hostHandler = null; |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 180 | private CordConfigHandler cordConfigHandler = null; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 181 | RouteHandler routeHandler = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 182 | private InternalEventHandler eventHandler = new InternalEventHandler(); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 183 | private final InternalHostListener hostListener = new InternalHostListener(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 184 | private final InternalConfigListener cfgListener = new InternalConfigListener(this); |
| 185 | private final InternalMcastListener mcastListener = new InternalMcastListener(); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 186 | private final InternalCordConfigListener cordConfigListener = new InternalCordConfigListener(); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 187 | private final InternalRouteEventListener routeListener = new InternalRouteEventListener(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 188 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 189 | private ScheduledExecutorService executorService = Executors |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 190 | .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log)); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 191 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 192 | @SuppressWarnings("unused") |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 193 | private static ScheduledFuture<?> eventHandlerFuture = null; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 194 | @SuppressWarnings("rawtypes") |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 195 | private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>(); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 196 | private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 197 | new ConcurrentHashMap<>(); |
| 198 | /** |
| 199 | * Per device next objective ID store with (device id + neighbor set) as key. |
| 200 | */ |
| 201 | public EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, Integer> |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 202 | nsNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 203 | /** |
| 204 | * Per device next objective ID store with (device id + subnet) as key. |
| 205 | */ |
| 206 | public EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer> |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 207 | subnetNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 208 | /** |
| 209 | * Per device next objective ID store with (device id + port) as key. |
| 210 | */ |
| 211 | public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 212 | portNextObjStore = null; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 213 | // Per device, per-subnet assigned-vlans store, with (device id + subnet |
| 214 | // IPv4 prefix) as key |
| 215 | private EventuallyConsistentMap<SubnetAssignedVidStoreKey, VlanId> |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 216 | subnetVidStore = null; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 217 | private EventuallyConsistentMap<String, Tunnel> tunnelStore = null; |
| 218 | private EventuallyConsistentMap<String, Policy> policyStore = null; |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 219 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 220 | private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 221 | new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>( |
| 222 | SubjectFactories.DEVICE_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 223 | SegmentRoutingDeviceConfig.class, "segmentrouting") { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 224 | @Override |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 225 | public SegmentRoutingDeviceConfig createConfig() { |
| 226 | return new SegmentRoutingDeviceConfig(); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 227 | } |
| 228 | }; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 229 | private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 230 | new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>( |
| 231 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 232 | SegmentRoutingAppConfig.class, "segmentrouting") { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 233 | @Override |
| 234 | public SegmentRoutingAppConfig createConfig() { |
| 235 | return new SegmentRoutingAppConfig(); |
| 236 | } |
| 237 | }; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 238 | private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory = |
| 239 | new ConfigFactory<ApplicationId, XConnectConfig>( |
| 240 | SubjectFactories.APP_SUBJECT_FACTORY, |
| 241 | XConnectConfig.class, "xconnect") { |
| 242 | @Override |
| 243 | public XConnectConfig createConfig() { |
| 244 | return new XConnectConfig(); |
| 245 | } |
| 246 | }; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 247 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 248 | new ConfigFactory<ApplicationId, McastConfig>( |
| 249 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 250 | McastConfig.class, "multicast") { |
| 251 | @Override |
| 252 | public McastConfig createConfig() { |
| 253 | return new McastConfig(); |
| 254 | } |
| 255 | }; |
| 256 | |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 257 | private Object threadSchedulerLock = new Object(); |
| 258 | private static int numOfEventsQueued = 0; |
| 259 | private static int numOfEventsExecuted = 0; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 260 | private static int numOfHandlerExecution = 0; |
| 261 | private static int numOfHandlerScheduled = 0; |
| 262 | |
Charles Chan | 1963f4f | 2016-02-18 14:22:42 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Segment Routing App ID. |
| 265 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 266 | public static final String APP_NAME = "org.onosproject.segmentrouting"; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 267 | /** |
| 268 | * The starting value of per-subnet VLAN ID assignment. |
| 269 | */ |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 270 | private static final short ASSIGNED_VLAN_START = 4093; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 271 | /** |
| 272 | * The default VLAN ID assigned to the interfaces without subnet config. |
| 273 | */ |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 274 | public static final short ASSIGNED_VLAN_NO_SUBNET = 4094; |
| 275 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 276 | @Activate |
| 277 | protected void activate() { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 278 | appId = coreService.registerApplication(APP_NAME); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 279 | |
| 280 | log.debug("Creating EC map nsnextobjectivestore"); |
| 281 | EventuallyConsistentMapBuilder<NeighborSetNextObjectiveStoreKey, Integer> |
| 282 | nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 283 | nsNextObjStore = nsNextObjMapBuilder |
| 284 | .withName("nsnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 285 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 286 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 287 | .build(); |
| 288 | log.trace("Current size {}", nsNextObjStore.size()); |
| 289 | |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 290 | log.debug("Creating EC map subnetnextobjectivestore"); |
| 291 | EventuallyConsistentMapBuilder<SubnetNextObjectiveStoreKey, Integer> |
| 292 | subnetNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 293 | subnetNextObjStore = subnetNextObjMapBuilder |
| 294 | .withName("subnetnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 295 | .withSerializer(createSerializer()) |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 296 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 297 | .build(); |
| 298 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 299 | log.debug("Creating EC map subnetnextobjectivestore"); |
| 300 | EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer> |
| 301 | portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 302 | portNextObjStore = portNextObjMapBuilder |
| 303 | .withName("portnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 304 | .withSerializer(createSerializer()) |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 305 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 306 | .build(); |
| 307 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 308 | EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder = |
| 309 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 310 | tunnelStore = tunnelMapBuilder |
| 311 | .withName("tunnelstore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 312 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 313 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 314 | .build(); |
| 315 | |
| 316 | EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder = |
| 317 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 318 | policyStore = policyMapBuilder |
| 319 | .withName("policystore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 320 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 321 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 322 | .build(); |
| 323 | |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 324 | EventuallyConsistentMapBuilder<SubnetAssignedVidStoreKey, VlanId> |
| 325 | subnetVidStoreMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 326 | subnetVidStore = subnetVidStoreMapBuilder |
| 327 | .withName("subnetvidstore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 328 | .withSerializer(createSerializer()) |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 329 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 330 | .build(); |
| 331 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 332 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 333 | "purgeOnDisconnection", "true"); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 334 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 335 | "purgeOnDisconnection", "true"); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 336 | compCfgService.preSetProperty("org.onosproject.vrouter.Vrouter", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 337 | "fibInstalledEnabled", "false"); |
| 338 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
| 339 | "requestInterceptsEnabled", "false"); |
Pier Luigi | bc976df | 2017-01-12 22:46:39 -0800 | [diff] [blame] | 340 | compCfgService.preSetProperty("org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager", |
| 341 | "requestInterceptsEnabled", "false"); |
| 342 | compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelay", |
| 343 | "arpEnabled", "false"); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 344 | |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 345 | processor = new InternalPacketProcessor(); |
| 346 | linkListener = new InternalLinkListener(); |
| 347 | deviceListener = new InternalDeviceListener(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 348 | appCfgHandler = new AppConfigHandler(this); |
| 349 | xConnectHandler = new XConnectHandler(this); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 350 | mcastHandler = new McastHandler(this); |
| 351 | hostHandler = new HostHandler(this); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 352 | cordConfigHandler = new CordConfigHandler(this); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 353 | routeHandler = new RouteHandler(this); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 354 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 355 | cfgService.addListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 356 | cfgService.registerConfigFactory(deviceConfigFactory); |
| 357 | cfgService.registerConfigFactory(appConfigFactory); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 358 | cfgService.registerConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 359 | cfgService.registerConfigFactory(mcastConfigFactory); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 360 | hostService.addListener(hostListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 361 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
| 362 | linkService.addListener(linkListener); |
| 363 | deviceService.addListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 364 | multicastRouteService.addListener(mcastListener); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 365 | cordConfigService.addListener(cordConfigListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 366 | |
| 367 | cfgListener.configureNetwork(); |
| 368 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 369 | routeService.addListener(routeListener); |
| 370 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 371 | log.info("Started"); |
| 372 | } |
| 373 | |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 374 | private KryoNamespace.Builder createSerializer() { |
| 375 | return new KryoNamespace.Builder() |
| 376 | .register(KryoNamespaces.API) |
| 377 | .register(NeighborSetNextObjectiveStoreKey.class, |
| 378 | SubnetNextObjectiveStoreKey.class, |
| 379 | SubnetAssignedVidStoreKey.class, |
| 380 | NeighborSet.class, |
| 381 | Tunnel.class, |
| 382 | DefaultTunnel.class, |
| 383 | Policy.class, |
| 384 | TunnelPolicy.class, |
| 385 | Policy.Type.class, |
| 386 | PortNextObjectiveStoreKey.class, |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 387 | XConnectStoreKey.class |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 388 | ); |
| 389 | } |
| 390 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 391 | @Deactivate |
| 392 | protected void deactivate() { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 393 | cfgService.removeListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 394 | cfgService.unregisterConfigFactory(deviceConfigFactory); |
| 395 | cfgService.unregisterConfigFactory(appConfigFactory); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 396 | cfgService.unregisterConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 397 | cfgService.unregisterConfigFactory(mcastConfigFactory); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 398 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 399 | packetService.removeProcessor(processor); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 400 | linkService.removeListener(linkListener); |
| 401 | deviceService.removeListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 402 | multicastRouteService.removeListener(mcastListener); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 403 | cordConfigService.removeListener(cordConfigListener); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 404 | routeService.removeListener(routeListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 405 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 406 | processor = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 407 | linkListener = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 408 | deviceListener = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 409 | groupHandlerMap.clear(); |
| 410 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 411 | nsNextObjStore.destroy(); |
| 412 | subnetNextObjStore.destroy(); |
| 413 | portNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 414 | tunnelStore.destroy(); |
| 415 | policyStore.destroy(); |
| 416 | subnetVidStore.destroy(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 417 | log.info("Stopped"); |
| 418 | } |
| 419 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 420 | @Override |
| 421 | public List<Tunnel> getTunnels() { |
| 422 | return tunnelHandler.getTunnels(); |
| 423 | } |
| 424 | |
| 425 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 426 | public TunnelHandler.Result createTunnel(Tunnel tunnel) { |
| 427 | return tunnelHandler.createTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 431 | public TunnelHandler.Result removeTunnel(Tunnel tunnel) { |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 432 | for (Policy policy: policyHandler.getPolicies()) { |
| 433 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
| 434 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
| 435 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { |
| 436 | log.warn("Cannot remove the tunnel used by a policy"); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 437 | return TunnelHandler.Result.TUNNEL_IN_USE; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | } |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 441 | return tunnelHandler.removeTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 445 | public PolicyHandler.Result removePolicy(Policy policy) { |
| 446 | return policyHandler.removePolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 450 | public PolicyHandler.Result createPolicy(Policy policy) { |
| 451 | return policyHandler.createPolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public List<Policy> getPolicies() { |
| 456 | return policyHandler.getPolicies(); |
| 457 | } |
| 458 | |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 459 | @Override |
| 460 | public void rerouteNetwork() { |
| 461 | cfgListener.configureNetwork(); |
| 462 | for (Device device : deviceService.getDevices()) { |
| 463 | defaultRoutingHandler.populatePortAddressingRules(device.id()); |
| 464 | } |
| 465 | defaultRoutingHandler.startPopulationProcess(); |
| 466 | } |
| 467 | |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 468 | @Override |
| 469 | public Map<DeviceId, Set<Ip4Prefix>> getDeviceSubnetMap() { |
| 470 | Map<DeviceId, Set<Ip4Prefix>> deviceSubnetMap = Maps.newHashMap(); |
| 471 | deviceService.getAvailableDevices().forEach(device -> { |
| 472 | deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id())); |
| 473 | }); |
| 474 | return deviceSubnetMap; |
| 475 | } |
| 476 | |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 477 | /** |
Pier Ventre | 7a78de2 | 2016-10-31 15:00:01 -0700 | [diff] [blame] | 478 | * Returns the MPLS-ECMP configuration. |
| 479 | * |
| 480 | * @return MPLS-ECMP value |
| 481 | */ |
| 482 | public boolean getMplsEcmp() { |
| 483 | SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService |
| 484 | .getConfig(this.appId, SegmentRoutingAppConfig.class); |
| 485 | return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp(); |
| 486 | } |
| 487 | |
| 488 | /** |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 489 | * Returns the tunnel object with the tunnel ID. |
| 490 | * |
| 491 | * @param tunnelId Tunnel ID |
| 492 | * @return Tunnel reference |
| 493 | */ |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 494 | public Tunnel getTunnel(String tunnelId) { |
| 495 | return tunnelHandler.getTunnel(tunnelId); |
| 496 | } |
| 497 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 498 | /** |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 499 | * Returns the vlan-id assigned to the subnet configured for a device. |
| 500 | * If no vlan-id has been assigned, a new one is assigned out of a pool of ids, |
| 501 | * if and only if this controller instance is the master for the device. |
| 502 | * <p> |
| 503 | * USAGE: The assigned vlans are meant to be applied to untagged packets on those |
| 504 | * switches/pipelines that need this functionality. These vids are meant |
| 505 | * to be used internally within a switch, and thus need to be unique only |
| 506 | * on a switch level. Note that packets never go out on the wire with these |
| 507 | * vlans. Currently, vlan ids are assigned from value 4093 down. |
| 508 | * Vlan id 4094 expected to be used for all ports that are not assigned subnets. |
| 509 | * Vlan id 4095 is reserved and unused. Only a single vlan id is assigned |
| 510 | * per subnet. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 511 | * |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 512 | * @param deviceId switch dpid |
| 513 | * @param subnet IPv4 prefix for which assigned vlan is desired |
| 514 | * @return VlanId assigned for the subnet on the device, or |
| 515 | * null if no vlan assignment was found and this instance is not |
| 516 | * the master for the device. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 517 | */ |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 518 | // TODO: We should avoid assigning VLAN IDs that are used by VLAN cross-connection. |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 519 | public VlanId getSubnetAssignedVlanId(DeviceId deviceId, Ip4Prefix subnet) { |
| 520 | VlanId assignedVid = subnetVidStore.get(new SubnetAssignedVidStoreKey( |
| 521 | deviceId, subnet)); |
| 522 | if (assignedVid != null) { |
| 523 | log.debug("Query for subnet:{} on device:{} returned assigned-vlan " |
| 524 | + "{}", subnet, deviceId, assignedVid); |
| 525 | return assignedVid; |
| 526 | } |
| 527 | //check mastership for the right to assign a vlan |
| 528 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 529 | log.warn("This controller instance is not the master for device {}. " |
| 530 | + "Cannot assign vlan-id for subnet {}", deviceId, subnet); |
| 531 | return null; |
| 532 | } |
| 533 | // vlan assignment is expensive but done only once |
Charles Chan | c6ad775 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 534 | Set<Ip4Prefix> configuredSubnets = deviceConfiguration.getSubnets(deviceId); |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 535 | Set<Short> assignedVlans = new HashSet<>(); |
| 536 | Set<Ip4Prefix> unassignedSubnets = new HashSet<>(); |
| 537 | for (Ip4Prefix sub : configuredSubnets) { |
| 538 | VlanId v = subnetVidStore.get(new SubnetAssignedVidStoreKey(deviceId, |
| 539 | sub)); |
| 540 | if (v != null) { |
| 541 | assignedVlans.add(v.toShort()); |
| 542 | } else { |
| 543 | unassignedSubnets.add(sub); |
| 544 | } |
| 545 | } |
| 546 | short nextAssignedVlan = ASSIGNED_VLAN_START; |
| 547 | if (!assignedVlans.isEmpty()) { |
| 548 | nextAssignedVlan = (short) (Collections.min(assignedVlans) - 1); |
| 549 | } |
| 550 | for (Ip4Prefix unsub : unassignedSubnets) { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 551 | // Special case for default route. Assign default VLAN ID to /32 and /0 subnets |
| 552 | if (unsub.prefixLength() == IpPrefix.MAX_INET_MASK_LENGTH || |
| 553 | unsub.prefixLength() == 0) { |
| 554 | subnetVidStore.put(new SubnetAssignedVidStoreKey(deviceId, unsub), |
| 555 | VlanId.vlanId(ASSIGNED_VLAN_NO_SUBNET)); |
| 556 | } else { |
| 557 | subnetVidStore.put(new SubnetAssignedVidStoreKey(deviceId, unsub), |
| 558 | VlanId.vlanId(nextAssignedVlan--)); |
| 559 | log.info("Assigned vlan: {} to subnet: {} on device: {}", |
| 560 | nextAssignedVlan + 1, unsub, deviceId); |
| 561 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 564 | return subnetVidStore.get(new SubnetAssignedVidStoreKey(deviceId, subnet)); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 565 | } |
| 566 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 567 | /** |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 568 | * Returns the next objective ID for the given NeighborSet. |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 569 | * If the nextObjective does not exist, a new one is created and |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 570 | * its id is returned. |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 571 | * |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 572 | * @param deviceId Device ID |
| 573 | * @param ns NegighborSet |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 574 | * @param meta metadata passed into the creation of a Next Objective |
| 575 | * @return next objective ID or -1 if an error was encountered during the |
| 576 | * creation of the nextObjective |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 577 | */ |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 578 | public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns, |
| 579 | TrafficSelector meta) { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 580 | if (groupHandlerMap.get(deviceId) != null) { |
| 581 | log.trace("getNextObjectiveId query in device {}", deviceId); |
| 582 | return groupHandlerMap |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 583 | .get(deviceId).getNextObjectiveId(ns, meta); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 584 | } else { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 585 | log.warn("getNextObjectiveId query - groupHandler for device {} " |
| 586 | + "not found", deviceId); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 587 | return -1; |
| 588 | } |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 591 | /** |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 592 | * Returns the next objective ID for the given subnet prefix. It is expected |
| 593 | * that the next-objective has been pre-created from configuration. |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 594 | * |
| 595 | * @param deviceId Device ID |
| 596 | * @param prefix Subnet |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 597 | * @return next objective ID or -1 if it was not found |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 598 | */ |
| 599 | public int getSubnetNextObjectiveId(DeviceId deviceId, IpPrefix prefix) { |
| 600 | if (groupHandlerMap.get(deviceId) != null) { |
| 601 | log.trace("getSubnetNextObjectiveId query in device {}", deviceId); |
| 602 | return groupHandlerMap |
| 603 | .get(deviceId).getSubnetNextObjectiveId(prefix); |
| 604 | } else { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 605 | log.warn("getSubnetNextObjectiveId query - groupHandler for " |
| 606 | + "device {} not found", deviceId); |
| 607 | return -1; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Returns the next objective ID for the given portNumber, given the treatment. |
| 613 | * There could be multiple different treatments to the same outport, which |
| 614 | * would result in different objectives. If the next object |
| 615 | * does not exist, a new one is created and its id is returned. |
| 616 | * |
| 617 | * @param deviceId Device ID |
| 618 | * @param portNum port number on device for which NextObjective is queried |
| 619 | * @param treatment the actions to apply on the packets (should include outport) |
| 620 | * @param meta metadata passed into the creation of a Next Objective if necessary |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 621 | * @return next objective ID or -1 if an error occurred during retrieval or creation |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 622 | */ |
| 623 | public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum, |
| 624 | TrafficTreatment treatment, |
| 625 | TrafficSelector meta) { |
| 626 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 627 | if (ghdlr != null) { |
| 628 | return ghdlr.getPortNextObjectiveId(portNum, treatment, meta); |
| 629 | } else { |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 630 | log.warn("getPortNextObjectiveId query - groupHandler for device {}" |
| 631 | + " not found", deviceId); |
| 632 | return -1; |
| 633 | } |
| 634 | } |
| 635 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 636 | private class InternalPacketProcessor implements PacketProcessor { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 637 | @Override |
| 638 | public void process(PacketContext context) { |
| 639 | |
| 640 | if (context.isHandled()) { |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | InboundPacket pkt = context.inPacket(); |
| 645 | Ethernet ethernet = pkt.parsed(); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 646 | log.trace("Rcvd pktin: {}", ethernet); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 647 | if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { |
| 648 | arpHandler.processPacketIn(pkt); |
| 649 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) { |
| 650 | IPv4 ipPacket = (IPv4) ethernet.getPayload(); |
Charles Chan | d041ad8 | 2017-01-13 17:20:44 -0800 | [diff] [blame^] | 651 | // ipHandler.addToPacketBuffer(ipPacket); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 652 | if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) { |
| 653 | icmpHandler.processPacketIn(pkt); |
| 654 | } else { |
Charles Chan | d041ad8 | 2017-01-13 17:20:44 -0800 | [diff] [blame^] | 655 | // NOTE: We don't support IP learning at this moment so this |
| 656 | // is not necessary. Also it causes duplication of DHCP packets. |
| 657 | // ipHandler.processPacketIn(pkt); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | private class InternalLinkListener implements LinkListener { |
| 664 | @Override |
| 665 | public void event(LinkEvent event) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 666 | if (event.type() == LinkEvent.Type.LINK_ADDED |
| 667 | || event.type() == LinkEvent.Type.LINK_REMOVED) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 668 | log.debug("Event {} received from Link Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 669 | scheduleEventHandlerIfNotScheduled(event); |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | private class InternalDeviceListener implements DeviceListener { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 675 | @Override |
| 676 | public void event(DeviceEvent event) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 677 | switch (event.type()) { |
| 678 | case DEVICE_ADDED: |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 679 | case PORT_UPDATED: |
| 680 | case PORT_ADDED: |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 681 | case DEVICE_UPDATED: |
| 682 | case DEVICE_AVAILABILITY_CHANGED: |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 683 | log.debug("Event {} received from Device Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 684 | scheduleEventHandlerIfNotScheduled(event); |
| 685 | break; |
| 686 | default: |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 691 | @SuppressWarnings("rawtypes") |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 692 | private void scheduleEventHandlerIfNotScheduled(Event event) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 693 | synchronized (threadSchedulerLock) { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 694 | eventQueue.add(event); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 695 | numOfEventsQueued++; |
| 696 | |
| 697 | if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) { |
| 698 | //No pending scheduled event handling threads. So start a new one. |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 699 | eventHandlerFuture = executorService |
| 700 | .schedule(eventHandler, 100, TimeUnit.MILLISECONDS); |
| 701 | numOfHandlerScheduled++; |
| 702 | } |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 703 | log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}", |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 704 | numOfEventsQueued, |
| 705 | numOfHandlerScheduled); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 706 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | private class InternalEventHandler implements Runnable { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 710 | @Override |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 711 | public void run() { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 712 | try { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 713 | while (true) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 714 | @SuppressWarnings("rawtypes") |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 715 | Event event = null; |
| 716 | synchronized (threadSchedulerLock) { |
| 717 | if (!eventQueue.isEmpty()) { |
| 718 | event = eventQueue.poll(); |
| 719 | numOfEventsExecuted++; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 720 | } else { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 721 | numOfHandlerExecution++; |
| 722 | log.debug("numOfHandlerExecution {} numOfEventsExecuted {}", |
| 723 | numOfHandlerExecution, numOfEventsExecuted); |
| 724 | break; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 725 | } |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 726 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 727 | if (event.type() == LinkEvent.Type.LINK_ADDED) { |
| 728 | processLinkAdded((Link) event.subject()); |
| 729 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 730 | Link linkRemoved = (Link) event.subject(); |
| 731 | if (linkRemoved.src().elementId() instanceof DeviceId && |
| 732 | !deviceService.isAvailable(linkRemoved.src().deviceId())) { |
| 733 | continue; |
| 734 | } |
| 735 | if (linkRemoved.dst().elementId() instanceof DeviceId && |
| 736 | !deviceService.isAvailable(linkRemoved.dst().deviceId())) { |
| 737 | continue; |
| 738 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 739 | processLinkRemoved((Link) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 740 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 741 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 742 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 743 | DeviceId deviceId = ((Device) event.subject()).id(); |
| 744 | if (deviceService.isAvailable(deviceId)) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 745 | log.info("Processing device event {} for available device {}", |
| 746 | event.type(), ((Device) event.subject()).id()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 747 | processDeviceAdded((Device) event.subject()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 748 | } else { |
| 749 | log.info("Processing device event {} for unavailable device {}", |
| 750 | event.type(), ((Device) event.subject()).id()); |
| 751 | processDeviceRemoved((Device) event.subject()); |
| 752 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 753 | } else if (event.type() == DeviceEvent.Type.PORT_ADDED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 754 | // typically these calls come when device is added first time |
| 755 | // so port filtering rules are handled at the device_added event. |
| 756 | // port added calls represent all ports on the device, |
| 757 | // enabled or not. |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 758 | log.debug("** PORT ADDED {}/{} -> {}", |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 759 | ((DeviceEvent) event).subject().id(), |
| 760 | ((DeviceEvent) event).port().number(), |
| 761 | event.type()); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 762 | } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 763 | // these calls happen for every subsequent event |
| 764 | // ports enabled, disabled, switch goes away, comes back |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 765 | log.info("** PORT UPDATED {}/{} -> {}", |
| 766 | event.subject(), |
| 767 | ((DeviceEvent) event).port(), |
| 768 | event.type()); |
| 769 | processPortUpdated(((Device) event.subject()), |
| 770 | ((DeviceEvent) event).port()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 771 | } else { |
| 772 | log.warn("Unhandled event type: {}", event.type()); |
| 773 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 774 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 775 | } catch (Exception e) { |
| 776 | log.error("SegmentRouting event handler " |
| 777 | + "thread thrown an exception: {}", e); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 778 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 782 | private void processLinkAdded(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 783 | log.info("** LINK ADDED {}", link.toString()); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 784 | if (!deviceConfiguration.isConfigured(link.src().deviceId())) { |
| 785 | log.warn("Source device of this link is not configured."); |
| 786 | return; |
| 787 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 788 | //Irrespective whether the local is a MASTER or not for this device, |
| 789 | //create group handler instance and push default TTP flow rules. |
| 790 | //Because in a multi-instance setup, instances can initiate |
| 791 | //groups for any devices. Also the default TTP rules are needed |
| 792 | //to be pushed before inserting any IP table entries for any device |
| 793 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src() |
| 794 | .deviceId()); |
| 795 | if (groupHandler != null) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 796 | groupHandler.linkUp(link, mastershipService.isLocalMaster( |
| 797 | link.src().deviceId())); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 798 | } else { |
| 799 | Device device = deviceService.getDevice(link.src().deviceId()); |
| 800 | if (device != null) { |
| 801 | log.warn("processLinkAdded: Link Added " |
| 802 | + "Notification without Device Added " |
| 803 | + "event, still handling it"); |
| 804 | processDeviceAdded(device); |
| 805 | groupHandler = groupHandlerMap.get(link.src() |
| 806 | .deviceId()); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 807 | groupHandler.linkUp(link, mastershipService.isLocalMaster(device.id())); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 810 | |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 811 | log.trace("Starting optimized route population process"); |
| 812 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null); |
| 813 | //log.trace("processLinkAdded: re-starting route population process"); |
| 814 | //defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 815 | |
| 816 | mcastHandler.init(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | private void processLinkRemoved(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 820 | log.info("** LINK REMOVED {}", link.toString()); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 821 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId()); |
| 822 | if (groupHandler != null) { |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 823 | groupHandler.portDown(link.src().port(), |
| 824 | mastershipService.isLocalMaster(link.src().deviceId())); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 825 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 826 | log.trace("Starting optimized route population process"); |
| 827 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link); |
| 828 | //log.trace("processLinkRemoved: re-starting route population process"); |
| 829 | //defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 830 | |
| 831 | mcastHandler.processLinkDown(link); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | private void processDeviceAdded(Device device) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 835 | log.info("** DEVICE ADDED with ID {}", device.id()); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 836 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 837 | log.warn("Device configuration uploading. Device {} will be " |
| 838 | + "processed after config completes.", device.id()); |
| 839 | return; |
| 840 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 841 | processDeviceAddedInternal(device.id()); |
| 842 | } |
| 843 | |
| 844 | private void processDeviceAddedInternal(DeviceId deviceId) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 845 | // Irrespective of whether the local is a MASTER or not for this device, |
| 846 | // we need to create a SR-group-handler instance. This is because in a |
| 847 | // multi-instance setup, any instance can initiate forwarding/next-objectives |
| 848 | // for any switch (even if this instance is a SLAVE or not even connected |
| 849 | // to the switch). To handle this, a default-group-handler instance is necessary |
| 850 | // per switch. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 851 | log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet()); |
| 852 | if (groupHandlerMap.get(deviceId) == null) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 853 | DefaultGroupHandler groupHandler; |
| 854 | try { |
| 855 | groupHandler = DefaultGroupHandler. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 856 | createGroupHandler(deviceId, |
| 857 | appId, |
| 858 | deviceConfiguration, |
| 859 | linkService, |
| 860 | flowObjectiveService, |
| 861 | this); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 862 | } catch (DeviceConfigNotFoundException e) { |
| 863 | log.warn(e.getMessage() + " Aborting processDeviceAdded."); |
| 864 | return; |
| 865 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 866 | log.debug("updating groupHandlerMap with new config for device: {}", |
| 867 | deviceId); |
| 868 | groupHandlerMap.put(deviceId, groupHandler); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 869 | } |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 870 | // Also, in some cases, drivers may need extra |
| 871 | // information to process rules (eg. Router IP/MAC); and so, we send |
| 872 | // port addressing rules to the driver as well irrespective of whether |
| 873 | // this instance is the master or not. |
| 874 | defaultRoutingHandler.populatePortAddressingRules(deviceId); |
| 875 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 876 | if (mastershipService.isLocalMaster(deviceId)) { |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 877 | hostHandler.init(deviceId); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 878 | xConnectHandler.init(deviceId); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 879 | cordConfigHandler.init(deviceId); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 880 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 881 | groupHandler.createGroupsFromSubnetConfig(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 882 | routingRulePopulator.populateSubnetBroadcastRule(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 883 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 884 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 885 | appCfgHandler.init(deviceId); |
| 886 | routeHandler.init(deviceId); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 889 | private void processDeviceRemoved(Device device) { |
| 890 | nsNextObjStore.entrySet().stream() |
| 891 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 892 | .forEach(entry -> { |
| 893 | nsNextObjStore.remove(entry.getKey()); |
| 894 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 895 | subnetNextObjStore.entrySet().stream() |
| 896 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 897 | .forEach(entry -> { |
| 898 | subnetNextObjStore.remove(entry.getKey()); |
| 899 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 900 | portNextObjStore.entrySet().stream() |
| 901 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 902 | .forEach(entry -> { |
| 903 | portNextObjStore.remove(entry.getKey()); |
| 904 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 905 | subnetVidStore.entrySet().stream() |
| 906 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 907 | .forEach(entry -> { |
| 908 | subnetVidStore.remove(entry.getKey()); |
| 909 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 910 | groupHandlerMap.remove(device.id()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 911 | defaultRoutingHandler.purgeEcmpGraph(device.id()); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 912 | mcastHandler.removeDevice(device.id()); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 913 | xConnectHandler.removeDevice(device.id()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 916 | private void processPortUpdated(Device device, Port port) { |
| 917 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
| 918 | log.warn("Device configuration uploading. Not handling port event for" |
| 919 | + "dev: {} port: {}", device.id(), port.number()); |
| 920 | return; |
| 921 | } |
| 922 | /* XXX create method for single port filtering rules which are needed |
| 923 | for both switch-to-switch ports and edge ports |
| 924 | if (defaultRoutingHandler != null) { |
| 925 | defaultRoutingHandler.populatePortAddressingRules( |
| 926 | ((Device) event.subject()).id()); |
| 927 | }*/ |
| 928 | |
| 929 | // portUpdated calls are for ports that have gone down or up. For switch |
| 930 | // to switch ports, link-events should take care of any re-routing or |
| 931 | // group editing necessary for port up/down. Here we only process edge ports |
| 932 | // that are already configured. |
| 933 | Ip4Prefix configuredSubnet = deviceConfiguration.getPortSubnet(device.id(), |
| 934 | port.number()); |
| 935 | if (configuredSubnet == null) { |
| 936 | log.debug("Not handling port updated event for unconfigured port " |
| 937 | + "dev/port: {}/{}", device.id(), port.number()); |
| 938 | return; |
| 939 | } |
| 940 | processEdgePort(device, port, configuredSubnet); |
| 941 | } |
| 942 | |
| 943 | private void processEdgePort(Device device, Port port, Ip4Prefix subnet) { |
| 944 | boolean portUp = port.isEnabled(); |
| 945 | if (portUp) { |
| 946 | log.info("Device:EdgePort {}:{} is enabled in subnet: {}", device.id(), |
| 947 | port.number(), subnet); |
| 948 | } else { |
| 949 | log.info("Device:EdgePort {}:{} is disabled in subnet: {}", device.id(), |
| 950 | port.number(), subnet); |
| 951 | } |
| 952 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 953 | DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 954 | if (groupHandler != null) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 955 | groupHandler.processEdgePort(port.number(), subnet, portUp, |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 956 | mastershipService.isLocalMaster(device.id())); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 957 | } else { |
| 958 | log.warn("Group handler not found for dev:{}. Not handling edge port" |
| 959 | + " {} event for port:{}", device.id(), |
| 960 | (portUp) ? "UP" : "DOWN", port.number()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 961 | } |
| 962 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 963 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 964 | private class InternalConfigListener implements NetworkConfigListener { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 965 | SegmentRoutingManager srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 966 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 967 | /** |
| 968 | * Constructs the internal network config listener. |
| 969 | * |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 970 | * @param srManager segment routing manager |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 971 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 972 | public InternalConfigListener(SegmentRoutingManager srManager) { |
| 973 | this.srManager = srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 976 | /** |
| 977 | * Reads network config and initializes related data structure accordingly. |
| 978 | */ |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 979 | public void configureNetwork() { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 980 | deviceConfiguration = new DeviceConfiguration(srManager); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 981 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 982 | arpHandler = new ArpHandler(srManager); |
| 983 | icmpHandler = new IcmpHandler(srManager); |
| 984 | ipHandler = new IpHandler(srManager); |
| 985 | routingRulePopulator = new RoutingRulePopulator(srManager); |
| 986 | defaultRoutingHandler = new DefaultRoutingHandler(srManager); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 987 | |
| 988 | tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
| 989 | groupHandlerMap, tunnelStore); |
| 990 | policyHandler = new PolicyHandler(appId, deviceConfiguration, |
| 991 | flowObjectiveService, |
| 992 | tunnelHandler, policyStore); |
| 993 | |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 994 | for (Device device : deviceService.getDevices()) { |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 995 | processDeviceAddedInternal(device.id()); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 999 | mcastHandler.init(); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1002 | @Override |
| 1003 | public void event(NetworkConfigEvent event) { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1004 | // TODO move this part to NetworkConfigEventHandler |
| 1005 | if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) { |
| 1006 | switch (event.type()) { |
| 1007 | case CONFIG_ADDED: |
| 1008 | log.info("Segment Routing Config added."); |
| 1009 | configureNetwork(); |
| 1010 | break; |
| 1011 | case CONFIG_UPDATED: |
| 1012 | log.info("Segment Routing Config updated."); |
| 1013 | // TODO support dynamic configuration |
| 1014 | break; |
| 1015 | default: |
| 1016 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1017 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1018 | } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) { |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1019 | checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized"); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1020 | switch (event.type()) { |
| 1021 | case CONFIG_ADDED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1022 | appCfgHandler.processAppConfigAdded(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1023 | break; |
| 1024 | case CONFIG_UPDATED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1025 | appCfgHandler.processAppConfigUpdated(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1026 | break; |
| 1027 | case CONFIG_REMOVED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1028 | appCfgHandler.processAppConfigRemoved(event); |
| 1029 | break; |
| 1030 | default: |
| 1031 | break; |
| 1032 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1033 | configureNetwork(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1034 | } else if (event.configClass().equals(XConnectConfig.class)) { |
| 1035 | checkState(xConnectHandler != null, "XConnectHandler is not initialized"); |
| 1036 | switch (event.type()) { |
| 1037 | case CONFIG_ADDED: |
| 1038 | xConnectHandler.processXConnectConfigAdded(event); |
| 1039 | break; |
| 1040 | case CONFIG_UPDATED: |
| 1041 | xConnectHandler.processXConnectConfigUpdated(event); |
| 1042 | break; |
| 1043 | case CONFIG_REMOVED: |
| 1044 | xConnectHandler.processXConnectConfigRemoved(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1045 | break; |
| 1046 | default: |
| 1047 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1048 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1052 | |
| 1053 | private class InternalHostListener implements HostListener { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1054 | @Override |
| 1055 | public void event(HostEvent event) { |
| 1056 | // Do not proceed without mastership |
| 1057 | DeviceId deviceId = event.subject().location().deviceId(); |
| 1058 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | switch (event.type()) { |
| 1063 | case HOST_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1064 | hostHandler.processHostAddedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1065 | break; |
| 1066 | case HOST_MOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1067 | hostHandler.processHostMovedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1068 | break; |
| 1069 | case HOST_REMOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1070 | hostHandler.processHostRemoveEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1071 | break; |
| 1072 | case HOST_UPDATED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1073 | hostHandler.processHostUpdatedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1074 | break; |
| 1075 | default: |
| 1076 | log.warn("Unsupported host event type: {}", event.type()); |
| 1077 | break; |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1082 | private class InternalMcastListener implements McastListener { |
| 1083 | @Override |
| 1084 | public void event(McastEvent event) { |
| 1085 | switch (event.type()) { |
| 1086 | case SOURCE_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1087 | mcastHandler.processSourceAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1088 | break; |
| 1089 | case SINK_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1090 | mcastHandler.processSinkAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | case SINK_REMOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1093 | mcastHandler.processSinkRemoved(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1094 | break; |
| 1095 | case ROUTE_ADDED: |
| 1096 | case ROUTE_REMOVED: |
| 1097 | default: |
| 1098 | break; |
| 1099 | } |
| 1100 | } |
| 1101 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 1102 | |
| 1103 | private class InternalCordConfigListener implements CordConfigListener { |
| 1104 | @Override |
| 1105 | public void event(CordConfigEvent event) { |
| 1106 | switch (event.type()) { |
| 1107 | case ACCESS_AGENT_ADDED: |
| 1108 | cordConfigHandler.processAccessAgentAddedEvent(event); |
| 1109 | break; |
| 1110 | case ACCESS_AGENT_UPDATED: |
| 1111 | cordConfigHandler.processAccessAgentUpdatedEvent(event); |
| 1112 | break; |
| 1113 | case ACCESS_AGENT_REMOVED: |
| 1114 | cordConfigHandler.processAccessAgentRemovedEvent(event); |
| 1115 | break; |
| 1116 | case ACCESS_DEVICE_ADDED: |
| 1117 | case ACCESS_DEVICE_UPDATED: |
| 1118 | case ACCESS_DEVICE_REMOVED: |
| 1119 | default: |
| 1120 | break; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1124 | |
| 1125 | private class InternalRouteEventListener implements RouteListener { |
| 1126 | @Override |
| 1127 | public void event(RouteEvent event) { |
| 1128 | switch (event.type()) { |
| 1129 | case ROUTE_ADDED: |
| 1130 | routeHandler.processRouteAdded(event); |
| 1131 | break; |
| 1132 | case ROUTE_UPDATED: |
| 1133 | routeHandler.processRouteUpdated(event); |
| 1134 | break; |
| 1135 | case ROUTE_REMOVED: |
| 1136 | routeHandler.processRouteRemoved(event); |
| 1137 | break; |
| 1138 | default: |
| 1139 | break; |
| 1140 | } |
| 1141 | } |
| 1142 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1143 | } |