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