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(); |
| 651 | ipHandler.addToPacketBuffer(ipPacket); |
| 652 | if (ipPacket.getProtocol() == IPv4.PROTOCOL_ICMP) { |
| 653 | icmpHandler.processPacketIn(pkt); |
| 654 | } else { |
| 655 | ipHandler.processPacketIn(pkt); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | private class InternalLinkListener implements LinkListener { |
| 662 | @Override |
| 663 | public void event(LinkEvent event) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 664 | if (event.type() == LinkEvent.Type.LINK_ADDED |
| 665 | || event.type() == LinkEvent.Type.LINK_REMOVED) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 666 | log.debug("Event {} received from Link Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 667 | scheduleEventHandlerIfNotScheduled(event); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | private class InternalDeviceListener implements DeviceListener { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 673 | @Override |
| 674 | public void event(DeviceEvent event) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 675 | switch (event.type()) { |
| 676 | case DEVICE_ADDED: |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 677 | case PORT_UPDATED: |
| 678 | case PORT_ADDED: |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 679 | case DEVICE_UPDATED: |
| 680 | case DEVICE_AVAILABILITY_CHANGED: |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 681 | log.debug("Event {} received from Device Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 682 | scheduleEventHandlerIfNotScheduled(event); |
| 683 | break; |
| 684 | default: |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 689 | @SuppressWarnings("rawtypes") |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 690 | private void scheduleEventHandlerIfNotScheduled(Event event) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 691 | synchronized (threadSchedulerLock) { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 692 | eventQueue.add(event); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 693 | numOfEventsQueued++; |
| 694 | |
| 695 | if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) { |
| 696 | //No pending scheduled event handling threads. So start a new one. |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 697 | eventHandlerFuture = executorService |
| 698 | .schedule(eventHandler, 100, TimeUnit.MILLISECONDS); |
| 699 | numOfHandlerScheduled++; |
| 700 | } |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 701 | log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}", |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 702 | numOfEventsQueued, |
| 703 | numOfHandlerScheduled); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 704 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | private class InternalEventHandler implements Runnable { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 708 | @Override |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 709 | public void run() { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 710 | try { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 711 | while (true) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 712 | @SuppressWarnings("rawtypes") |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 713 | Event event = null; |
| 714 | synchronized (threadSchedulerLock) { |
| 715 | if (!eventQueue.isEmpty()) { |
| 716 | event = eventQueue.poll(); |
| 717 | numOfEventsExecuted++; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 718 | } else { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 719 | numOfHandlerExecution++; |
| 720 | log.debug("numOfHandlerExecution {} numOfEventsExecuted {}", |
| 721 | numOfHandlerExecution, numOfEventsExecuted); |
| 722 | break; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 723 | } |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 724 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 725 | if (event.type() == LinkEvent.Type.LINK_ADDED) { |
| 726 | processLinkAdded((Link) event.subject()); |
| 727 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 728 | Link linkRemoved = (Link) event.subject(); |
| 729 | if (linkRemoved.src().elementId() instanceof DeviceId && |
| 730 | !deviceService.isAvailable(linkRemoved.src().deviceId())) { |
| 731 | continue; |
| 732 | } |
| 733 | if (linkRemoved.dst().elementId() instanceof DeviceId && |
| 734 | !deviceService.isAvailable(linkRemoved.dst().deviceId())) { |
| 735 | continue; |
| 736 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 737 | processLinkRemoved((Link) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 738 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 739 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 740 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 741 | DeviceId deviceId = ((Device) event.subject()).id(); |
| 742 | if (deviceService.isAvailable(deviceId)) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 743 | log.info("Processing device event {} for available device {}", |
| 744 | event.type(), ((Device) event.subject()).id()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 745 | processDeviceAdded((Device) event.subject()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 746 | } else { |
| 747 | log.info("Processing device event {} for unavailable device {}", |
| 748 | event.type(), ((Device) event.subject()).id()); |
| 749 | processDeviceRemoved((Device) event.subject()); |
| 750 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 751 | } else if (event.type() == DeviceEvent.Type.PORT_ADDED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 752 | // typically these calls come when device is added first time |
| 753 | // so port filtering rules are handled at the device_added event. |
| 754 | // port added calls represent all ports on the device, |
| 755 | // enabled or not. |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 756 | log.debug("** PORT ADDED {}/{} -> {}", |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 757 | ((DeviceEvent) event).subject().id(), |
| 758 | ((DeviceEvent) event).port().number(), |
| 759 | event.type()); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 760 | } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 761 | // these calls happen for every subsequent event |
| 762 | // ports enabled, disabled, switch goes away, comes back |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 763 | log.info("** PORT UPDATED {}/{} -> {}", |
| 764 | event.subject(), |
| 765 | ((DeviceEvent) event).port(), |
| 766 | event.type()); |
| 767 | processPortUpdated(((Device) event.subject()), |
| 768 | ((DeviceEvent) event).port()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 769 | } else { |
| 770 | log.warn("Unhandled event type: {}", event.type()); |
| 771 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 772 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 773 | } catch (Exception e) { |
| 774 | log.error("SegmentRouting event handler " |
| 775 | + "thread thrown an exception: {}", e); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 776 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 780 | private void processLinkAdded(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 781 | log.info("** LINK ADDED {}", link.toString()); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 782 | if (!deviceConfiguration.isConfigured(link.src().deviceId())) { |
| 783 | log.warn("Source device of this link is not configured."); |
| 784 | return; |
| 785 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 786 | //Irrespective whether the local is a MASTER or not for this device, |
| 787 | //create group handler instance and push default TTP flow rules. |
| 788 | //Because in a multi-instance setup, instances can initiate |
| 789 | //groups for any devices. Also the default TTP rules are needed |
| 790 | //to be pushed before inserting any IP table entries for any device |
| 791 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src() |
| 792 | .deviceId()); |
| 793 | if (groupHandler != null) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 794 | groupHandler.linkUp(link, mastershipService.isLocalMaster( |
| 795 | link.src().deviceId())); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 796 | } else { |
| 797 | Device device = deviceService.getDevice(link.src().deviceId()); |
| 798 | if (device != null) { |
| 799 | log.warn("processLinkAdded: Link Added " |
| 800 | + "Notification without Device Added " |
| 801 | + "event, still handling it"); |
| 802 | processDeviceAdded(device); |
| 803 | groupHandler = groupHandlerMap.get(link.src() |
| 804 | .deviceId()); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 805 | groupHandler.linkUp(link, mastershipService.isLocalMaster(device.id())); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 806 | } |
| 807 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 808 | |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 809 | log.trace("Starting optimized route population process"); |
| 810 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null); |
| 811 | //log.trace("processLinkAdded: re-starting route population process"); |
| 812 | //defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 813 | |
| 814 | mcastHandler.init(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | private void processLinkRemoved(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 818 | log.info("** LINK REMOVED {}", link.toString()); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 819 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId()); |
| 820 | if (groupHandler != null) { |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 821 | groupHandler.portDown(link.src().port(), |
| 822 | mastershipService.isLocalMaster(link.src().deviceId())); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 823 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 824 | log.trace("Starting optimized route population process"); |
| 825 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link); |
| 826 | //log.trace("processLinkRemoved: re-starting route population process"); |
| 827 | //defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 828 | |
| 829 | mcastHandler.processLinkDown(link); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | private void processDeviceAdded(Device device) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 833 | log.info("** DEVICE ADDED with ID {}", device.id()); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 834 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 835 | log.warn("Device configuration uploading. Device {} will be " |
| 836 | + "processed after config completes.", device.id()); |
| 837 | return; |
| 838 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 839 | processDeviceAddedInternal(device.id()); |
| 840 | } |
| 841 | |
| 842 | private void processDeviceAddedInternal(DeviceId deviceId) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 843 | // Irrespective of whether the local is a MASTER or not for this device, |
| 844 | // we need to create a SR-group-handler instance. This is because in a |
| 845 | // multi-instance setup, any instance can initiate forwarding/next-objectives |
| 846 | // for any switch (even if this instance is a SLAVE or not even connected |
| 847 | // to the switch). To handle this, a default-group-handler instance is necessary |
| 848 | // per switch. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 849 | log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet()); |
| 850 | if (groupHandlerMap.get(deviceId) == null) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 851 | DefaultGroupHandler groupHandler; |
| 852 | try { |
| 853 | groupHandler = DefaultGroupHandler. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 854 | createGroupHandler(deviceId, |
| 855 | appId, |
| 856 | deviceConfiguration, |
| 857 | linkService, |
| 858 | flowObjectiveService, |
| 859 | this); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 860 | } catch (DeviceConfigNotFoundException e) { |
| 861 | log.warn(e.getMessage() + " Aborting processDeviceAdded."); |
| 862 | return; |
| 863 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 864 | log.debug("updating groupHandlerMap with new config for device: {}", |
| 865 | deviceId); |
| 866 | groupHandlerMap.put(deviceId, groupHandler); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 867 | } |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 868 | // Also, in some cases, drivers may need extra |
| 869 | // information to process rules (eg. Router IP/MAC); and so, we send |
| 870 | // port addressing rules to the driver as well irrespective of whether |
| 871 | // this instance is the master or not. |
| 872 | defaultRoutingHandler.populatePortAddressingRules(deviceId); |
| 873 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 874 | if (mastershipService.isLocalMaster(deviceId)) { |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 875 | hostHandler.init(deviceId); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 876 | xConnectHandler.init(deviceId); |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 877 | cordConfigHandler.init(deviceId); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 878 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 879 | groupHandler.createGroupsFromSubnetConfig(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 880 | routingRulePopulator.populateSubnetBroadcastRule(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 881 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 882 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 883 | appCfgHandler.init(deviceId); |
| 884 | routeHandler.init(deviceId); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 887 | private void processDeviceRemoved(Device device) { |
| 888 | nsNextObjStore.entrySet().stream() |
| 889 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 890 | .forEach(entry -> { |
| 891 | nsNextObjStore.remove(entry.getKey()); |
| 892 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 893 | subnetNextObjStore.entrySet().stream() |
| 894 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 895 | .forEach(entry -> { |
| 896 | subnetNextObjStore.remove(entry.getKey()); |
| 897 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 898 | portNextObjStore.entrySet().stream() |
| 899 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 900 | .forEach(entry -> { |
| 901 | portNextObjStore.remove(entry.getKey()); |
| 902 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 903 | subnetVidStore.entrySet().stream() |
| 904 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 905 | .forEach(entry -> { |
| 906 | subnetVidStore.remove(entry.getKey()); |
| 907 | }); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 908 | groupHandlerMap.remove(device.id()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 909 | defaultRoutingHandler.purgeEcmpGraph(device.id()); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 910 | mcastHandler.removeDevice(device.id()); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 911 | xConnectHandler.removeDevice(device.id()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 914 | private void processPortUpdated(Device device, Port port) { |
| 915 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
| 916 | log.warn("Device configuration uploading. Not handling port event for" |
| 917 | + "dev: {} port: {}", device.id(), port.number()); |
| 918 | return; |
| 919 | } |
| 920 | /* XXX create method for single port filtering rules which are needed |
| 921 | for both switch-to-switch ports and edge ports |
| 922 | if (defaultRoutingHandler != null) { |
| 923 | defaultRoutingHandler.populatePortAddressingRules( |
| 924 | ((Device) event.subject()).id()); |
| 925 | }*/ |
| 926 | |
| 927 | // portUpdated calls are for ports that have gone down or up. For switch |
| 928 | // to switch ports, link-events should take care of any re-routing or |
| 929 | // group editing necessary for port up/down. Here we only process edge ports |
| 930 | // that are already configured. |
| 931 | Ip4Prefix configuredSubnet = deviceConfiguration.getPortSubnet(device.id(), |
| 932 | port.number()); |
| 933 | if (configuredSubnet == null) { |
| 934 | log.debug("Not handling port updated event for unconfigured port " |
| 935 | + "dev/port: {}/{}", device.id(), port.number()); |
| 936 | return; |
| 937 | } |
| 938 | processEdgePort(device, port, configuredSubnet); |
| 939 | } |
| 940 | |
| 941 | private void processEdgePort(Device device, Port port, Ip4Prefix subnet) { |
| 942 | boolean portUp = port.isEnabled(); |
| 943 | if (portUp) { |
| 944 | log.info("Device:EdgePort {}:{} is enabled in subnet: {}", device.id(), |
| 945 | port.number(), subnet); |
| 946 | } else { |
| 947 | log.info("Device:EdgePort {}:{} is disabled in subnet: {}", device.id(), |
| 948 | port.number(), subnet); |
| 949 | } |
| 950 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 951 | DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 952 | if (groupHandler != null) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 953 | groupHandler.processEdgePort(port.number(), subnet, portUp, |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 954 | mastershipService.isLocalMaster(device.id())); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 955 | } else { |
| 956 | log.warn("Group handler not found for dev:{}. Not handling edge port" |
| 957 | + " {} event for port:{}", device.id(), |
| 958 | (portUp) ? "UP" : "DOWN", port.number()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 959 | } |
| 960 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 961 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 962 | private class InternalConfigListener implements NetworkConfigListener { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 963 | SegmentRoutingManager srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 964 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 965 | /** |
| 966 | * Constructs the internal network config listener. |
| 967 | * |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 968 | * @param srManager segment routing manager |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 969 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 970 | public InternalConfigListener(SegmentRoutingManager srManager) { |
| 971 | this.srManager = srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 974 | /** |
| 975 | * Reads network config and initializes related data structure accordingly. |
| 976 | */ |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 977 | public void configureNetwork() { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 978 | deviceConfiguration = new DeviceConfiguration(srManager); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 979 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 980 | arpHandler = new ArpHandler(srManager); |
| 981 | icmpHandler = new IcmpHandler(srManager); |
| 982 | ipHandler = new IpHandler(srManager); |
| 983 | routingRulePopulator = new RoutingRulePopulator(srManager); |
| 984 | defaultRoutingHandler = new DefaultRoutingHandler(srManager); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 985 | |
| 986 | tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
| 987 | groupHandlerMap, tunnelStore); |
| 988 | policyHandler = new PolicyHandler(appId, deviceConfiguration, |
| 989 | flowObjectiveService, |
| 990 | tunnelHandler, policyStore); |
| 991 | |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 992 | for (Device device : deviceService.getDevices()) { |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 993 | processDeviceAddedInternal(device.id()); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | defaultRoutingHandler.startPopulationProcess(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 997 | mcastHandler.init(); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1000 | @Override |
| 1001 | public void event(NetworkConfigEvent event) { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1002 | // TODO move this part to NetworkConfigEventHandler |
| 1003 | if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) { |
| 1004 | switch (event.type()) { |
| 1005 | case CONFIG_ADDED: |
| 1006 | log.info("Segment Routing Config added."); |
| 1007 | configureNetwork(); |
| 1008 | break; |
| 1009 | case CONFIG_UPDATED: |
| 1010 | log.info("Segment Routing Config updated."); |
| 1011 | // TODO support dynamic configuration |
| 1012 | break; |
| 1013 | default: |
| 1014 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1015 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1016 | } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) { |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1017 | checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized"); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1018 | switch (event.type()) { |
| 1019 | case CONFIG_ADDED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1020 | appCfgHandler.processAppConfigAdded(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1021 | break; |
| 1022 | case CONFIG_UPDATED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1023 | appCfgHandler.processAppConfigUpdated(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1024 | break; |
| 1025 | case CONFIG_REMOVED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1026 | appCfgHandler.processAppConfigRemoved(event); |
| 1027 | break; |
| 1028 | default: |
| 1029 | break; |
| 1030 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1031 | configureNetwork(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1032 | } else if (event.configClass().equals(XConnectConfig.class)) { |
| 1033 | checkState(xConnectHandler != null, "XConnectHandler is not initialized"); |
| 1034 | switch (event.type()) { |
| 1035 | case CONFIG_ADDED: |
| 1036 | xConnectHandler.processXConnectConfigAdded(event); |
| 1037 | break; |
| 1038 | case CONFIG_UPDATED: |
| 1039 | xConnectHandler.processXConnectConfigUpdated(event); |
| 1040 | break; |
| 1041 | case CONFIG_REMOVED: |
| 1042 | xConnectHandler.processXConnectConfigRemoved(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1043 | break; |
| 1044 | default: |
| 1045 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1046 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1050 | |
| 1051 | private class InternalHostListener implements HostListener { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1052 | @Override |
| 1053 | public void event(HostEvent event) { |
| 1054 | // Do not proceed without mastership |
| 1055 | DeviceId deviceId = event.subject().location().deviceId(); |
| 1056 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | switch (event.type()) { |
| 1061 | case HOST_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1062 | hostHandler.processHostAddedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1063 | break; |
| 1064 | case HOST_MOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1065 | hostHandler.processHostMovedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1066 | break; |
| 1067 | case HOST_REMOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1068 | hostHandler.processHostRemoveEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1069 | break; |
| 1070 | case HOST_UPDATED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1071 | hostHandler.processHostUpdatedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1072 | break; |
| 1073 | default: |
| 1074 | log.warn("Unsupported host event type: {}", event.type()); |
| 1075 | break; |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1080 | private class InternalMcastListener implements McastListener { |
| 1081 | @Override |
| 1082 | public void event(McastEvent event) { |
| 1083 | switch (event.type()) { |
| 1084 | case SOURCE_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1085 | mcastHandler.processSourceAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1086 | break; |
| 1087 | case SINK_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1088 | mcastHandler.processSinkAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1089 | break; |
| 1090 | case SINK_REMOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1091 | mcastHandler.processSinkRemoved(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1092 | break; |
| 1093 | case ROUTE_ADDED: |
| 1094 | case ROUTE_REMOVED: |
| 1095 | default: |
| 1096 | break; |
| 1097 | } |
| 1098 | } |
| 1099 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 1100 | |
| 1101 | private class InternalCordConfigListener implements CordConfigListener { |
| 1102 | @Override |
| 1103 | public void event(CordConfigEvent event) { |
| 1104 | switch (event.type()) { |
| 1105 | case ACCESS_AGENT_ADDED: |
| 1106 | cordConfigHandler.processAccessAgentAddedEvent(event); |
| 1107 | break; |
| 1108 | case ACCESS_AGENT_UPDATED: |
| 1109 | cordConfigHandler.processAccessAgentUpdatedEvent(event); |
| 1110 | break; |
| 1111 | case ACCESS_AGENT_REMOVED: |
| 1112 | cordConfigHandler.processAccessAgentRemovedEvent(event); |
| 1113 | break; |
| 1114 | case ACCESS_DEVICE_ADDED: |
| 1115 | case ACCESS_DEVICE_UPDATED: |
| 1116 | case ACCESS_DEVICE_REMOVED: |
| 1117 | default: |
| 1118 | break; |
| 1119 | } |
| 1120 | } |
| 1121 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1122 | |
| 1123 | private class InternalRouteEventListener implements RouteListener { |
| 1124 | @Override |
| 1125 | public void event(RouteEvent event) { |
| 1126 | switch (event.type()) { |
| 1127 | case ROUTE_ADDED: |
| 1128 | routeHandler.processRouteAdded(event); |
| 1129 | break; |
| 1130 | case ROUTE_UPDATED: |
| 1131 | routeHandler.processRouteUpdated(event); |
| 1132 | break; |
| 1133 | case ROUTE_REMOVED: |
| 1134 | routeHandler.processRouteRemoved(event); |
| 1135 | break; |
| 1136 | default: |
| 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1141 | } |