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