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