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