sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 18 | import java.util.List; |
| 19 | import java.util.Map; |
| 20 | import java.util.Map.Entry; |
| 21 | import java.util.Optional; |
| 22 | import java.util.Set; |
| 23 | import java.util.concurrent.ConcurrentHashMap; |
| 24 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 25 | import java.util.concurrent.Executors; |
| 26 | import java.util.concurrent.ScheduledExecutorService; |
| 27 | import java.util.concurrent.ScheduledFuture; |
| 28 | import java.util.concurrent.TimeUnit; |
| 29 | import java.util.concurrent.atomic.AtomicBoolean; |
| 30 | import java.util.stream.Collectors; |
| 31 | |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 32 | import com.google.common.collect.Sets; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 33 | import org.apache.felix.scr.annotations.Activate; |
| 34 | import org.apache.felix.scr.annotations.Component; |
| 35 | import org.apache.felix.scr.annotations.Deactivate; |
| 36 | import org.apache.felix.scr.annotations.Reference; |
| 37 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 38 | import org.apache.felix.scr.annotations.Service; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 39 | import org.onlab.packet.Ethernet; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 40 | import org.onlab.packet.ICMP6; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 41 | import org.onlab.packet.IPv4; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 42 | import org.onlab.packet.IPv6; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 43 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 44 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 45 | import org.onlab.util.KryoNamespace; |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 46 | import org.onosproject.cfg.ComponentConfigService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 47 | import org.onosproject.core.ApplicationId; |
| 48 | import org.onosproject.core.CoreService; |
| 49 | import org.onosproject.event.Event; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 50 | import org.onosproject.mastership.MastershipService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 51 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 52 | import org.onosproject.net.Device; |
| 53 | import org.onosproject.net.DeviceId; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 54 | import org.onosproject.net.Host; |
| 55 | import org.onosproject.net.HostId; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 56 | import org.onosproject.net.Link; |
| 57 | import org.onosproject.net.Port; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 58 | import org.onosproject.net.PortNumber; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 59 | import org.onosproject.net.config.ConfigFactory; |
| 60 | import org.onosproject.net.config.NetworkConfigEvent; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 61 | import org.onosproject.net.config.NetworkConfigListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 62 | import org.onosproject.net.config.NetworkConfigRegistry; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 63 | import org.onosproject.net.config.basics.InterfaceConfig; |
| 64 | import org.onosproject.net.config.basics.McastConfig; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 65 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 66 | import org.onosproject.net.device.DeviceEvent; |
| 67 | import org.onosproject.net.device.DeviceListener; |
| 68 | import org.onosproject.net.device.DeviceService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 69 | import org.onosproject.net.flow.TrafficSelector; |
| 70 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 71 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 72 | import org.onosproject.net.host.HostEvent; |
| 73 | import org.onosproject.net.host.HostListener; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 74 | import org.onosproject.net.host.HostService; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 75 | import org.onosproject.net.intf.Interface; |
| 76 | import org.onosproject.net.intf.InterfaceService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 77 | import org.onosproject.net.link.LinkEvent; |
| 78 | import org.onosproject.net.link.LinkListener; |
| 79 | import org.onosproject.net.link.LinkService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 80 | import org.onosproject.net.mcast.McastEvent; |
| 81 | import org.onosproject.net.mcast.McastListener; |
| 82 | import org.onosproject.net.mcast.MulticastRouteService; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 83 | import org.onosproject.net.neighbour.NeighbourResolutionService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 84 | import org.onosproject.net.packet.InboundPacket; |
| 85 | import org.onosproject.net.packet.PacketContext; |
| 86 | import org.onosproject.net.packet.PacketProcessor; |
| 87 | import org.onosproject.net.packet.PacketService; |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 88 | import org.onosproject.net.topology.PathService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 89 | import org.onosproject.net.topology.TopologyService; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 90 | import org.onosproject.routeservice.ResolvedRoute; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 91 | import org.onosproject.routeservice.RouteEvent; |
| 92 | import org.onosproject.routeservice.RouteListener; |
| 93 | import org.onosproject.routeservice.RouteService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 94 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 95 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 96 | import org.onosproject.segmentrouting.config.PwaasConfig; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 97 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 98 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 99 | import org.onosproject.segmentrouting.config.XConnectConfig; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 100 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 101 | import org.onosproject.segmentrouting.grouphandler.DestinationSet; |
| 102 | import org.onosproject.segmentrouting.grouphandler.NextNeighbors; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 103 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 104 | import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 105 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 106 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 107 | import org.onosproject.segmentrouting.storekey.XConnectStoreKey; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 108 | import org.onosproject.store.serializers.KryoNamespaces; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 109 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 110 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
| 111 | import org.onosproject.store.service.StorageService; |
| 112 | import org.onosproject.store.service.WallClockTimestamp; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 113 | import org.slf4j.Logger; |
| 114 | import org.slf4j.LoggerFactory; |
| 115 | |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 116 | import com.google.common.collect.HashMultimap; |
| 117 | import com.google.common.collect.ImmutableMap; |
| 118 | import com.google.common.collect.Maps; |
| 119 | import com.google.common.collect.Multimap; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 120 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 121 | import static com.google.common.base.Preconditions.checkState; |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 122 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 123 | import static org.onlab.util.Tools.groupedThreads; |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 124 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 125 | /** |
| 126 | * Segment routing manager. |
| 127 | */ |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 128 | @Service |
| 129 | @Component(immediate = true) |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 130 | public class SegmentRoutingManager implements SegmentRoutingService { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 131 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 132 | private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 133 | |
| 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 135 | private ComponentConfigService compCfgService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 136 | |
| 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 138 | private NeighbourResolutionService neighbourResolutionService; |
| 139 | |
| 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 141 | public PathService pathService; |
| 142 | |
| 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 144 | CoreService coreService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 145 | |
| 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 147 | PacketService packetService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 148 | |
| 149 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 150 | HostService hostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 151 | |
| 152 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 153 | DeviceService deviceService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 154 | |
| 155 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 156 | public FlowObjectiveService flowObjectiveService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 157 | |
| 158 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 159 | LinkService linkService; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 160 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 161 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 162 | public MastershipService mastershipService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 163 | |
| 164 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 165 | public StorageService storageService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 166 | |
| 167 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 168 | MulticastRouteService multicastRouteService; |
| 169 | |
| 170 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 171 | TopologyService topologyService; |
| 172 | |
| 173 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 174 | RouteService routeService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 175 | |
| 176 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 177 | public NetworkConfigRegistry cfgService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 178 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 179 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 180 | public InterfaceService interfaceService; |
| 181 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 182 | ArpHandler arpHandler = null; |
| 183 | IcmpHandler icmpHandler = null; |
| 184 | IpHandler ipHandler = null; |
| 185 | RoutingRulePopulator routingRulePopulator = null; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 186 | ApplicationId appId; |
| 187 | DeviceConfiguration deviceConfiguration = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 188 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 189 | DefaultRoutingHandler defaultRoutingHandler = null; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 190 | private TunnelHandler tunnelHandler = null; |
| 191 | private PolicyHandler policyHandler = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 192 | private InternalPacketProcessor processor = null; |
| 193 | private InternalLinkListener linkListener = null; |
| 194 | private InternalDeviceListener deviceListener = null; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 195 | private AppConfigHandler appCfgHandler = null; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 196 | XConnectHandler xConnectHandler = null; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 197 | private McastHandler mcastHandler = null; |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 198 | private HostHandler hostHandler = null; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 199 | private RouteHandler routeHandler = null; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 200 | private SegmentRoutingNeighbourDispatcher neighbourHandler = null; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 201 | private L2TunnelHandler l2TunnelHandler = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 202 | private InternalEventHandler eventHandler = new InternalEventHandler(); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 203 | private final InternalHostListener hostListener = new InternalHostListener(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 204 | private final InternalConfigListener cfgListener = new InternalConfigListener(this); |
| 205 | private final InternalMcastListener mcastListener = new InternalMcastListener(); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 206 | private final InternalRouteEventListener routeListener = new InternalRouteEventListener(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 207 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 208 | private ScheduledExecutorService executorService = Executors |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 209 | .newScheduledThreadPool(1, groupedThreads("SegmentRoutingManager", "event-%d", log)); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 210 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 211 | @SuppressWarnings("unused") |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 212 | private static ScheduledFuture<?> eventHandlerFuture = null; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 213 | @SuppressWarnings("rawtypes") |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 214 | private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<>(); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 215 | private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 216 | new ConcurrentHashMap<>(); |
| 217 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 218 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 219 | * Used to keep track on MPLS group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 220 | */ |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 221 | EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
| 222 | dsNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 223 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 224 | * Per device next objective ID store with (device id + vlanid) as key. |
| 225 | * Used to keep track on L2 flood group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 226 | */ |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 227 | EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 228 | vlanNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 229 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 230 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
| 231 | * Used to keep track on L2 interface group and L3 unicast group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 232 | */ |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 233 | EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 234 | portNextObjStore = null; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 235 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 236 | // Local store for all links seen and their present status, used for |
| 237 | // optimized routing. The existence of the link in the keys is enough to know |
| 238 | // if the link has been "seen-before" by this instance of the controller. |
| 239 | // The boolean value indicates if the link is currently up or not. |
| 240 | // XXX Currently the optimized routing logic depends on "forgetting" a link |
| 241 | // when a switch goes down, but "remembering" it when only the link goes down. |
| 242 | // Consider changing this logic so we can use the Link Service instead of |
| 243 | // a local cache. |
| 244 | private Map<Link, Boolean> seenLinks = new ConcurrentHashMap<>(); |
| 245 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 246 | private EventuallyConsistentMap<String, Tunnel> tunnelStore = null; |
| 247 | private EventuallyConsistentMap<String, Policy> policyStore = null; |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 248 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 249 | private AtomicBoolean programmingScheduled = new AtomicBoolean(); |
| 250 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 251 | private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 252 | new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>( |
| 253 | SubjectFactories.DEVICE_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 254 | SegmentRoutingDeviceConfig.class, "segmentrouting") { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 255 | @Override |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 256 | public SegmentRoutingDeviceConfig createConfig() { |
| 257 | return new SegmentRoutingDeviceConfig(); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 258 | } |
| 259 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 260 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 261 | private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 262 | new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>( |
| 263 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 264 | SegmentRoutingAppConfig.class, "segmentrouting") { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 265 | @Override |
| 266 | public SegmentRoutingAppConfig createConfig() { |
| 267 | return new SegmentRoutingAppConfig(); |
| 268 | } |
| 269 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 270 | |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 271 | private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory = |
| 272 | new ConfigFactory<ApplicationId, XConnectConfig>( |
| 273 | SubjectFactories.APP_SUBJECT_FACTORY, |
| 274 | XConnectConfig.class, "xconnect") { |
| 275 | @Override |
| 276 | public XConnectConfig createConfig() { |
| 277 | return new XConnectConfig(); |
| 278 | } |
| 279 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 280 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 281 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 282 | new ConfigFactory<ApplicationId, McastConfig>( |
| 283 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 284 | McastConfig.class, "multicast") { |
| 285 | @Override |
| 286 | public McastConfig createConfig() { |
| 287 | return new McastConfig(); |
| 288 | } |
| 289 | }; |
| 290 | |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 291 | private final ConfigFactory<ApplicationId, PwaasConfig> pwaasConfigFactory = |
| 292 | new ConfigFactory<ApplicationId, PwaasConfig>( |
| 293 | SubjectFactories.APP_SUBJECT_FACTORY, |
| 294 | PwaasConfig.class, "pwaas") { |
| 295 | @Override |
| 296 | public PwaasConfig createConfig() { |
| 297 | return new PwaasConfig(); |
| 298 | } |
| 299 | }; |
| 300 | |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 301 | private static final Object THREAD_SCHED_LOCK = new Object(); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 302 | private static int numOfEventsQueued = 0; |
| 303 | private static int numOfEventsExecuted = 0; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 304 | private static int numOfHandlerExecution = 0; |
| 305 | private static int numOfHandlerScheduled = 0; |
| 306 | |
Charles Chan | 1963f4f | 2016-02-18 14:22:42 -0800 | [diff] [blame] | 307 | /** |
| 308 | * Segment Routing App ID. |
| 309 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 310 | public static final String APP_NAME = "org.onosproject.segmentrouting"; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 311 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 312 | /** |
| 313 | * The default VLAN ID assigned to the interfaces without subnet config. |
| 314 | */ |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 315 | public static final VlanId INTERNAL_VLAN = VlanId.vlanId((short) 4094); |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 316 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 317 | @Activate |
| 318 | protected void activate() { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 319 | appId = coreService.registerApplication(APP_NAME); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 320 | |
| 321 | log.debug("Creating EC map nsnextobjectivestore"); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 322 | EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 323 | nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 324 | dsNextObjStore = nsNextObjMapBuilder |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 325 | .withName("nsnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 326 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 327 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 328 | .build(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 329 | log.trace("Current size {}", dsNextObjStore.size()); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 330 | |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 331 | log.debug("Creating EC map vlannextobjectivestore"); |
| 332 | EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer> |
| 333 | vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 334 | vlanNextObjStore = vlanNextObjMapBuilder |
| 335 | .withName("vlannextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 336 | .withSerializer(createSerializer()) |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 337 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 338 | .build(); |
| 339 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 340 | log.debug("Creating EC map subnetnextobjectivestore"); |
| 341 | EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer> |
| 342 | portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 343 | portNextObjStore = portNextObjMapBuilder |
| 344 | .withName("portnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 345 | .withSerializer(createSerializer()) |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 346 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 347 | .build(); |
| 348 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 349 | EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder = |
| 350 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 351 | tunnelStore = tunnelMapBuilder |
| 352 | .withName("tunnelstore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 353 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 354 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 355 | .build(); |
| 356 | |
| 357 | EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder = |
| 358 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 359 | policyStore = policyMapBuilder |
| 360 | .withName("policystore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 361 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 362 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 363 | .build(); |
| 364 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 365 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 366 | "purgeOnDisconnection", "true"); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 367 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 368 | "purgeOnDisconnection", "true"); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 369 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
| 370 | "requestInterceptsEnabled", "false"); |
Charles Chan | c1909e1 | 2017-08-08 15:13:37 -0700 | [diff] [blame] | 371 | compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager", |
Pier Luigi | bc976df | 2017-01-12 22:46:39 -0800 | [diff] [blame] | 372 | "requestInterceptsEnabled", "false"); |
Charles Chan | 9597f8d | 2017-07-24 15:56:10 -0700 | [diff] [blame] | 373 | compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager", |
Pier Luigi | bc976df | 2017-01-12 22:46:39 -0800 | [diff] [blame] | 374 | "arpEnabled", "false"); |
Pier Luigi | 0ebeb31 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 375 | compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager", |
| 376 | "greedyLearningIpv6", "true"); |
Charles Chan | cf8ea47 | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 377 | compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager", |
| 378 | "forceUnprovision", "true"); |
Charles Chan | c7b73c7 | 2017-08-10 16:57:28 -0700 | [diff] [blame] | 379 | compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl", |
Charles Chan | 4c95c0d | 2017-07-20 16:16:25 -0700 | [diff] [blame] | 380 | "distributed", "true"); |
Charles Chan | 804772f | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 381 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
| 382 | "multihomingEnabled", "true"); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 383 | |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 384 | processor = new InternalPacketProcessor(); |
| 385 | linkListener = new InternalLinkListener(); |
| 386 | deviceListener = new InternalDeviceListener(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 387 | appCfgHandler = new AppConfigHandler(this); |
| 388 | xConnectHandler = new XConnectHandler(this); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 389 | mcastHandler = new McastHandler(this); |
| 390 | hostHandler = new HostHandler(this); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 391 | routeHandler = new RouteHandler(this); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 392 | neighbourHandler = new SegmentRoutingNeighbourDispatcher(this); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 393 | l2TunnelHandler = new L2TunnelHandler(this); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 394 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 395 | cfgService.addListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 396 | cfgService.registerConfigFactory(deviceConfigFactory); |
| 397 | cfgService.registerConfigFactory(appConfigFactory); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 398 | cfgService.registerConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 399 | cfgService.registerConfigFactory(mcastConfigFactory); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 400 | cfgService.registerConfigFactory(pwaasConfigFactory); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 401 | hostService.addListener(hostListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 402 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
| 403 | linkService.addListener(linkListener); |
| 404 | deviceService.addListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 405 | multicastRouteService.addListener(mcastListener); |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 406 | routeService.addListener(routeListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 407 | |
| 408 | cfgListener.configureNetwork(); |
| 409 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 410 | log.info("Started"); |
| 411 | } |
| 412 | |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 413 | private KryoNamespace.Builder createSerializer() { |
| 414 | return new KryoNamespace.Builder() |
| 415 | .register(KryoNamespaces.API) |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 416 | .register(DestinationSetNextObjectiveStoreKey.class, |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 417 | VlanNextObjectiveStoreKey.class, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 418 | DestinationSet.class, |
| 419 | NextNeighbors.class, |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 420 | Tunnel.class, |
| 421 | DefaultTunnel.class, |
| 422 | Policy.class, |
| 423 | TunnelPolicy.class, |
| 424 | Policy.Type.class, |
| 425 | PortNextObjectiveStoreKey.class, |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 426 | XConnectStoreKey.class |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 427 | ); |
| 428 | } |
| 429 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 430 | @Deactivate |
| 431 | protected void deactivate() { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 432 | cfgService.removeListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 433 | cfgService.unregisterConfigFactory(deviceConfigFactory); |
| 434 | cfgService.unregisterConfigFactory(appConfigFactory); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 435 | cfgService.unregisterConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 436 | cfgService.unregisterConfigFactory(mcastConfigFactory); |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 437 | cfgService.unregisterConfigFactory(pwaasConfigFactory); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 438 | |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 439 | hostService.removeListener(hostListener); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 440 | packetService.removeProcessor(processor); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 441 | linkService.removeListener(linkListener); |
| 442 | deviceService.removeListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 443 | multicastRouteService.removeListener(mcastListener); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 444 | routeService.removeListener(routeListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 445 | |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 446 | neighbourResolutionService.unregisterNeighbourHandlers(appId); |
| 447 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 448 | processor = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 449 | linkListener = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 450 | deviceListener = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 451 | groupHandlerMap.clear(); |
| 452 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 453 | dsNextObjStore.destroy(); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 454 | vlanNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 455 | portNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 456 | tunnelStore.destroy(); |
| 457 | policyStore.destroy(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 458 | log.info("Stopped"); |
| 459 | } |
| 460 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 461 | @Override |
| 462 | public List<Tunnel> getTunnels() { |
| 463 | return tunnelHandler.getTunnels(); |
| 464 | } |
| 465 | |
| 466 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 467 | public TunnelHandler.Result createTunnel(Tunnel tunnel) { |
| 468 | return tunnelHandler.createTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 472 | public TunnelHandler.Result removeTunnel(Tunnel tunnel) { |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 473 | for (Policy policy: policyHandler.getPolicies()) { |
| 474 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
| 475 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
| 476 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { |
| 477 | log.warn("Cannot remove the tunnel used by a policy"); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 478 | return TunnelHandler.Result.TUNNEL_IN_USE; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 482 | return tunnelHandler.removeTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 486 | public PolicyHandler.Result removePolicy(Policy policy) { |
| 487 | return policyHandler.removePolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 491 | public PolicyHandler.Result createPolicy(Policy policy) { |
| 492 | return policyHandler.createPolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public List<Policy> getPolicies() { |
| 497 | return policyHandler.getPolicies(); |
| 498 | } |
| 499 | |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 500 | @Override |
| 501 | public void rerouteNetwork() { |
| 502 | cfgListener.configureNetwork(); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 505 | @Override |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 506 | public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() { |
| 507 | Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap(); |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 508 | deviceService.getAvailableDevices().forEach(device -> { |
| 509 | deviceSubnetMap.put(device.id(), deviceConfiguration.getSubnets(device.id())); |
| 510 | }); |
| 511 | return deviceSubnetMap; |
| 512 | } |
| 513 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 514 | |
| 515 | @Override |
| 516 | public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() { |
| 517 | if (defaultRoutingHandler != null) { |
| 518 | return defaultRoutingHandler.getCurrentEmcpSpgMap(); |
| 519 | } else { |
| 520 | return null; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | @Override |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 525 | public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDestinationSet() { |
| 526 | if (dsNextObjStore != null) { |
| 527 | return ImmutableMap.copyOf(dsNextObjStore.entrySet()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 528 | } else { |
| 529 | return ImmutableMap.of(); |
| 530 | } |
| 531 | } |
| 532 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 533 | @Override |
| 534 | public void verifyGroups(DeviceId id) { |
| 535 | DefaultGroupHandler gh = groupHandlerMap.get(id); |
| 536 | if (gh != null) { |
| 537 | gh.triggerBucketCorrector(); |
| 538 | } |
| 539 | } |
| 540 | |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 541 | /** |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 542 | * Extracts the application ID from the manager. |
| 543 | * |
| 544 | * @return application ID |
| 545 | */ |
| 546 | public ApplicationId appId() { |
| 547 | return appId; |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Returns the device configuration. |
| 552 | * |
| 553 | * @return device configuration |
| 554 | */ |
| 555 | public DeviceConfiguration deviceConfiguration() { |
| 556 | return deviceConfiguration; |
| 557 | } |
| 558 | |
| 559 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 560 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 561 | * Used to keep track on MPLS group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 562 | * |
| 563 | * @return next objective ID store |
| 564 | */ |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 565 | public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
| 566 | dsNextObjStore() { |
| 567 | return dsNextObjStore; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 571 | * Per device next objective ID store with (device id + vlanid) as key. |
| 572 | * Used to keep track on L2 flood group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 573 | * |
| 574 | * @return vlan next object store |
| 575 | */ |
| 576 | public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() { |
| 577 | return vlanNextObjStore; |
| 578 | } |
| 579 | |
| 580 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 581 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
| 582 | * Used to keep track on L2 interface group and L3 unicast group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 583 | * |
| 584 | * @return port next object store. |
| 585 | */ |
| 586 | public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() { |
| 587 | return portNextObjStore; |
| 588 | } |
| 589 | |
| 590 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 591 | * Returns the MPLS-ECMP configuration which indicates whether ECMP on |
| 592 | * labeled packets should be programmed or not. |
Pier Ventre | 7a78de2 | 2016-10-31 15:00:01 -0700 | [diff] [blame] | 593 | * |
| 594 | * @return MPLS-ECMP value |
| 595 | */ |
| 596 | public boolean getMplsEcmp() { |
| 597 | SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService |
| 598 | .getConfig(this.appId, SegmentRoutingAppConfig.class); |
| 599 | return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp(); |
| 600 | } |
| 601 | |
| 602 | /** |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 603 | * Returns the tunnel object with the tunnel ID. |
| 604 | * |
| 605 | * @param tunnelId Tunnel ID |
| 606 | * @return Tunnel reference |
| 607 | */ |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 608 | public Tunnel getTunnel(String tunnelId) { |
| 609 | return tunnelHandler.getTunnel(tunnelId); |
| 610 | } |
| 611 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 612 | // TODO Consider moving these to InterfaceService |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 613 | /** |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 614 | * Returns untagged VLAN configured on given connect point. |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 615 | * <p> |
| 616 | * Only returns the first match if there are multiple untagged VLAN configured |
| 617 | * on the connect point. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 618 | * |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 619 | * @param connectPoint connect point |
| 620 | * @return untagged VLAN or null if not configured |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 621 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 622 | VlanId getUntaggedVlanId(ConnectPoint connectPoint) { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 623 | return interfaceService.getInterfacesByPort(connectPoint).stream() |
| 624 | .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE)) |
| 625 | .map(Interface::vlanUntagged) |
| 626 | .findFirst().orElse(null); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 627 | } |
| 628 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 629 | /** |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 630 | * Returns tagged VLAN configured on given connect point. |
| 631 | * <p> |
| 632 | * Returns all matches if there are multiple tagged VLAN configured |
| 633 | * on the connect point. |
| 634 | * |
| 635 | * @param connectPoint connect point |
| 636 | * @return tagged VLAN or empty set if not configured |
| 637 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 638 | Set<VlanId> getTaggedVlanId(ConnectPoint connectPoint) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 639 | Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint); |
| 640 | return interfaces.stream() |
| 641 | .map(Interface::vlanTagged) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 642 | .flatMap(Set::stream) |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 643 | .collect(Collectors.toSet()); |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Returns native VLAN configured on given connect point. |
| 648 | * <p> |
| 649 | * Only returns the first match if there are multiple native VLAN configured |
| 650 | * on the connect point. |
| 651 | * |
| 652 | * @param connectPoint connect point |
| 653 | * @return native VLAN or null if not configured |
| 654 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 655 | VlanId getNativeVlanId(ConnectPoint connectPoint) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 656 | Set<Interface> interfaces = interfaceService.getInterfacesByPort(connectPoint); |
| 657 | return interfaces.stream() |
| 658 | .filter(intf -> !intf.vlanNative().equals(VlanId.NONE)) |
| 659 | .map(Interface::vlanNative) |
| 660 | .findFirst() |
| 661 | .orElse(null); |
| 662 | } |
| 663 | |
| 664 | /** |
Charles Chan | d9265a3 | 2017-06-16 15:19:24 -0700 | [diff] [blame] | 665 | * Returns internal VLAN for untagged hosts on given connect point. |
| 666 | * <p> |
| 667 | * The internal VLAN is either vlan-untagged for an access port, |
| 668 | * or vlan-native for a trunk port. |
| 669 | * |
| 670 | * @param connectPoint connect point |
| 671 | * @return internal VLAN or null if both vlan-untagged and vlan-native are undefined |
| 672 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 673 | VlanId getInternalVlanId(ConnectPoint connectPoint) { |
Charles Chan | d9265a3 | 2017-06-16 15:19:24 -0700 | [diff] [blame] | 674 | VlanId untaggedVlanId = getUntaggedVlanId(connectPoint); |
| 675 | VlanId nativeVlanId = getNativeVlanId(connectPoint); |
| 676 | return untaggedVlanId != null ? untaggedVlanId : nativeVlanId; |
| 677 | } |
| 678 | |
| 679 | /** |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 680 | * Returns optional pair device ID of given device. |
| 681 | * |
| 682 | * @param deviceId device ID |
| 683 | * @return optional pair device ID. Might be empty if pair device is not configured |
| 684 | */ |
| 685 | Optional<DeviceId> getPairDeviceId(DeviceId deviceId) { |
| 686 | SegmentRoutingDeviceConfig deviceConfig = |
| 687 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 688 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId); |
| 689 | } |
| 690 | /** |
| 691 | * Returns optional pair device local port of given device. |
| 692 | * |
| 693 | * @param deviceId device ID |
| 694 | * @return optional pair device ID. Might be empty if pair device is not configured |
| 695 | */ |
| 696 | Optional<PortNumber> getPairLocalPorts(DeviceId deviceId) { |
| 697 | SegmentRoutingDeviceConfig deviceConfig = |
| 698 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 699 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort); |
| 700 | } |
| 701 | |
| 702 | /** |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 703 | * Returns locations of given resolved route. |
| 704 | * |
| 705 | * @param resolvedRoute resolved route |
| 706 | * @return locations of nexthop. Might be empty if next hop is not found |
| 707 | */ |
| 708 | Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) { |
| 709 | HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan()); |
| 710 | return Optional.ofNullable(hostService.getHost(hostId)) |
| 711 | .map(Host::locations).orElse(Sets.newHashSet()) |
| 712 | .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet()); |
| 713 | } |
| 714 | |
| 715 | /** |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 716 | * Returns vlan port map of given device. |
| 717 | * |
| 718 | * @param deviceId device id |
| 719 | * @return vlan-port multimap |
| 720 | */ |
| 721 | public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) { |
| 722 | HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create(); |
| 723 | |
| 724 | interfaceService.getInterfaces().stream() |
| 725 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
| 726 | .forEach(intf -> { |
| 727 | vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port()); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 728 | intf.vlanTagged().forEach(vlanTagged -> |
| 729 | vlanPortMap.put(vlanTagged, intf.connectPoint().port()) |
| 730 | ); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 731 | vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port()); |
| 732 | }); |
| 733 | vlanPortMap.removeAll(VlanId.NONE); |
| 734 | |
| 735 | return vlanPortMap; |
| 736 | } |
| 737 | |
| 738 | /** |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 739 | * 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] | 740 | * 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] | 741 | * that the next-objective has been pre-created from configuration. |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 742 | * |
| 743 | * @param deviceId Device ID |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 744 | * @param vlanId VLAN ID |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 745 | * @return next objective ID or -1 if it was not found |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 746 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 747 | int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) { |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 748 | if (groupHandlerMap.get(deviceId) != null) { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 749 | log.trace("getVlanNextObjectiveId query in device {}", deviceId); |
| 750 | return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 751 | } else { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 752 | log.warn("getVlanNextObjectiveId query - groupHandler for " |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 753 | + "device {} not found", deviceId); |
| 754 | return -1; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Returns the next objective ID for the given portNumber, given the treatment. |
| 760 | * There could be multiple different treatments to the same outport, which |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 761 | * would result in different objectives. If the next object does not exist, |
| 762 | * and should be created, a new one is created and its id is returned. |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 763 | * |
| 764 | * @param deviceId Device ID |
| 765 | * @param portNum port number on device for which NextObjective is queried |
| 766 | * @param treatment the actions to apply on the packets (should include outport) |
| 767 | * @param meta metadata passed into the creation of a Next Objective if necessary |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 768 | * @param createIfMissing true if a next object should be created if not found |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 769 | * @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] | 770 | */ |
| 771 | public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum, |
| 772 | TrafficTreatment treatment, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 773 | TrafficSelector meta, |
| 774 | boolean createIfMissing) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 775 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 776 | if (ghdlr != null) { |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 777 | return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 778 | } else { |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 779 | log.warn("getPortNextObjectiveId query - groupHandler for device {}" |
| 780 | + " not found", deviceId); |
| 781 | return -1; |
| 782 | } |
| 783 | } |
| 784 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 785 | /** |
| 786 | * Returns the group handler object for the specified device id. |
| 787 | * |
| 788 | * @param devId the device identifier |
| 789 | * @return the groupHandler object for the device id, or null if not found |
| 790 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 791 | DefaultGroupHandler getGroupHandler(DeviceId devId) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 792 | return groupHandlerMap.get(devId); |
| 793 | } |
| 794 | |
| 795 | /** |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 796 | * Returns the default routing handler object. |
| 797 | * |
| 798 | * @return the default routing handler object |
| 799 | */ |
| 800 | public DefaultRoutingHandler getRoutingHandler() { |
| 801 | return defaultRoutingHandler; |
| 802 | } |
| 803 | |
| 804 | /** |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 805 | * Returns true if this controller instance has seen this link before. The |
| 806 | * link may not be currently up, but as long as the link had been seen before |
| 807 | * this method will return true. The one exception is when the link was |
| 808 | * indeed seen before, but this controller instance was forced to forget it |
| 809 | * by a call to purgeSeenLink method. |
| 810 | * |
| 811 | * @param link the infrastructure link being queried |
| 812 | * @return true if this controller instance has seen this link before |
| 813 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 814 | boolean isSeenLink(Link link) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 815 | return seenLinks.containsKey(link); |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Updates the seen link store. Updates can be for links that are currently |
| 820 | * available or not. |
| 821 | * |
| 822 | * @param link the link to update in the seen-link local store |
| 823 | * @param up the status of the link, true if up, false if down |
| 824 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 825 | void updateSeenLink(Link link, boolean up) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 826 | seenLinks.put(link, up); |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Returns the status of a seen-link (up or down). If the link has not |
| 831 | * been seen-before, a null object is returned. |
| 832 | * |
| 833 | * @param link the infrastructure link being queried |
| 834 | * @return null if the link was not seen-before; |
| 835 | * true if the seen-link is up; |
| 836 | * false if the seen-link is down |
| 837 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 838 | Boolean isSeenLinkUp(Link link) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 839 | return seenLinks.get(link); |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Makes this controller instance forget a previously seen before link. |
| 844 | * |
| 845 | * @param link the infrastructure link to purge |
| 846 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 847 | private void purgeSeenLink(Link link) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 848 | seenLinks.remove(link); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Returns the status of a link as parallel link. A parallel link |
| 853 | * is defined as a link which has common src and dst switches as another |
| 854 | * seen-link that is currently enabled. It is not necessary for the link being |
| 855 | * queried to be a seen-link. |
| 856 | * |
| 857 | * @param link the infrastructure link being queried |
| 858 | * @return true if a seen-link exists that is up, and shares the |
| 859 | * same src and dst switches as the link being queried |
| 860 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 861 | private boolean isParallelLink(Link link) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 862 | for (Entry<Link, Boolean> seen : seenLinks.entrySet()) { |
| 863 | Link seenLink = seen.getKey(); |
| 864 | if (seenLink.equals(link)) { |
| 865 | continue; |
| 866 | } |
| 867 | if (seenLink.src().deviceId().equals(link.src().deviceId()) && |
| 868 | seenLink.dst().deviceId().equals(link.dst().deviceId()) && |
| 869 | seen.getValue()) { |
| 870 | return true; |
| 871 | } |
| 872 | } |
| 873 | return false; |
| 874 | } |
| 875 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 876 | /** |
| 877 | * Returns true if the link being queried is a bidirectional link. A bidi |
| 878 | * link is defined as a link, whose reverse link - ie. the link in the reverse |
| 879 | * direction - has been seen-before and is up. It is not necessary for the link |
| 880 | * being queried to be a seen-link. |
| 881 | * |
| 882 | * @param link the infrastructure link being queried |
| 883 | * @return true if another unidirectional link exists in the reverse direction, |
| 884 | * has been seen-before and is up |
| 885 | */ |
| 886 | public boolean isBidirectional(Link link) { |
| 887 | Link reverseLink = linkService.getLink(link.dst(), link.src()); |
| 888 | if (reverseLink == null) { |
| 889 | return false; |
| 890 | } |
| 891 | Boolean result = isSeenLinkUp(reverseLink); |
| 892 | if (result == null) { |
| 893 | return false; |
| 894 | } |
| 895 | return result.booleanValue(); |
| 896 | } |
| 897 | |
| 898 | /** |
| 899 | * Determines if the given link should be avoided in routing calculations |
| 900 | * by policy or design. |
| 901 | * |
| 902 | * @param link the infrastructure link being queried |
| 903 | * @return true if link should be avoided |
| 904 | */ |
| 905 | public boolean avoidLink(Link link) { |
| 906 | // XXX currently only avoids all pair-links. In the future can be |
| 907 | // extended to avoid any generic link |
| 908 | DeviceId src = link.src().deviceId(); |
| 909 | PortNumber srcPort = link.src().port(); |
| 910 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(src)) { |
| 911 | log.warn("Device {} not configured..cannot avoid link {}", src, link); |
| 912 | return false; |
| 913 | } |
| 914 | DeviceId pairDev; |
| 915 | PortNumber pairLocalPort, pairRemotePort = null; |
| 916 | try { |
| 917 | pairDev = deviceConfiguration.getPairDeviceId(src); |
| 918 | pairLocalPort = deviceConfiguration.getPairLocalPort(src); |
| 919 | if (pairDev != null) { |
| 920 | pairRemotePort = deviceConfiguration.getPairLocalPort(pairDev); |
| 921 | } |
| 922 | } catch (DeviceConfigNotFoundException e) { |
| 923 | log.warn("Pair dev for dev {} not configured..cannot avoid link {}", |
| 924 | src, link); |
| 925 | return false; |
| 926 | } |
| 927 | |
| 928 | if (srcPort.equals(pairLocalPort) && |
| 929 | link.dst().deviceId().equals(pairDev) && |
| 930 | link.dst().port().equals(pairRemotePort)) { |
| 931 | return true; |
| 932 | } |
| 933 | return false; |
| 934 | } |
| 935 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 936 | private class InternalPacketProcessor implements PacketProcessor { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 937 | @Override |
| 938 | public void process(PacketContext context) { |
| 939 | |
| 940 | if (context.isHandled()) { |
| 941 | return; |
| 942 | } |
| 943 | |
| 944 | InboundPacket pkt = context.inPacket(); |
| 945 | Ethernet ethernet = pkt.parsed(); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 946 | |
| 947 | if (ethernet == null) { |
| 948 | return; |
| 949 | } |
| 950 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 951 | log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(), |
| 952 | ethernet); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 953 | if (ethernet.getEtherType() == TYPE_ARP) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 954 | log.warn("Received unexpected ARP packet on {}", |
| 955 | context.inPacket().receivedFrom()); |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 956 | log.trace("{}", ethernet); |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 957 | return; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 958 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) { |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 959 | IPv4 ipv4Packet = (IPv4) ethernet.getPayload(); |
| 960 | //ipHandler.addToPacketBuffer(ipv4Packet); |
| 961 | if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) { |
| 962 | icmpHandler.processIcmp(ethernet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 963 | } else { |
Charles Chan | d041ad8 | 2017-01-13 17:20:44 -0800 | [diff] [blame] | 964 | // NOTE: We don't support IP learning at this moment so this |
| 965 | // is not necessary. Also it causes duplication of DHCP packets. |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 966 | // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 967 | } |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 968 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) { |
| 969 | IPv6 ipv6Packet = (IPv6) ethernet.getPayload(); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 970 | //ipHandler.addToPacketBuffer(ipv6Packet); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 971 | // 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] | 972 | if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) { |
| 973 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
| 974 | if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST || |
| 975 | icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) { |
| 976 | icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom()); |
| 977 | } else { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 978 | log.trace("Received ICMPv6 0x{} - not handled", |
Charles Chan | d3727b7 | 2017-03-13 13:10:30 -0700 | [diff] [blame] | 979 | Integer.toHexString(icmp6Packet.getIcmpType() & 0xff)); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 980 | } |
| 981 | } else { |
| 982 | // NOTE: We don't support IP learning at this moment so this |
| 983 | // is not necessary. Also it causes duplication of DHCPv6 packets. |
| 984 | // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom()); |
| 985 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | private class InternalLinkListener implements LinkListener { |
| 991 | @Override |
| 992 | public void event(LinkEvent event) { |
Charles Chan | 0cff8aa | 2017-03-29 16:39:05 -0700 | [diff] [blame] | 993 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 994 | event.type() == LinkEvent.Type.LINK_UPDATED || |
| 995 | event.type() == LinkEvent.Type.LINK_REMOVED) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 996 | log.debug("Event {} received from Link Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 997 | scheduleEventHandlerIfNotScheduled(event); |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | private class InternalDeviceListener implements DeviceListener { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1003 | @Override |
| 1004 | public void event(DeviceEvent event) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1005 | switch (event.type()) { |
| 1006 | case DEVICE_ADDED: |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1007 | case PORT_UPDATED: |
| 1008 | case PORT_ADDED: |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 1009 | case DEVICE_UPDATED: |
| 1010 | case DEVICE_AVAILABILITY_CHANGED: |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1011 | log.trace("Event {} received from Device Service", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1012 | scheduleEventHandlerIfNotScheduled(event); |
| 1013 | break; |
| 1014 | default: |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1019 | @SuppressWarnings("rawtypes") |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1020 | private void scheduleEventHandlerIfNotScheduled(Event event) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1021 | synchronized (THREAD_SCHED_LOCK) { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1022 | eventQueue.add(event); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1023 | numOfEventsQueued++; |
| 1024 | |
| 1025 | if ((numOfHandlerScheduled - numOfHandlerExecution) == 0) { |
| 1026 | //No pending scheduled event handling threads. So start a new one. |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1027 | eventHandlerFuture = executorService |
| 1028 | .schedule(eventHandler, 100, TimeUnit.MILLISECONDS); |
| 1029 | numOfHandlerScheduled++; |
| 1030 | } |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 1031 | log.trace("numOfEventsQueued {}, numOfEventHandlerScheduled {}", |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1032 | numOfEventsQueued, |
| 1033 | numOfHandlerScheduled); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1034 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | private class InternalEventHandler implements Runnable { |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 1038 | @Override |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1039 | public void run() { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1040 | try { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1041 | while (true) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1042 | @SuppressWarnings("rawtypes") |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1043 | Event event; |
| 1044 | synchronized (THREAD_SCHED_LOCK) { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1045 | if (!eventQueue.isEmpty()) { |
| 1046 | event = eventQueue.poll(); |
| 1047 | numOfEventsExecuted++; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1048 | } else { |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1049 | numOfHandlerExecution++; |
| 1050 | log.debug("numOfHandlerExecution {} numOfEventsExecuted {}", |
| 1051 | numOfHandlerExecution, numOfEventsExecuted); |
| 1052 | break; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1053 | } |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 1054 | } |
Charles Chan | 0cff8aa | 2017-03-29 16:39:05 -0700 | [diff] [blame] | 1055 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 1056 | event.type() == LinkEvent.Type.LINK_UPDATED) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1057 | // Note: do not update seenLinks here, otherwise every |
| 1058 | // link, even one seen for the first time, will be appear |
| 1059 | // to be a previously seen link |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1060 | processLinkAdded((Link) event.subject()); |
| 1061 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 1062 | Link linkRemoved = (Link) event.subject(); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1063 | if (linkRemoved.type() == Link.Type.DIRECT) { |
| 1064 | updateSeenLink(linkRemoved, false); |
| 1065 | } |
| 1066 | // device availability check helps to ensure that |
| 1067 | // multiple link-removed events are actually treated as a |
| 1068 | // single switch removed event. purgeSeenLink is necessary |
| 1069 | // so we do rerouting (instead of rehashing) when switch |
| 1070 | // comes back. |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 1071 | if (linkRemoved.src().elementId() instanceof DeviceId && |
| 1072 | !deviceService.isAvailable(linkRemoved.src().deviceId())) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1073 | purgeSeenLink(linkRemoved); |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 1074 | continue; |
| 1075 | } |
| 1076 | if (linkRemoved.dst().elementId() instanceof DeviceId && |
| 1077 | !deviceService.isAvailable(linkRemoved.dst().deviceId())) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1078 | purgeSeenLink(linkRemoved); |
Pier Ventre | 6d59389 | 2016-09-13 21:33:40 -0700 | [diff] [blame] | 1079 | continue; |
| 1080 | } |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1081 | processLinkRemoved((Link) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1082 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 1083 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 1084 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
Saurav Das | 62af880 | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1085 | DeviceId deviceId = ((Device) event.subject()).id(); |
| 1086 | if (deviceService.isAvailable(deviceId)) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1087 | log.info("Processing device event {} for available device {}", |
| 1088 | event.type(), ((Device) event.subject()).id()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1089 | processDeviceAdded((Device) event.subject()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1090 | } else { |
| 1091 | log.info("Processing device event {} for unavailable device {}", |
| 1092 | event.type(), ((Device) event.subject()).id()); |
| 1093 | processDeviceRemoved((Device) event.subject()); |
| 1094 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1095 | } else if (event.type() == DeviceEvent.Type.PORT_ADDED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1096 | // typically these calls come when device is added first time |
| 1097 | // so port filtering rules are handled at the device_added event. |
| 1098 | // port added calls represent all ports on the device, |
| 1099 | // enabled or not. |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1100 | log.trace("** PORT ADDED {}/{} -> {}", |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1101 | ((DeviceEvent) event).subject().id(), |
| 1102 | ((DeviceEvent) event).port().number(), |
| 1103 | event.type()); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1104 | } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) { |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1105 | // these calls happen for every subsequent event |
| 1106 | // ports enabled, disabled, switch goes away, comes back |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1107 | log.info("** PORT UPDATED {}/{} -> {}", |
| 1108 | event.subject(), |
| 1109 | ((DeviceEvent) event).port(), |
| 1110 | event.type()); |
| 1111 | processPortUpdated(((Device) event.subject()), |
| 1112 | ((DeviceEvent) event).port()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1113 | } else { |
| 1114 | log.warn("Unhandled event type: {}", event.type()); |
| 1115 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1116 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1117 | } catch (Exception e) { |
| 1118 | log.error("SegmentRouting event handler " |
| 1119 | + "thread thrown an exception: {}", e); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1120 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1124 | private void processLinkAdded(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1125 | log.info("** LINK ADDED {}", link.toString()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1126 | if (link.type() != Link.Type.DIRECT) { |
| 1127 | // NOTE: A DIRECT link might be transiently marked as INDIRECT |
| 1128 | // if BDDP is received before LLDP. We can safely ignore that |
| 1129 | // until the LLDP is received and the link is marked as DIRECT. |
| 1130 | log.info("Ignore link {}->{}. Link type is {} instead of DIRECT.", |
| 1131 | link.src(), link.dst(), link.type()); |
| 1132 | return; |
| 1133 | } |
Saurav Das | fe0b05e | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1134 | if (!deviceConfiguration.isConfigured(link.src().deviceId())) { |
| 1135 | updateSeenLink(link, true); |
| 1136 | // XXX revisit - what about devicePortMap |
| 1137 | log.warn("Source device of this link is not configured.. " |
| 1138 | + "not processing further"); |
| 1139 | return; |
| 1140 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1141 | |
| 1142 | //Irrespective of whether the local is a MASTER or not for this device, |
| 1143 | //create group handler instance and push default TTP flow rules if needed, |
| 1144 | //as in a multi-instance setup, instances can initiate groups for any device. |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1145 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src() |
| 1146 | .deviceId()); |
| 1147 | if (groupHandler != null) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1148 | groupHandler.portUpForLink(link); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1149 | } else { |
Saurav Das | fe0b05e | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1150 | // XXX revisit/cleanup |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1151 | Device device = deviceService.getDevice(link.src().deviceId()); |
| 1152 | if (device != null) { |
| 1153 | log.warn("processLinkAdded: Link Added " |
| 1154 | + "Notification without Device Added " |
| 1155 | + "event, still handling it"); |
| 1156 | processDeviceAdded(device); |
| 1157 | groupHandler = groupHandlerMap.get(link.src() |
| 1158 | .deviceId()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1159 | groupHandler.portUpForLink(link); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 1162 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1163 | /*// process link only if it is bidirectional |
| 1164 | if (!isBidirectional(link)) { |
| 1165 | log.debug("Link not bidirectional.. waiting for other direction " |
| 1166 | + "src {} --> dst {} ", link.dst(), link.src()); |
| 1167 | // note that if we are not processing for routing, it should at least |
| 1168 | // be considered a seen-link |
| 1169 | updateSeenLink(link, true); |
| 1170 | return; |
| 1171 | } |
| 1172 | TO DO this ensure that rehash is still done correctly even if link is |
| 1173 | not processed for rerouting - perhaps rehash in both directions when |
| 1174 | it ultimately becomes bidi? |
| 1175 | */ |
| 1176 | |
| 1177 | log.debug("Starting optimized route population process for link " |
| 1178 | + "{} --> {}", link.src(), link.dst()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1179 | boolean seenBefore = isSeenLink(link); |
| 1180 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(null, link, null); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1181 | |
| 1182 | // It's possible that linkUp causes no route-path change as ECMP graph does |
| 1183 | // not change if the link is a parallel link (same src-dst as another link. |
| 1184 | // However we still need to update ECMP hash groups to include new buckets |
| 1185 | // for the link that has come up. |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1186 | if (mastershipService.isLocalMaster(link.src().deviceId())) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1187 | if (!seenBefore && isParallelLink(link)) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1188 | // if link seen first time, we need to ensure hash-groups have all ports |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1189 | log.debug("Attempting retryHash for paralled first-time link {}", link); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1190 | groupHandler.retryHash(link, false, true); |
| 1191 | } else { |
| 1192 | //seen before-link |
| 1193 | if (isParallelLink(link)) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1194 | log.debug("Attempting retryHash for paralled seen-before " |
| 1195 | + "link {}", link); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1196 | groupHandler.retryHash(link, false, false); |
| 1197 | } |
| 1198 | } |
| 1199 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1200 | |
| 1201 | mcastHandler.init(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | private void processLinkRemoved(Link link) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1205 | log.info("** LINK REMOVED {}", link.toString()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1206 | defaultRoutingHandler.populateRoutingRulesForLinkStatusChange(link, null, null); |
| 1207 | |
| 1208 | // update local groupHandler stores |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 1209 | DefaultGroupHandler groupHandler = groupHandlerMap.get(link.src().deviceId()); |
| 1210 | if (groupHandler != null) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1211 | if (mastershipService.isLocalMaster(link.src().deviceId()) && |
| 1212 | isParallelLink(link)) { |
Saurav Das | fe0b05e | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1213 | log.debug("* retrying hash for parallel link removed:{}", link); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1214 | groupHandler.retryHash(link, true, false); |
Saurav Das | fe0b05e | 2017-08-14 16:44:43 -0700 | [diff] [blame] | 1215 | } else { |
| 1216 | log.debug("Not attempting retry-hash for link removed: {} .. {}", link, |
| 1217 | (mastershipService.isLocalMaster(link.src().deviceId())) |
| 1218 | ? "not parallel" : "not master"); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1219 | } |
| 1220 | // ensure local stores are updated |
| 1221 | groupHandler.portDown(link.src().port()); |
| 1222 | } else { |
| 1223 | log.warn("group handler not found for dev:{} when removing link: {}", |
| 1224 | link.src().deviceId(), link); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 1225 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1226 | |
| 1227 | mcastHandler.processLinkDown(link); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | private void processDeviceAdded(Device device) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1231 | log.info("** DEVICE ADDED with ID {}", device.id()); |
Charles Chan | 9bd6aea | 2017-06-27 18:48:32 -0700 | [diff] [blame] | 1232 | |
| 1233 | // NOTE: Punt ARP/NDP even when the device is not configured. |
| 1234 | // Host learning without network config is required for CORD config generator. |
| 1235 | routingRulePopulator.populateIpPunts(device.id()); |
| 1236 | routingRulePopulator.populateArpNdpPunts(device.id()); |
| 1237 | |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1238 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1239 | log.warn("Device configuration unavailable. Device {} will be " |
| 1240 | + "processed after configuration.", device.id()); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1241 | return; |
| 1242 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1243 | processDeviceAddedInternal(device.id()); |
| 1244 | } |
| 1245 | |
| 1246 | private void processDeviceAddedInternal(DeviceId deviceId) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1247 | // Irrespective of whether the local is a MASTER or not for this device, |
| 1248 | // we need to create a SR-group-handler instance. This is because in a |
| 1249 | // multi-instance setup, any instance can initiate forwarding/next-objectives |
| 1250 | // for any switch (even if this instance is a SLAVE or not even connected |
| 1251 | // to the switch). To handle this, a default-group-handler instance is necessary |
| 1252 | // per switch. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1253 | log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet()); |
| 1254 | if (groupHandlerMap.get(deviceId) == null) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1255 | DefaultGroupHandler groupHandler; |
| 1256 | try { |
| 1257 | groupHandler = DefaultGroupHandler. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1258 | createGroupHandler(deviceId, |
| 1259 | appId, |
| 1260 | deviceConfiguration, |
| 1261 | linkService, |
| 1262 | flowObjectiveService, |
| 1263 | this); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1264 | } catch (DeviceConfigNotFoundException e) { |
| 1265 | log.warn(e.getMessage() + " Aborting processDeviceAdded."); |
| 1266 | return; |
| 1267 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1268 | log.debug("updating groupHandlerMap with new config for device: {}", |
| 1269 | deviceId); |
| 1270 | groupHandlerMap.put(deviceId, groupHandler); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1271 | } |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1272 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1273 | if (mastershipService.isLocalMaster(deviceId)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1274 | defaultRoutingHandler.populatePortAddressingRules(deviceId); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1275 | hostHandler.init(deviceId); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1276 | xConnectHandler.init(deviceId); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1277 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1278 | groupHandler.createGroupsFromVlanConfig(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1279 | routingRulePopulator.populateSubnetBroadcastRule(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1280 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1281 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1282 | appCfgHandler.init(deviceId); |
| 1283 | routeHandler.init(deviceId); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1286 | private void processDeviceRemoved(Device device) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1287 | dsNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1288 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 1289 | .forEach(entry -> { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1290 | dsNextObjStore.remove(entry.getKey()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1291 | }); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1292 | vlanNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1293 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1294 | .forEach(entry -> vlanNextObjStore.remove(entry.getKey())); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1295 | portNextObjStore.entrySet().stream() |
| 1296 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1297 | .forEach(entry -> portNextObjStore.remove(entry.getKey())); |
Charles Chan | 17d75d8 | 2017-06-15 00:44:51 -0700 | [diff] [blame] | 1298 | |
| 1299 | seenLinks.keySet().removeIf(key -> key.src().deviceId().equals(device.id()) || |
| 1300 | key.dst().deviceId().equals(device.id())); |
| 1301 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1302 | DefaultGroupHandler gh = groupHandlerMap.remove(device.id()); |
| 1303 | if (gh != null) { |
| 1304 | gh.shutdown(); |
| 1305 | } |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1306 | defaultRoutingHandler.purgeEcmpGraph(device.id()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1307 | // Note that a switch going down is associated with all of its links |
| 1308 | // going down as well, but it is treated as a single switch down event |
| 1309 | // while the link-downs are ignored. |
| 1310 | defaultRoutingHandler |
| 1311 | .populateRoutingRulesForLinkStatusChange(null, null, device.id()); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1312 | mcastHandler.removeDevice(device.id()); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1313 | xConnectHandler.removeDevice(device.id()); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1316 | private void processPortUpdated(Device device, Port port) { |
| 1317 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
| 1318 | log.warn("Device configuration uploading. Not handling port event for" |
| 1319 | + "dev: {} port: {}", device.id(), port.number()); |
| 1320 | return; |
| 1321 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1322 | |
| 1323 | if (!mastershipService.isLocalMaster(device.id())) { |
| 1324 | log.debug("Not master for dev:{} .. not handling port updated event" |
| 1325 | + "for port {}", device.id(), port.number()); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | // first we handle filtering rules associated with the port |
| 1330 | if (port.isEnabled()) { |
| 1331 | log.info("Switchport {}/{} enabled..programming filters", |
| 1332 | device.id(), port.number()); |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1333 | routingRulePopulator.processSinglePortFilters(device.id(), port.number(), true); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1334 | } else { |
| 1335 | log.info("Switchport {}/{} disabled..removing filters", |
| 1336 | device.id(), port.number()); |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1337 | routingRulePopulator.processSinglePortFilters(device.id(), port.number(), false); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1338 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1339 | |
| 1340 | // portUpdated calls are for ports that have gone down or up. For switch |
| 1341 | // to switch ports, link-events should take care of any re-routing or |
| 1342 | // group editing necessary for port up/down. Here we only process edge ports |
| 1343 | // that are already configured. |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1344 | ConnectPoint cp = new ConnectPoint(device.id(), port.number()); |
| 1345 | VlanId untaggedVlan = getUntaggedVlanId(cp); |
| 1346 | VlanId nativeVlan = getNativeVlanId(cp); |
| 1347 | Set<VlanId> taggedVlans = getTaggedVlanId(cp); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1348 | |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1349 | if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1350 | log.debug("Not handling port updated event for non-edge port (unconfigured) " |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1351 | + "dev/port: {}/{}", device.id(), port.number()); |
| 1352 | return; |
| 1353 | } |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1354 | if (untaggedVlan != null) { |
| 1355 | processEdgePort(device, port, untaggedVlan, true); |
| 1356 | } |
| 1357 | if (nativeVlan != null) { |
| 1358 | processEdgePort(device, port, nativeVlan, true); |
| 1359 | } |
| 1360 | if (!taggedVlans.isEmpty()) { |
| 1361 | taggedVlans.forEach(tag -> processEdgePort(device, port, tag, false)); |
| 1362 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1365 | private void processEdgePort(Device device, Port port, VlanId vlanId, |
| 1366 | boolean popVlan) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1367 | boolean portUp = port.isEnabled(); |
| 1368 | if (portUp) { |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1369 | log.info("Device:EdgePort {}:{} is enabled in vlan: {}", device.id(), |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1370 | port.number(), vlanId); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1371 | } else { |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1372 | log.info("Device:EdgePort {}:{} is disabled in vlan: {}", device.id(), |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1373 | port.number(), vlanId); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 1376 | DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1377 | if (groupHandler != null) { |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1378 | groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1379 | } else { |
| 1380 | log.warn("Group handler not found for dev:{}. Not handling edge port" |
| 1381 | + " {} event for port:{}", device.id(), |
| 1382 | (portUp) ? "UP" : "DOWN", port.number()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1385 | |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1386 | /** |
| 1387 | * Registers the given connect point with the NRS, this is necessary |
| 1388 | * to receive the NDP and ARP packets from the NRS. |
| 1389 | * |
| 1390 | * @param portToRegister connect point to register |
| 1391 | */ |
| 1392 | public void registerConnectPoint(ConnectPoint portToRegister) { |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 1393 | neighbourResolutionService.registerNeighbourHandler( |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1394 | portToRegister, |
| 1395 | neighbourHandler, |
| 1396 | appId |
| 1397 | ); |
| 1398 | } |
| 1399 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1400 | private class InternalConfigListener implements NetworkConfigListener { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1401 | private static final long PROGRAM_DELAY = 2; |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1402 | SegmentRoutingManager srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1403 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1404 | /** |
| 1405 | * Constructs the internal network config listener. |
| 1406 | * |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1407 | * @param srManager segment routing manager |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1408 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1409 | InternalConfigListener(SegmentRoutingManager srManager) { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1410 | this.srManager = srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1413 | /** |
| 1414 | * Reads network config and initializes related data structure accordingly. |
| 1415 | */ |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1416 | public void configureNetwork() { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1417 | if (deviceConfiguration == null) { |
| 1418 | deviceConfiguration = new DeviceConfiguration(srManager); |
| 1419 | } else { |
| 1420 | deviceConfiguration.updateConfig(); |
| 1421 | } |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1422 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1423 | arpHandler = new ArpHandler(srManager); |
| 1424 | icmpHandler = new IcmpHandler(srManager); |
| 1425 | ipHandler = new IpHandler(srManager); |
| 1426 | routingRulePopulator = new RoutingRulePopulator(srManager); |
| 1427 | defaultRoutingHandler = new DefaultRoutingHandler(srManager); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1428 | |
| 1429 | tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
| 1430 | groupHandlerMap, tunnelStore); |
| 1431 | policyHandler = new PolicyHandler(appId, deviceConfiguration, |
| 1432 | flowObjectiveService, |
| 1433 | tunnelHandler, policyStore); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1434 | // add a small delay to absorb multiple network config added notifications |
| 1435 | if (!programmingScheduled.get()) { |
| 1436 | programmingScheduled.set(true); |
| 1437 | executorService.schedule(new ConfigChange(), PROGRAM_DELAY, |
| 1438 | TimeUnit.SECONDS); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1439 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1440 | mcastHandler.init(); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1443 | @Override |
| 1444 | public void event(NetworkConfigEvent event) { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1445 | // TODO move this part to NetworkConfigEventHandler |
| 1446 | if (event.configClass().equals(SegmentRoutingDeviceConfig.class)) { |
| 1447 | switch (event.type()) { |
| 1448 | case CONFIG_ADDED: |
Charles Chan | 68363b1 | 2017-06-26 15:25:09 -0700 | [diff] [blame] | 1449 | log.info("Segment Routing Device Config added for {}", event.subject()); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1450 | configureNetwork(); |
| 1451 | break; |
| 1452 | case CONFIG_UPDATED: |
Charles Chan | 68363b1 | 2017-06-26 15:25:09 -0700 | [diff] [blame] | 1453 | log.info("Segment Routing Config updated for {}", event.subject()); |
| 1454 | // TODO support dynamic configuration |
| 1455 | break; |
| 1456 | default: |
| 1457 | break; |
| 1458 | } |
| 1459 | } else if (event.configClass().equals(InterfaceConfig.class)) { |
| 1460 | switch (event.type()) { |
| 1461 | case CONFIG_ADDED: |
| 1462 | log.info("Interface Config added for {}", event.subject()); |
| 1463 | configureNetwork(); |
| 1464 | break; |
| 1465 | case CONFIG_UPDATED: |
| 1466 | log.info("Interface Config updated for {}", event.subject()); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1467 | // TODO support dynamic configuration |
| 1468 | break; |
| 1469 | default: |
| 1470 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1471 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1472 | } else if (event.configClass().equals(SegmentRoutingAppConfig.class)) { |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1473 | checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized"); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1474 | switch (event.type()) { |
| 1475 | case CONFIG_ADDED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1476 | appCfgHandler.processAppConfigAdded(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1477 | break; |
| 1478 | case CONFIG_UPDATED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1479 | appCfgHandler.processAppConfigUpdated(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1480 | break; |
| 1481 | case CONFIG_REMOVED: |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1482 | appCfgHandler.processAppConfigRemoved(event); |
| 1483 | break; |
| 1484 | default: |
| 1485 | break; |
| 1486 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1487 | configureNetwork(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1488 | } else if (event.configClass().equals(XConnectConfig.class)) { |
| 1489 | checkState(xConnectHandler != null, "XConnectHandler is not initialized"); |
| 1490 | switch (event.type()) { |
| 1491 | case CONFIG_ADDED: |
| 1492 | xConnectHandler.processXConnectConfigAdded(event); |
| 1493 | break; |
| 1494 | case CONFIG_UPDATED: |
| 1495 | xConnectHandler.processXConnectConfigUpdated(event); |
| 1496 | break; |
| 1497 | case CONFIG_REMOVED: |
| 1498 | xConnectHandler.processXConnectConfigRemoved(event); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1499 | break; |
| 1500 | default: |
| 1501 | break; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 1502 | } |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 1503 | } else if (event.configClass().equals(PwaasConfig.class)) { |
| 1504 | checkState(l2TunnelHandler != null, "L2TunnelHandler is not initialized"); |
| 1505 | switch (event.type()) { |
| 1506 | case CONFIG_ADDED: |
| 1507 | l2TunnelHandler.processPwaasConfigAdded(event); |
| 1508 | break; |
| 1509 | case CONFIG_UPDATED: |
| 1510 | l2TunnelHandler.processPwaasConfigUpdated(event); |
| 1511 | break; |
| 1512 | case CONFIG_REMOVED: |
| 1513 | l2TunnelHandler.processPwaasConfigRemoved(event); |
| 1514 | break; |
| 1515 | default: |
| 1516 | break; |
| 1517 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1518 | } |
| 1519 | } |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1520 | |
| 1521 | private final class ConfigChange implements Runnable { |
| 1522 | @Override |
| 1523 | public void run() { |
| 1524 | programmingScheduled.set(false); |
| 1525 | for (Device device : deviceService.getDevices()) { |
| 1526 | processDeviceAdded(device); |
| 1527 | } |
| 1528 | defaultRoutingHandler.startPopulationProcess(); |
| 1529 | } |
| 1530 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1531 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1532 | |
| 1533 | private class InternalHostListener implements HostListener { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1534 | @Override |
| 1535 | public void event(HostEvent event) { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1536 | switch (event.type()) { |
| 1537 | case HOST_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1538 | hostHandler.processHostAddedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1539 | break; |
| 1540 | case HOST_MOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1541 | hostHandler.processHostMovedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1542 | break; |
| 1543 | case HOST_REMOVED: |
Charles Chan | d9265a3 | 2017-06-16 15:19:24 -0700 | [diff] [blame] | 1544 | hostHandler.processHostRemovedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1545 | break; |
| 1546 | case HOST_UPDATED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1547 | hostHandler.processHostUpdatedEvent(event); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1548 | break; |
| 1549 | default: |
| 1550 | log.warn("Unsupported host event type: {}", event.type()); |
| 1551 | break; |
| 1552 | } |
| 1553 | } |
| 1554 | } |
| 1555 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1556 | private class InternalMcastListener implements McastListener { |
| 1557 | @Override |
| 1558 | public void event(McastEvent event) { |
| 1559 | switch (event.type()) { |
| 1560 | case SOURCE_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1561 | mcastHandler.processSourceAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1562 | break; |
| 1563 | case SINK_ADDED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1564 | mcastHandler.processSinkAdded(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | case SINK_REMOVED: |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 1567 | mcastHandler.processSinkRemoved(event); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1568 | break; |
| 1569 | case ROUTE_ADDED: |
| 1570 | case ROUTE_REMOVED: |
| 1571 | default: |
| 1572 | break; |
| 1573 | } |
| 1574 | } |
| 1575 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 1576 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1577 | private class InternalRouteEventListener implements RouteListener { |
| 1578 | @Override |
| 1579 | public void event(RouteEvent event) { |
| 1580 | switch (event.type()) { |
| 1581 | case ROUTE_ADDED: |
| 1582 | routeHandler.processRouteAdded(event); |
| 1583 | break; |
| 1584 | case ROUTE_UPDATED: |
| 1585 | routeHandler.processRouteUpdated(event); |
| 1586 | break; |
| 1587 | case ROUTE_REMOVED: |
| 1588 | routeHandler.processRouteRemoved(event); |
| 1589 | break; |
| 1590 | default: |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1595 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1596 | } |