blob: 78bb928fc8c2fbb3c1827911396b60dcac461a90 [file] [log] [blame]
sangho80f11cb2015-04-01 13:05:26 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
sangho80f11cb2015-04-01 13:05:26 -07003 *
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 */
16package org.onosproject.segmentrouting;
17
Jonathan Hart61e24e12017-11-30 18:23:42 -080018import com.google.common.collect.HashMultimap;
19import com.google.common.collect.ImmutableMap;
pierventrec80a5052021-05-20 12:56:38 +020020import com.google.common.collect.Lists;
Jonathan Hart61e24e12017-11-30 18:23:42 -080021import com.google.common.collect.Maps;
22import com.google.common.collect.Multimap;
Charles Chanf0ae41e2017-08-23 13:55:39 -070023import com.google.common.collect.Sets;
sangho80f11cb2015-04-01 13:05:26 -070024import org.onlab.packet.Ethernet;
Pier Ventreb6b81d52016-12-02 08:16:05 -080025import org.onlab.packet.ICMP6;
Charles Chan77277672015-10-20 16:24:19 -070026import org.onlab.packet.IPv4;
Pier Ventreb6a7f342016-11-26 21:05:22 -080027import org.onlab.packet.IPv6;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070028import org.onlab.packet.IpAddress;
Charles Chan77277672015-10-20 16:24:19 -070029import org.onlab.packet.IpPrefix;
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +000030import org.onlab.packet.MacAddress;
Carmelo Cascone61004262020-01-16 13:36:02 -080031import org.onlab.packet.VlanId;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -070032import org.onlab.util.KryoNamespace;
Charles Chan873661e2017-11-30 15:37:50 -080033import org.onlab.util.Tools;
Saurav Dasc3604f12016-03-23 11:22:49 -070034import org.onosproject.cfg.ComponentConfigService;
Saurav Das00e553b2018-04-21 17:19:48 -070035import org.onosproject.cluster.ClusterEvent;
36import org.onosproject.cluster.ClusterEventListener;
Pier Luigi580fd8a2018-01-16 10:47:50 +010037import org.onosproject.cluster.ClusterService;
Pierdb27b8d2018-04-17 16:29:56 +020038import org.onosproject.cluster.NodeId;
sangho80f11cb2015-04-01 13:05:26 -070039import org.onosproject.core.ApplicationId;
40import org.onosproject.core.CoreService;
41import org.onosproject.event.Event;
Charles Chanfbcb8812018-04-18 18:41:05 -070042import org.onosproject.mastership.MastershipEvent;
43import org.onosproject.mastership.MastershipListener;
Jonathan Hart54541d12016-04-12 15:39:44 -070044import org.onosproject.mastership.MastershipService;
Pier1f87aca2018-03-14 16:47:32 -070045import org.onosproject.mcast.api.McastEvent;
46import org.onosproject.mcast.api.McastListener;
47import org.onosproject.mcast.api.MulticastRouteService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080048import org.onosproject.net.ConnectPoint;
Jonathan Hart54541d12016-04-12 15:39:44 -070049import org.onosproject.net.Device;
50import org.onosproject.net.DeviceId;
Charles Chanf0ae41e2017-08-23 13:55:39 -070051import org.onosproject.net.Host;
52import org.onosproject.net.HostId;
Jonathan Hart54541d12016-04-12 15:39:44 -070053import org.onosproject.net.Link;
54import org.onosproject.net.Port;
Charles Chanf4586112015-11-09 16:37:23 -080055import org.onosproject.net.PortNumber;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070056import org.onosproject.net.config.ConfigException;
Charles Chan72f556a2015-10-05 17:50:33 -070057import org.onosproject.net.config.ConfigFactory;
58import org.onosproject.net.config.NetworkConfigEvent;
Charles Chan72f556a2015-10-05 17:50:33 -070059import org.onosproject.net.config.NetworkConfigListener;
Jonathan Hart54541d12016-04-12 15:39:44 -070060import org.onosproject.net.config.NetworkConfigRegistry;
Ray Milkeyae0068a2017-08-15 11:02:29 -070061import org.onosproject.net.config.basics.InterfaceConfig;
62import org.onosproject.net.config.basics.McastConfig;
Charles Chan72f556a2015-10-05 17:50:33 -070063import org.onosproject.net.config.basics.SubjectFactories;
Saurav Dase6c448a2018-01-18 12:07:33 -080064import org.onosproject.net.device.DeviceAdminService;
Jonathan Hart54541d12016-04-12 15:39:44 -070065import org.onosproject.net.device.DeviceEvent;
66import org.onosproject.net.device.DeviceListener;
67import org.onosproject.net.device.DeviceService;
Charles Chanf4586112015-11-09 16:37:23 -080068import org.onosproject.net.flow.TrafficSelector;
69import org.onosproject.net.flow.TrafficTreatment;
Jonathan Hart54541d12016-04-12 15:39:44 -070070import org.onosproject.net.flowobjective.FlowObjectiveService;
Charles Chan0b1dd7e2018-08-19 19:21:46 -070071import org.onosproject.net.flowobjective.NextObjective;
Charles Chanf4586112015-11-09 16:37:23 -080072import org.onosproject.net.host.HostEvent;
73import org.onosproject.net.host.HostListener;
Charles Chanc6bcdf92018-06-01 16:33:48 -070074import org.onosproject.net.host.HostProbingService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080075import org.onosproject.net.host.HostService;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -070076import org.onosproject.net.host.InterfaceIpAddress;
Pierdb27b8d2018-04-17 16:29:56 +020077import org.onosproject.net.intent.WorkPartitionService;
Ray Milkeyae0068a2017-08-15 11:02:29 -070078import org.onosproject.net.intf.Interface;
79import org.onosproject.net.intf.InterfaceService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080080import org.onosproject.net.link.LinkEvent;
81import org.onosproject.net.link.LinkListener;
82import org.onosproject.net.link.LinkService;
Ray Milkeyae0068a2017-08-15 11:02:29 -070083import org.onosproject.net.neighbour.NeighbourResolutionService;
Pier Ventreb6a7f342016-11-26 21:05:22 -080084import org.onosproject.net.packet.InboundPacket;
85import org.onosproject.net.packet.PacketContext;
86import org.onosproject.net.packet.PacketProcessor;
87import org.onosproject.net.packet.PacketService;
Pier Luigid8a15162018-02-15 16:33:08 +010088import org.onosproject.net.topology.TopologyEvent;
89import org.onosproject.net.topology.TopologyListener;
Charles Chanc91c8782016-03-30 17:54:24 -070090import org.onosproject.net.topology.TopologyService;
Charles Chanf0ae41e2017-08-23 13:55:39 -070091import org.onosproject.routeservice.ResolvedRoute;
Ray Milkeyae0068a2017-08-15 11:02:29 -070092import org.onosproject.routeservice.RouteEvent;
93import org.onosproject.routeservice.RouteListener;
94import org.onosproject.routeservice.RouteService;
Charles Chanc91c8782016-03-30 17:54:24 -070095import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
Pier Ventre6b19e482016-11-07 16:21:04 -080096import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig;
Ray Milkeyae0068a2017-08-15 11:02:29 -070097import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig;
Charles Chanc91c8782016-03-30 17:54:24 -070098import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler;
Saurav Das261c3002017-06-13 15:35:54 -070099import org.onosproject.segmentrouting.grouphandler.DestinationSet;
100import org.onosproject.segmentrouting.grouphandler.NextNeighbors;
Harshada Chaundkar9204f312019-07-02 16:01:24 +0000101import org.onosproject.segmentrouting.mcast.McastFilteringObjStoreKey;
Pier Luigi69f774d2018-02-28 12:10:50 +0100102import org.onosproject.segmentrouting.mcast.McastHandler;
103import org.onosproject.segmentrouting.mcast.McastRole;
Piere99511d2018-04-19 16:47:06 +0200104import org.onosproject.segmentrouting.mcast.McastRoleStoreKey;
Ray Milkey2bd24a92018-08-17 14:54:17 -0700105import org.onosproject.segmentrouting.mcast.McastStoreKey;
pierventre37f18d02022-05-12 22:18:20 +0200106import org.onosproject.segmentrouting.phasedrecovery.api.Phase;
Charles Chan12a8a842020-02-14 13:23:57 -0800107import org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700108import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel;
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700109import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800110import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler;
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700111import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800112import org.onosproject.segmentrouting.pwaas.L2Tunnel;
Ray Milkey2bd24a92018-08-17 14:54:17 -0700113import org.onosproject.segmentrouting.pwaas.L2TunnelDescription;
Ray Milkeyae0068a2017-08-15 11:02:29 -0700114import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800115import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy;
Saurav Das261c3002017-06-13 15:35:54 -0700116import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
Carmelo Cascone61004262020-01-16 13:36:02 -0800117import org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey;
Charles Chan1eaf4802016-04-18 13:44:03 -0700118import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
Charles Chan10b0fb72017-02-02 16:20:42 -0800119import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
Charles Chan82f19972016-05-17 13:13:55 -0700120import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
Charles Chan8d316332018-06-19 20:31:57 -0700121import org.onosproject.segmentrouting.xconnect.api.XconnectService;
Jonathan Hart54541d12016-04-12 15:39:44 -0700122import org.onosproject.store.serializers.KryoNamespaces;
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700123import org.onosproject.store.service.EventuallyConsistentMap;
124import org.onosproject.store.service.EventuallyConsistentMapBuilder;
125import org.onosproject.store.service.StorageService;
126import org.onosproject.store.service.WallClockTimestamp;
Charles Chan873661e2017-11-30 15:37:50 -0800127import org.osgi.service.component.ComponentContext;
Ray Milkey2bd24a92018-08-17 14:54:17 -0700128import org.osgi.service.component.annotations.Activate;
129import org.osgi.service.component.annotations.Component;
130import org.osgi.service.component.annotations.Deactivate;
131import org.osgi.service.component.annotations.Modified;
132import org.osgi.service.component.annotations.Reference;
133import org.osgi.service.component.annotations.ReferenceCardinality;
Charles Chanb4f9cd12019-02-27 11:46:32 -0800134import org.osgi.service.component.annotations.ReferencePolicy;
sangho80f11cb2015-04-01 13:05:26 -0700135import org.slf4j.Logger;
136import org.slf4j.LoggerFactory;
137
Saurav Das00e553b2018-04-21 17:19:48 -0700138import java.time.Instant;
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700139import java.util.ArrayList;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800140import java.util.Collections;
Charles Chan873661e2017-11-30 15:37:50 -0800141import java.util.Dictionary;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800142import java.util.HashSet;
143import java.util.List;
144import java.util.Map;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800145import java.util.Optional;
146import java.util.Set;
Andrea Campanella060cad82018-04-17 12:09:34 +0200147import java.util.concurrent.CompletableFuture;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800148import java.util.concurrent.ConcurrentHashMap;
Andrea Campanella060cad82018-04-17 12:09:34 +0200149import java.util.concurrent.CopyOnWriteArrayList;
pierventrea3989be2021-01-08 16:43:17 +0100150import java.util.concurrent.ExecutionException;
Charles Chan77cdde42018-05-08 21:35:50 -0700151import java.util.concurrent.ExecutorService;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800152import java.util.concurrent.Executors;
153import java.util.concurrent.ScheduledExecutorService;
pierventrea3989be2021-01-08 16:43:17 +0100154import java.util.concurrent.ScheduledFuture;
Jonathan Hart61e24e12017-11-30 18:23:42 -0800155import java.util.concurrent.TimeUnit;
156import java.util.concurrent.atomic.AtomicBoolean;
157import java.util.stream.Collectors;
sangho80f11cb2015-04-01 13:05:26 -0700158
Charles Chand6d25332016-02-26 22:19:52 -0800159import static com.google.common.base.Preconditions.checkState;
Pier Ventreadb4ae62016-11-23 09:57:42 -0800160import static org.onlab.packet.Ethernet.TYPE_ARP;
Yuta HIGUCHIebee2f12016-07-21 16:54:33 -0700161import static org.onlab.util.Tools.groupedThreads;
Saurav Dase321cff2018-02-09 17:26:45 -0800162import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REGISTERED;
163import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UNREGISTERED;
Ray Milkey05edbfc2018-10-23 14:23:16 -0700164import static org.onosproject.segmentrouting.OsgiPropertyConstants.ACTIVE_PROBING_DEFAULT;
165import static org.onosproject.segmentrouting.OsgiPropertyConstants.DEFAULT_INTERNAL_VLAN_DEFAULT;
166import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ACTIVE_PROBING;
167import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_DEFAULT_INTERNAL_VLAN;
168import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_PW_TRANSPORT_VLAN;
169import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_RESPOND_TO_UNKNOWN_HOSTS;
170import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ROUTE_DOUBLE_TAGGED_HOSTS;
psneha86e60d32019-03-26 06:31:41 -0400171import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ROUTE_SIMPLIFICATION;
Ray Milkey05edbfc2018-10-23 14:23:16 -0700172import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_SINGLE_HOMED_DOWN;
Ray Milkeye96d0de2018-11-02 17:12:21 -0700173import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_SYMMETRIC_PROBING;
Ray Milkey05edbfc2018-10-23 14:23:16 -0700174import static org.onosproject.segmentrouting.OsgiPropertyConstants.PW_TRANSPORT_VLAN_DEFAULT;
175import static org.onosproject.segmentrouting.OsgiPropertyConstants.RESPOND_TO_UNKNOWN_HOSTS_DEFAULT;
176import static org.onosproject.segmentrouting.OsgiPropertyConstants.ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT;
psneha86e60d32019-03-26 06:31:41 -0400177import static org.onosproject.segmentrouting.OsgiPropertyConstants.ROUTE_SIMPLIFICATION_DEFAULT;
Ray Milkey05edbfc2018-10-23 14:23:16 -0700178import static org.onosproject.segmentrouting.OsgiPropertyConstants.SINGLE_HOMED_DOWN_DEFAULT;
Ray Milkeye96d0de2018-11-02 17:12:21 -0700179import static org.onosproject.segmentrouting.OsgiPropertyConstants.SYMMETRIC_PROBING_DEFAULT;
Charles Chand6d25332016-02-26 22:19:52 -0800180
Charles Chanb7f75ac2016-01-11 18:28:54 -0800181/**
182 * Segment routing manager.
183 */
Ray Milkey05edbfc2018-10-23 14:23:16 -0700184@Component(
185 immediate = true,
186 service = SegmentRoutingService.class,
187 property = {
188 PROP_ACTIVE_PROBING + ":Boolean=" + ACTIVE_PROBING_DEFAULT,
189 PROP_SINGLE_HOMED_DOWN + ":Boolean=" + SINGLE_HOMED_DOWN_DEFAULT,
190 PROP_RESPOND_TO_UNKNOWN_HOSTS + ":Boolean=" + RESPOND_TO_UNKNOWN_HOSTS_DEFAULT,
191 PROP_ROUTE_DOUBLE_TAGGED_HOSTS + ":Boolean=" + ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT,
192 PROP_DEFAULT_INTERNAL_VLAN + ":Integer=" + DEFAULT_INTERNAL_VLAN_DEFAULT,
193 PROP_PW_TRANSPORT_VLAN + ":Integer=" + PW_TRANSPORT_VLAN_DEFAULT,
psneha86e60d32019-03-26 06:31:41 -0400194 PROP_SYMMETRIC_PROBING + ":Boolean=" + SYMMETRIC_PROBING_DEFAULT,
195 PROP_ROUTE_SIMPLIFICATION + ":Boolean=" + ROUTE_SIMPLIFICATION_DEFAULT
Ray Milkey05edbfc2018-10-23 14:23:16 -0700196 }
197)
sangho27462c62015-05-14 00:39:53 -0700198public class SegmentRoutingManager implements SegmentRoutingService {
sangho80f11cb2015-04-01 13:05:26 -0700199
Charles Chan46fdfaf2016-11-09 20:51:44 -0800200 private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class);
sangho80f11cb2015-04-01 13:05:26 -0700201
Ray Milkey2bd24a92018-08-17 14:54:17 -0700202 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chandebfea32016-10-24 14:52:01 -0700203 private ComponentConfigService compCfgService;
sangho80f11cb2015-04-01 13:05:26 -0700204
Ray Milkey2bd24a92018-08-17 14:54:17 -0700205 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chancf789822019-03-22 10:04:27 -0700206 public NeighbourResolutionService neighbourResolutionService;
Pier Ventreb6a7f342016-11-26 21:05:22 -0800207
Ray Milkey2bd24a92018-08-17 14:54:17 -0700208 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100209 public CoreService coreService;
sangho80f11cb2015-04-01 13:05:26 -0700210
Ray Milkey2bd24a92018-08-17 14:54:17 -0700211 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chandebfea32016-10-24 14:52:01 -0700212 PacketService packetService;
sangho80f11cb2015-04-01 13:05:26 -0700213
Ray Milkey2bd24a92018-08-17 14:54:17 -0700214 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chandebfea32016-10-24 14:52:01 -0700215 HostService hostService;
sangho80f11cb2015-04-01 13:05:26 -0700216
Ray Milkey2bd24a92018-08-17 14:54:17 -0700217 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chanc6bcdf92018-06-01 16:33:48 -0700218 HostProbingService probingService;
Charles Chan873661e2017-11-30 15:37:50 -0800219
Ray Milkey2bd24a92018-08-17 14:54:17 -0700220 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100221 public DeviceService deviceService;
sangho80f11cb2015-04-01 13:05:26 -0700222
Ray Milkey2bd24a92018-08-17 14:54:17 -0700223 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Saurav Dase6c448a2018-01-18 12:07:33 -0800224 DeviceAdminService deviceAdminService;
225
Ray Milkey2bd24a92018-08-17 14:54:17 -0700226 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800227 public FlowObjectiveService flowObjectiveService;
sangho80f11cb2015-04-01 13:05:26 -0700228
Ray Milkey2bd24a92018-08-17 14:54:17 -0700229 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100230 public LinkService linkService;
sangho27462c62015-05-14 00:39:53 -0700231
Ray Milkey2bd24a92018-08-17 14:54:17 -0700232 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800233 public MastershipService mastershipService;
Charles Chandebfea32016-10-24 14:52:01 -0700234
Ray Milkey2bd24a92018-08-17 14:54:17 -0700235 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Ventref3cf5b92016-11-09 14:17:26 -0800236 public StorageService storageService;
Charles Chandebfea32016-10-24 14:52:01 -0700237
Ray Milkey2bd24a92018-08-17 14:54:17 -0700238 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Luigi69f774d2018-02-28 12:10:50 +0100239 public MulticastRouteService multicastRouteService;
Charles Chandebfea32016-10-24 14:52:01 -0700240
Ray Milkey2bd24a92018-08-17 14:54:17 -0700241 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chan83163812018-01-09 13:45:07 -0800242 public TopologyService topologyService;
Charles Chandebfea32016-10-24 14:52:01 -0700243
Ray Milkey2bd24a92018-08-17 14:54:17 -0700244 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chan19b70032019-04-17 14:20:26 -0700245 public RouteService routeService;
Charles Chan82ab1932016-01-30 23:22:37 -0800246
Ray Milkey2bd24a92018-08-17 14:54:17 -0700247 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chan46fdfaf2016-11-09 20:51:44 -0800248 public NetworkConfigRegistry cfgService;
Charles Chan82ab1932016-01-30 23:22:37 -0800249
Ray Milkey2bd24a92018-08-17 14:54:17 -0700250 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Charles Chan46fdfaf2016-11-09 20:51:44 -0800251 public InterfaceService interfaceService;
252
Ray Milkey2bd24a92018-08-17 14:54:17 -0700253 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pier Luigi580fd8a2018-01-16 10:47:50 +0100254 public ClusterService clusterService;
255
Ray Milkey2bd24a92018-08-17 14:54:17 -0700256 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Pierdb27b8d2018-04-17 16:29:56 +0200257 public WorkPartitionService workPartitionService;
Pier Luigi580fd8a2018-01-16 10:47:50 +0100258
Charles Chanb4f9cd12019-02-27 11:46:32 -0800259 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
Charles Chanb4f9cd12019-02-27 11:46:32 -0800260 policy = ReferencePolicy.DYNAMIC)
Carmelo Cascone61004262020-01-16 13:36:02 -0800261 public volatile XconnectService xconnectService;
Charles Chan8d316332018-06-19 20:31:57 -0700262
Charles Chan12a8a842020-02-14 13:23:57 -0800263 @Reference(cardinality = ReferenceCardinality.OPTIONAL,
264 policy = ReferencePolicy.DYNAMIC)
265 volatile PhasedRecoveryService phasedRecoveryService;
266
Ray Milkey05edbfc2018-10-23 14:23:16 -0700267 /** Enable active probing to discover dual-homed hosts. */
268 boolean activeProbing = ACTIVE_PROBING_DEFAULT;
Charles Chan873661e2017-11-30 15:37:50 -0800269
Ray Milkeye96d0de2018-11-02 17:12:21 -0700270 /** Enable only send probe on the same port number of the pair device. */
271 boolean symmetricProbing = SYMMETRIC_PROBING_DEFAULT;
Mayank Tiwarif7942402018-10-29 18:27:35 -0400272
Ray Milkey05edbfc2018-10-23 14:23:16 -0700273 /** Enable administratively taking down single-homed hosts. */
274 boolean singleHomedDown = SINGLE_HOMED_DOWN_DEFAULT;
Saurav Dasec683dc2018-04-27 18:42:30 -0700275
Ray Milkey05edbfc2018-10-23 14:23:16 -0700276 /** Enable this to respond to ARP/NDP requests from unknown hosts. */
277 boolean respondToUnknownHosts = RESPOND_TO_UNKNOWN_HOSTS_DEFAULT;
Andreas Pantelopoulos6464d862018-06-18 12:50:35 -0700278
Ray Milkey05edbfc2018-10-23 14:23:16 -0700279 /** Program flows and groups to pop and route double tagged hosts. */
280 boolean routeDoubleTaggedHosts = ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT;
Charles Chan4eb73bb2018-07-19 14:55:31 -0700281
Ray Milkey05edbfc2018-10-23 14:23:16 -0700282 /** internal vlan assigned by default to unconfigured ports. */
283 private int defaultInternalVlan = DEFAULT_INTERNAL_VLAN_DEFAULT;
Saurav Das9bf49582018-08-13 15:34:26 -0700284
Ray Milkey05edbfc2018-10-23 14:23:16 -0700285 /** vlan used for transport of pseudowires between switches. */
286 private int pwTransportVlan = PW_TRANSPORT_VLAN_DEFAULT;
Saurav Das9bf49582018-08-13 15:34:26 -0700287
psneha86e60d32019-03-26 06:31:41 -0400288 /** Enabling route simplification. */
289 boolean routeSimplification = ROUTE_SIMPLIFICATION_DEFAULT;
290
Charles Chandebfea32016-10-24 14:52:01 -0700291 ArpHandler arpHandler = null;
292 IcmpHandler icmpHandler = null;
293 IpHandler ipHandler = null;
294 RoutingRulePopulator routingRulePopulator = null;
Ray Milkeyb85de082017-04-05 09:42:04 -0700295 ApplicationId appId;
296 DeviceConfiguration deviceConfiguration = null;
sangho80f11cb2015-04-01 13:05:26 -0700297
Charles Chandebfea32016-10-24 14:52:01 -0700298 DefaultRoutingHandler defaultRoutingHandler = null;
sangho27462c62015-05-14 00:39:53 -0700299 private TunnelHandler tunnelHandler = null;
300 private PolicyHandler policyHandler = null;
Charles Chan2b078ae2015-10-14 11:24:40 -0700301 private InternalPacketProcessor processor = null;
302 private InternalLinkListener linkListener = null;
303 private InternalDeviceListener deviceListener = null;
Charles Chan82f19972016-05-17 13:13:55 -0700304 private AppConfigHandler appCfgHandler = null;
Saurav Dase6c448a2018-01-18 12:07:33 -0800305 McastHandler mcastHandler = null;
306 HostHandler hostHandler = null;
Pier Ventreb6a7f342016-11-26 21:05:22 -0800307 private RouteHandler routeHandler = null;
Saurav Dase6c448a2018-01-18 12:07:33 -0800308 LinkHandler linkHandler = null;
Pier Ventreb6b81d52016-12-02 08:16:05 -0800309 private SegmentRoutingNeighbourDispatcher neighbourHandler = null;
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800310 private DefaultL2TunnelHandler l2TunnelHandler = null;
Pier Luigid8a15162018-02-15 16:33:08 +0100311 private TopologyHandler topologyHandler = null;
Charles Chan82ab1932016-01-30 23:22:37 -0800312 private final InternalHostListener hostListener = new InternalHostListener();
Charles Chanc91c8782016-03-30 17:54:24 -0700313 private final InternalConfigListener cfgListener = new InternalConfigListener(this);
314 private final InternalMcastListener mcastListener = new InternalMcastListener();
Charles Chandebfea32016-10-24 14:52:01 -0700315 private final InternalRouteEventListener routeListener = new InternalRouteEventListener();
Pier Luigid8a15162018-02-15 16:33:08 +0100316 private final InternalTopologyListener topologyListener = new InternalTopologyListener();
Charles Chanfbcb8812018-04-18 18:41:05 -0700317 private final InternalMastershipListener mastershipListener = new InternalMastershipListener();
Saurav Das00e553b2018-04-21 17:19:48 -0700318 final InternalClusterListener clusterListener = new InternalClusterListener();
Andrea Campanella060cad82018-04-17 12:09:34 +0200319 //Completable future for network configuration process to buffer config events handling during activation
320 private CompletableFuture<Boolean> networkConfigCompletion = null;
Ray Milkey521e4392018-11-16 15:15:14 -0800321 private final Object networkConfigCompletionLock = new Object();
Charles Chan39b75522018-04-21 00:44:29 -0700322 private List<Event> queuedEvents = new CopyOnWriteArrayList<>();
sangho80f11cb2015-04-01 13:05:26 -0700323
Charles Chan52003922018-04-05 16:31:15 -0700324 // Handles device, link, topology and network config events
Charles Chanfbcb8812018-04-18 18:41:05 -0700325 private ScheduledExecutorService mainEventExecutor;
sangho80f11cb2015-04-01 13:05:26 -0700326
Charles Chanfbcb8812018-04-18 18:41:05 -0700327 // Handles host, route and mcast events respectively
328 private ScheduledExecutorService hostEventExecutor;
329 private ScheduledExecutorService routeEventExecutor;
330 private ScheduledExecutorService mcastEventExecutor;
Charles Chan77cdde42018-05-08 21:35:50 -0700331 private ExecutorService packetExecutor;
Charles Chana7601c92019-01-23 15:03:17 -0800332 ExecutorService neighborExecutor;
Charles Chan52003922018-04-05 16:31:15 -0700333
334 Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<>();
Charles Chanb7f75ac2016-01-11 18:28:54 -0800335 /**
Saurav Das261c3002017-06-13 15:35:54 -0700336 * Per device next objective ID store with (device id + destination set) as key.
Charles Chan53de91f2017-08-22 15:07:34 -0700337 * Used to keep track on MPLS group information.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800338 */
Charles Chan873661e2017-11-30 15:37:50 -0800339 private EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Saurav Das261c3002017-06-13 15:35:54 -0700340 dsNextObjStore = null;
Charles Chanb7f75ac2016-01-11 18:28:54 -0800341 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700342 * Per device next objective ID store with (device id + vlanid) as key.
343 * Used to keep track on L2 flood group information.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800344 */
Charles Chan873661e2017-11-30 15:37:50 -0800345 private EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer>
Charles Chan10b0fb72017-02-02 16:20:42 -0800346 vlanNextObjStore = null;
Charles Chanb7f75ac2016-01-11 18:28:54 -0800347 /**
Charles Chan53de91f2017-08-22 15:07:34 -0700348 * Per device next objective ID store with (device id + port + treatment + meta) as key.
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000349 * Used to keep track on L2 interface group and L3 unicast group information for direct hosts.
Charles Chanb7f75ac2016-01-11 18:28:54 -0800350 */
Charles Chan873661e2017-11-30 15:37:50 -0800351 private EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer>
Saurav Das2d94d312015-11-24 23:21:05 -0800352 portNextObjStore = null;
Charles Chan10b0fb72017-02-02 16:20:42 -0800353
Jonghwan Hyun9aaa34f2018-04-09 09:40:50 -0700354 /**
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000355 * Per device next objective ID store with (device id + MAC address + vlan) as key.
356 * Used to keep track of L3 unicast group for indirect hosts.
357 */
358 private EventuallyConsistentMap<MacVlanNextObjectiveStoreKey, Integer>
359 macVlanNextObjStore = null;
360
Saurav Das2d94d312015-11-24 23:21:05 -0800361 private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
362 private EventuallyConsistentMap<String, Policy> policyStore = null;
sangho4a5c42a2015-05-20 22:16:38 -0700363
Saurav Das261c3002017-06-13 15:35:54 -0700364 private AtomicBoolean programmingScheduled = new AtomicBoolean();
365
Charles Chanc91c8782016-03-30 17:54:24 -0700366 private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700367 new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>(
368 SubjectFactories.DEVICE_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700369 SegmentRoutingDeviceConfig.class, "segmentrouting") {
Charles Chan72f556a2015-10-05 17:50:33 -0700370 @Override
Charles Chan82ab1932016-01-30 23:22:37 -0800371 public SegmentRoutingDeviceConfig createConfig() {
372 return new SegmentRoutingDeviceConfig();
Charles Chan72f556a2015-10-05 17:50:33 -0700373 }
374 };
Pier Ventre6b19e482016-11-07 16:21:04 -0800375
Charles Chanc91c8782016-03-30 17:54:24 -0700376 private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700377 new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>(
378 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700379 SegmentRoutingAppConfig.class, "segmentrouting") {
Charles Chan82ab1932016-01-30 23:22:37 -0800380 @Override
381 public SegmentRoutingAppConfig createConfig() {
382 return new SegmentRoutingAppConfig();
383 }
384 };
Pier Ventre6b19e482016-11-07 16:21:04 -0800385
Charles Chanc91c8782016-03-30 17:54:24 -0700386 private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory =
Charles Chan82f19972016-05-17 13:13:55 -0700387 new ConfigFactory<ApplicationId, McastConfig>(
388 SubjectFactories.APP_SUBJECT_FACTORY,
Charles Chanc91c8782016-03-30 17:54:24 -0700389 McastConfig.class, "multicast") {
390 @Override
391 public McastConfig createConfig() {
392 return new McastConfig();
393 }
394 };
395
Charles Chan1963f4f2016-02-18 14:22:42 -0800396 /**
397 * Segment Routing App ID.
398 */
Charles Chan46fdfaf2016-11-09 20:51:44 -0800399 public static final String APP_NAME = "org.onosproject.segmentrouting";
Saurav Das7c305372015-10-28 12:39:42 -0700400
Jonghwan Hyun9aaa34f2018-04-09 09:40:50 -0700401 /**
402 * Minumum and maximum value of dummy VLAN ID to be allocated.
403 */
404 public static final int MIN_DUMMY_VLAN_ID = 2;
405 public static final int MAX_DUMMY_VLAN_ID = 4093;
406
Charles Chana7601c92019-01-23 15:03:17 -0800407 private static final int DEFAULT_POOL_SIZE = 32;
408
Saurav Dasec683dc2018-04-27 18:42:30 -0700409 Instant lastEdgePortEvent = Instant.EPOCH;
410
sangho80f11cb2015-04-01 13:05:26 -0700411 @Activate
Charles Chan873661e2017-11-30 15:37:50 -0800412 protected void activate(ComponentContext context) {
Charles Chan46fdfaf2016-11-09 20:51:44 -0800413 appId = coreService.registerApplication(APP_NAME);
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700414
Charles Chana7601c92019-01-23 15:03:17 -0800415 mainEventExecutor = Executors.newSingleThreadScheduledExecutor(
416 groupedThreads("onos/sr", "event-main-%d", log));
417 hostEventExecutor = Executors.newSingleThreadScheduledExecutor(
418 groupedThreads("onos/sr", "event-host-%d", log));
419 routeEventExecutor = Executors.newSingleThreadScheduledExecutor(
420 groupedThreads("onos/sr", "event-route-%d", log));
421 mcastEventExecutor = Executors.newSingleThreadScheduledExecutor(
422 groupedThreads("onos/sr", "event-mcast-%d", log));
423 packetExecutor = Executors.newSingleThreadExecutor(groupedThreads("onos/sr", "packet-%d", log));
424 neighborExecutor = Executors.newFixedThreadPool(DEFAULT_POOL_SIZE,
425 groupedThreads("onos/sr", "neighbor-%d", log));
Charles Chanfbcb8812018-04-18 18:41:05 -0700426
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700427 log.debug("Creating EC map nsnextobjectivestore");
Saurav Das261c3002017-06-13 15:35:54 -0700428 EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors>
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700429 nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
Saurav Das261c3002017-06-13 15:35:54 -0700430 dsNextObjStore = nsNextObjMapBuilder
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700431 .withName("nsnextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700432 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700433 .withTimestampProvider((k, v) -> new WallClockTimestamp())
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700434 .build();
Saurav Das261c3002017-06-13 15:35:54 -0700435 log.trace("Current size {}", dsNextObjStore.size());
Srikanth Vavilapalli7cd16712015-05-04 09:48:09 -0700436
Charles Chan10b0fb72017-02-02 16:20:42 -0800437 log.debug("Creating EC map vlannextobjectivestore");
438 EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer>
439 vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
440 vlanNextObjStore = vlanNextObjMapBuilder
441 .withName("vlannextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700442 .withSerializer(createSerializer())
Charles Chan77277672015-10-20 16:24:19 -0700443 .withTimestampProvider((k, v) -> new WallClockTimestamp())
444 .build();
445
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000446 log.debug("Creating EC map macvlannextobjectivestore");
447 EventuallyConsistentMapBuilder<MacVlanNextObjectiveStoreKey, Integer>
448 macVlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
449 macVlanNextObjStore = macVlanNextObjMapBuilder
450 .withName("macvlannextobjectivestore")
451 .withSerializer(createSerializer())
452 .withTimestampProvider((k, v) -> new WallClockTimestamp())
453 .build();
454
Saurav Das2d94d312015-11-24 23:21:05 -0800455 log.debug("Creating EC map subnetnextobjectivestore");
456 EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer>
457 portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder();
458 portNextObjStore = portNextObjMapBuilder
459 .withName("portnextobjectivestore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700460 .withSerializer(createSerializer())
Saurav Das2d94d312015-11-24 23:21:05 -0800461 .withTimestampProvider((k, v) -> new WallClockTimestamp())
462 .build();
463
sangho4a5c42a2015-05-20 22:16:38 -0700464 EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder =
465 storageService.eventuallyConsistentMapBuilder();
sangho4a5c42a2015-05-20 22:16:38 -0700466 tunnelStore = tunnelMapBuilder
467 .withName("tunnelstore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700468 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700469 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho4a5c42a2015-05-20 22:16:38 -0700470 .build();
471
472 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
473 storageService.eventuallyConsistentMapBuilder();
sangho4a5c42a2015-05-20 22:16:38 -0700474 policyStore = policyMapBuilder
475 .withName("policystore")
Jonathan Hart54541d12016-04-12 15:39:44 -0700476 .withSerializer(createSerializer())
Madan Jampani675ae202015-06-24 19:05:56 -0700477 .withTimestampProvider((k, v) -> new WallClockTimestamp())
sangho4a5c42a2015-05-20 22:16:38 -0700478 .build();
479
Charles Chan97979802020-02-26 15:04:44 -0800480 processor = new InternalPacketProcessor();
481 linkListener = new InternalLinkListener();
482 deviceListener = new InternalDeviceListener();
483 appCfgHandler = new AppConfigHandler(this);
484 mcastHandler = new McastHandler(this);
485 hostHandler = new HostHandler(this);
486 linkHandler = new LinkHandler(this);
487 routeHandler = new RouteHandler(this);
488 neighbourHandler = new SegmentRoutingNeighbourDispatcher(this);
489 l2TunnelHandler = new DefaultL2TunnelHandler(this);
490 topologyHandler = new TopologyHandler(this);
491
Pier Luigib9632ba2017-01-12 18:14:58 -0800492 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
Charles Chan0fa51db2019-04-10 17:12:20 -0700493 "requestInterceptsEnabled", "false", false);
Charles Chanc1909e12017-08-08 15:13:37 -0700494 compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700495 "requestInterceptsEnabled", "false", false);
Charles Chan9597f8d2017-07-24 15:56:10 -0700496 compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700497 "arpEnabled", "false", false);
Pier Luigi0ebeb312017-02-02 22:31:34 -0800498 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700499 "greedyLearningIpv6", "true", false);
Charles Chancf8ea472017-02-28 15:15:17 -0800500 compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700501 "forceUnprovision", "true", false);
Charles Chanc7b73c72017-08-10 16:57:28 -0700502 compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl",
Charles Chan0fa51db2019-04-10 17:12:20 -0700503 "distributed", "true", false);
Charles Chan804772f2017-08-14 11:42:11 -0700504 compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider",
Charles Chan0fa51db2019-04-10 17:12:20 -0700505 "multihomingEnabled", "true", false);
Charles Chan0c9c19f2017-11-29 19:54:20 -0800506 compCfgService.preSetProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider",
Charles Chan0fa51db2019-04-10 17:12:20 -0700507 "staleLinkAge", "15000", false);
Charles Chan0c9c19f2017-11-29 19:54:20 -0800508 compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700509 "allowDuplicateIps", "false", false);
Yi Tsenga7da8d82018-08-19 03:09:54 +0800510 // For P4 switches
511 compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700512 "fallbackFlowPollFrequency", "4", false);
Yi Tsenga7da8d82018-08-19 03:09:54 +0800513 compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager",
Charles Chan0fa51db2019-04-10 17:12:20 -0700514 "fallbackGroupPollFrequency", "3", false);
pierventre4582cf12021-09-14 20:42:59 +0200515 compCfgService.preSetProperty("org.onosproject.net.meter.impl.MeterManager",
516 "fallbackMeterPollFrequency", "3", false);
Charles Chan873661e2017-11-30 15:37:50 -0800517 compCfgService.registerProperties(getClass());
518 modified(context);
Saurav Dasc3604f12016-03-23 11:22:49 -0700519
Charles Chand6d25332016-02-26 22:19:52 -0800520 cfgService.addListener(cfgListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700521 cfgService.registerConfigFactory(deviceConfigFactory);
522 cfgService.registerConfigFactory(appConfigFactory);
523 cfgService.registerConfigFactory(mcastConfigFactory);
Saurav Dase321cff2018-02-09 17:26:45 -0800524 log.info("Configuring network before adding listeners");
Andrea Campanella060cad82018-04-17 12:09:34 +0200525
Charles Chan6961f222018-01-04 14:26:07 -0800526 cfgListener.configureNetwork();
527
Charles Chan82ab1932016-01-30 23:22:37 -0800528 hostService.addListener(hostListener);
Charles Chan2b078ae2015-10-14 11:24:40 -0700529 packetService.addProcessor(processor, PacketProcessor.director(2));
530 linkService.addListener(linkListener);
531 deviceService.addListener(deviceListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700532 multicastRouteService.addListener(mcastListener);
Charles Chanfd48c222017-06-19 00:43:31 -0700533 routeService.addListener(routeListener);
Pier Luigid8a15162018-02-15 16:33:08 +0100534 topologyService.addListener(topologyListener);
Charles Chanfbcb8812018-04-18 18:41:05 -0700535 mastershipService.addListener(mastershipListener);
Saurav Das00e553b2018-04-21 17:19:48 -0700536 clusterService.addListener(clusterListener);
Charles Chan2b078ae2015-10-14 11:24:40 -0700537
Charles Chanc12c3d02018-03-09 15:53:44 -0800538 linkHandler.init();
Andreas Pantelopoulos75eef062018-01-11 07:53:48 -0800539 l2TunnelHandler.init();
540
pierventrec80a5052021-05-20 12:56:38 +0200541 drainEvents();
Andrea Campanella060cad82018-04-17 12:09:34 +0200542
sangho80f11cb2015-04-01 13:05:26 -0700543 log.info("Started");
544 }
545
pierventrec80a5052021-05-20 12:56:38 +0200546 // Drain buffered events
547 private void drainEvents() {
548 synchronized (networkConfigCompletionLock) {
549 final List<Event> processedEvents = Lists.newArrayList();
550 if (networkConfigCompletion != null) {
551 networkConfigCompletion.whenComplete((value, ex) -> {
552 //setting to null for easier fall through
553 networkConfigCompletion = null;
554 //process all queued events
555 queuedEvents.forEach(event -> {
556 mainEventExecutor.execute(new InternalEventHandler(event));
557 processedEvents.add(event);
558 });
559 // Removes all
560 queuedEvents.removeAll(processedEvents);
561 processedEvents.clear();
562 });
563 }
564 }
565 }
566
Saurav Dase6c448a2018-01-18 12:07:33 -0800567 KryoNamespace.Builder createSerializer() {
Jonathan Hart54541d12016-04-12 15:39:44 -0700568 return new KryoNamespace.Builder()
569 .register(KryoNamespaces.API)
Saurav Das261c3002017-06-13 15:35:54 -0700570 .register(DestinationSetNextObjectiveStoreKey.class,
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800571 VlanNextObjectiveStoreKey.class,
572 DestinationSet.class,
Andreas Pantelopoulos92998c92018-05-29 13:11:14 -0700573 DestinationSet.DestinationSetType.class,
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800574 NextNeighbors.class,
575 Tunnel.class,
576 DefaultTunnel.class,
577 Policy.class,
578 TunnelPolicy.class,
579 Policy.Type.class,
580 PortNextObjectiveStoreKey.class,
581 XConnectStoreKey.class,
582 L2Tunnel.class,
583 L2TunnelPolicy.class,
584 DefaultL2Tunnel.class,
Jonghwan Hyun9aaa34f2018-04-09 09:40:50 -0700585 DefaultL2TunnelPolicy.class,
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000586 MacVlanNextObjectiveStoreKey.class
Jonathan Hart54541d12016-04-12 15:39:44 -0700587 );
588 }
589
sangho80f11cb2015-04-01 13:05:26 -0700590 @Deactivate
591 protected void deactivate() {
Charles Chanfbcb8812018-04-18 18:41:05 -0700592 mainEventExecutor.shutdown();
593 hostEventExecutor.shutdown();
594 routeEventExecutor.shutdown();
595 mcastEventExecutor.shutdown();
Charles Chan77cdde42018-05-08 21:35:50 -0700596 packetExecutor.shutdown();
Charles Chana7601c92019-01-23 15:03:17 -0800597 neighborExecutor.shutdown();
Charles Chanfbcb8812018-04-18 18:41:05 -0700598
Ray Milkeyaee4d3e2018-05-11 09:59:19 -0700599 mainEventExecutor = null;
600 hostEventExecutor = null;
601 routeEventExecutor = null;
602 mcastEventExecutor = null;
603 packetExecutor = null;
Charles Chana7601c92019-01-23 15:03:17 -0800604 neighborExecutor = null;
Ray Milkeyaee4d3e2018-05-11 09:59:19 -0700605
Danny Chang44a7b952020-09-08 15:27:04 -0700606 cancelPackets();
607
Charles Chan72f556a2015-10-05 17:50:33 -0700608 cfgService.removeListener(cfgListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700609 cfgService.unregisterConfigFactory(deviceConfigFactory);
610 cfgService.unregisterConfigFactory(appConfigFactory);
611 cfgService.unregisterConfigFactory(mcastConfigFactory);
Charles Chan873661e2017-11-30 15:37:50 -0800612 compCfgService.unregisterProperties(getClass(), false);
Charles Chan72f556a2015-10-05 17:50:33 -0700613
Charles Chanfd48c222017-06-19 00:43:31 -0700614 hostService.removeListener(hostListener);
sangho80f11cb2015-04-01 13:05:26 -0700615 packetService.removeProcessor(processor);
Charles Chan2b078ae2015-10-14 11:24:40 -0700616 linkService.removeListener(linkListener);
617 deviceService.removeListener(deviceListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700618 multicastRouteService.removeListener(mcastListener);
Charles Chandebfea32016-10-24 14:52:01 -0700619 routeService.removeListener(routeListener);
Pier Luigid8a15162018-02-15 16:33:08 +0100620 topologyService.removeListener(topologyListener);
Charles Chanfbcb8812018-04-18 18:41:05 -0700621 mastershipService.removeListener(mastershipListener);
Saurav Das00e553b2018-04-21 17:19:48 -0700622 clusterService.removeListener(clusterListener);
Charles Chanc91c8782016-03-30 17:54:24 -0700623
Charles Chan2e71ef32017-02-23 15:44:08 -0800624 neighbourResolutionService.unregisterNeighbourHandlers(appId);
625
sangho80f11cb2015-04-01 13:05:26 -0700626 processor = null;
Charles Chan2b078ae2015-10-14 11:24:40 -0700627 linkListener = null;
Charles Chanc91c8782016-03-30 17:54:24 -0700628 deviceListener = null;
Charles Chan05bb1702018-04-19 13:10:01 -0700629 groupHandlerMap.forEach((k, v) -> v.shutdown());
Charles Chan2b078ae2015-10-14 11:24:40 -0700630 groupHandlerMap.clear();
Saurav Das49368392018-04-23 18:42:12 -0700631 defaultRoutingHandler.shutdown();
Charles Chan2b078ae2015-10-14 11:24:40 -0700632
Saurav Das261c3002017-06-13 15:35:54 -0700633 dsNextObjStore.destroy();
Charles Chan10b0fb72017-02-02 16:20:42 -0800634 vlanNextObjStore.destroy();
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000635 macVlanNextObjStore.destroy();
Charles Chanc91c8782016-03-30 17:54:24 -0700636 portNextObjStore.destroy();
Charles Chanc91c8782016-03-30 17:54:24 -0700637 tunnelStore.destroy();
638 policyStore.destroy();
Pier Luigi35dab3f2018-01-25 16:16:02 +0100639
640 mcastHandler.terminate();
piercf557922019-05-17 20:47:06 +0200641 hostHandler.terminate();
sangho80f11cb2015-04-01 13:05:26 -0700642 log.info("Stopped");
643 }
644
Charles Chan873661e2017-11-30 15:37:50 -0800645 @Modified
646 private void modified(ComponentContext context) {
647 Dictionary<?, ?> properties = context.getProperties();
648 if (properties == null) {
649 return;
650 }
651
Ray Milkey48d10c02018-10-24 10:04:03 -0700652 String strActiveProbing = Tools.get(properties, PROP_ACTIVE_PROBING);
Andreas Pantelopoulos6464d862018-06-18 12:50:35 -0700653 boolean expectActiveProbing = Boolean.parseBoolean(strActiveProbing);
Charles Chan873661e2017-11-30 15:37:50 -0800654 if (expectActiveProbing != activeProbing) {
655 activeProbing = expectActiveProbing;
656 log.info("{} active probing", activeProbing ? "Enabling" : "Disabling");
657 }
Saurav Dasec683dc2018-04-27 18:42:30 -0700658
Ray Milkeye96d0de2018-11-02 17:12:21 -0700659
660 String strSymmetricProbing = Tools.get(properties, PROP_SYMMETRIC_PROBING);
661 boolean expectSymmetricProbing = Boolean.parseBoolean(strSymmetricProbing);
Mayank Tiwarif7942402018-10-29 18:27:35 -0400662 if (expectSymmetricProbing != symmetricProbing) {
663 symmetricProbing = expectSymmetricProbing;
664 log.info("{} symmetric probing", symmetricProbing ? "Enabling" : "Disabling");
665 }
666
Ray Milkey48d10c02018-10-24 10:04:03 -0700667 String strSingleHomedDown = Tools.get(properties, PROP_SINGLE_HOMED_DOWN);
Saurav Dasec683dc2018-04-27 18:42:30 -0700668 boolean expectSingleHomedDown = Boolean.parseBoolean(strSingleHomedDown);
669 if (expectSingleHomedDown != singleHomedDown) {
670 singleHomedDown = expectSingleHomedDown;
671 log.info("{} downing of single homed hosts for lost uplinks",
672 singleHomedDown ? "Enabling" : "Disabling");
673 if (singleHomedDown && linkHandler != null) {
674 hostService.getHosts().forEach(host -> host.locations()
675 .forEach(loc -> {
676 if (interfaceService.isConfigured(loc)) {
677 linkHandler.checkUplinksForHost(loc);
678 }
679 }));
680 } else {
681 log.warn("Disabling singleHomedDown does not re-enable already "
682 + "downed ports for single-homed hosts");
683 }
684 }
Andreas Pantelopoulos6464d862018-06-18 12:50:35 -0700685
Ray Milkey48d10c02018-10-24 10:04:03 -0700686 String strRespondToUnknownHosts = Tools.get(properties, PROP_RESPOND_TO_UNKNOWN_HOSTS);
Andreas Pantelopoulos6464d862018-06-18 12:50:35 -0700687 boolean expectRespondToUnknownHosts = Boolean.parseBoolean(strRespondToUnknownHosts);
688 if (expectRespondToUnknownHosts != respondToUnknownHosts) {
689 respondToUnknownHosts = expectRespondToUnknownHosts;
690 log.info("{} responding to ARPs/NDPs from unknown hosts", respondToUnknownHosts ? "Enabling" : "Disabling");
691 }
Charles Chan4eb73bb2018-07-19 14:55:31 -0700692
Ray Milkey48d10c02018-10-24 10:04:03 -0700693 String strRouteDoubleTaggedHosts = Tools.get(properties, PROP_ROUTE_DOUBLE_TAGGED_HOSTS);
Charles Chanfbca55e2018-07-24 16:40:35 -0700694 boolean expectRouteDoubleTaggedHosts = Boolean.parseBoolean(strRouteDoubleTaggedHosts);
695 if (expectRouteDoubleTaggedHosts != routeDoubleTaggedHosts) {
696 routeDoubleTaggedHosts = expectRouteDoubleTaggedHosts;
697 log.info("{} routing for double tagged hosts", routeDoubleTaggedHosts ? "Enabling" : "Disabling");
Charles Chan4eb73bb2018-07-19 14:55:31 -0700698
Charles Chanfbca55e2018-07-24 16:40:35 -0700699 if (routeDoubleTaggedHosts) {
Charles Chan4eb73bb2018-07-19 14:55:31 -0700700 hostHandler.populateAllDoubleTaggedHost();
701 } else {
702 hostHandler.revokeAllDoubleTaggedHost();
703 }
704 }
Saurav Das9bf49582018-08-13 15:34:26 -0700705
Ray Milkey48d10c02018-10-24 10:04:03 -0700706 String strDefaultInternalVlan = Tools.get(properties, PROP_DEFAULT_INTERNAL_VLAN);
Saurav Das9bf49582018-08-13 15:34:26 -0700707 int defIntVlan = Integer.parseInt(strDefaultInternalVlan);
708 if (defIntVlan != defaultInternalVlan) {
709 if (canUseVlanId(defIntVlan)) {
710 log.warn("Default internal vlan value changed from {} to {}.. "
711 + "re-programming filtering rules, but NOT any groups already "
712 + "created with the former value", defaultInternalVlan, defIntVlan);
713 VlanId oldDefIntVlan = VlanId.vlanId((short) defaultInternalVlan);
714 defaultInternalVlan = defIntVlan;
715 routingRulePopulator
716 .updateSpecialVlanFilteringRules(true, oldDefIntVlan,
717 VlanId.vlanId((short) defIntVlan));
718 } else {
719 log.warn("Cannot change default internal vlan to unusable "
720 + "value {}", defIntVlan);
721 }
722 }
723
Ray Milkey48d10c02018-10-24 10:04:03 -0700724 String strPwTxpVlan = Tools.get(properties, PROP_PW_TRANSPORT_VLAN);
Saurav Das9bf49582018-08-13 15:34:26 -0700725 int pwTxpVlan = Integer.parseInt(strPwTxpVlan);
726 if (pwTxpVlan != pwTransportVlan) {
727 if (canUseVlanId(pwTxpVlan)) {
728 log.warn("Pseudowire transport vlan value changed from {} to {}.. "
729 + "re-programming filtering rules, but NOT any groups already "
730 + "created with the former value", pwTransportVlan,
731 pwTxpVlan);
732 VlanId oldPwTxpVlan = VlanId.vlanId((short) pwTransportVlan);
733 pwTransportVlan = pwTxpVlan;
734 routingRulePopulator
735 .updateSpecialVlanFilteringRules(false, oldPwTxpVlan,
736 VlanId.vlanId((short) pwTxpVlan));
737 } else {
738 log.warn("Cannot change pseudowire transport vlan to unusable "
739 + "value {}", pwTxpVlan);
740 }
741 }
742
psneha86e60d32019-03-26 06:31:41 -0400743 String strRouteSimplification = Tools.get(properties, PROP_ROUTE_SIMPLIFICATION);
744 boolean expectRouteSimplification = Boolean.parseBoolean(strRouteSimplification);
745 if (expectRouteSimplification != routeSimplification) {
746 routeSimplification = expectRouteSimplification;
747 log.info("{} route simplification", routeSimplification ? "Enabling" : "Disabling");
748 }
749
Saurav Das9bf49582018-08-13 15:34:26 -0700750 }
751
752 /**
Danny Chang44a7b952020-09-08 15:27:04 -0700753 * Removes all packet requests.
754 */
755 private void cancelPackets() {
756 if (routingRulePopulator == null) {
757 return;
758 }
759 log.info("Removing packet requests.");
760 routingRulePopulator.revokePacketsPunts();
761 }
762
763 /**
Saurav Das9bf49582018-08-13 15:34:26 -0700764 * Returns true if given vlan id is not being used in the system currently,
765 * either as one of the default system wide vlans or as one of the
766 * configured interface vlans.
767 *
768 * @param vlanId given vlan id
769 * @return true if vlan is not currently in use
770 */
771 public boolean canUseVlanId(int vlanId) {
772 if (vlanId >= 4095 || vlanId <= 1) {
773 log.error("Vlan id {} value is not in valid range 2 <--> 4094",
774 vlanId);
775 return false;
776 }
777
778 VlanId vid = VlanId.vlanId((short) vlanId);
779 if (getDefaultInternalVlan().equals(vid) || getPwTransportVlan().equals(vid)) {
780 log.warn("Vlan id {} value is already in use system-wide. "
781 + "DefaultInternalVlan:{} PwTransportVlan:{} ", vlanId,
782 getDefaultInternalVlan(), getPwTransportVlan());
783 return false;
784 }
785
786 if (interfaceService.inUse(vid)) {
787 log.warn("Vlan id {} value is already in use on a configured "
788 + "interface in the system", vlanId);
789 return false;
790 }
791 return true;
792 }
793
pierventre4f68ffa2021-03-09 22:52:14 +0100794 @Override
Saurav Das9bf49582018-08-13 15:34:26 -0700795 public VlanId getDefaultInternalVlan() {
796 return VlanId.vlanId((short) defaultInternalVlan);
797 }
798
799 /**
800 * Returns the Vlan id used to transport pseudowire traffic across the
801 * network.
802 *
803 * @return the pseudowire transport vlan id
804 */
805 public VlanId getPwTransportVlan() {
806 return VlanId.vlanId((short) pwTransportVlan);
Charles Chan873661e2017-11-30 15:37:50 -0800807 }
808
sangho27462c62015-05-14 00:39:53 -0700809 @Override
810 public List<Tunnel> getTunnels() {
811 return tunnelHandler.getTunnels();
812 }
813
814 @Override
sanghobd812f82015-06-29 14:58:47 -0700815 public TunnelHandler.Result createTunnel(Tunnel tunnel) {
816 return tunnelHandler.createTunnel(tunnel);
sangho27462c62015-05-14 00:39:53 -0700817 }
818
819 @Override
sanghobd812f82015-06-29 14:58:47 -0700820 public TunnelHandler.Result removeTunnel(Tunnel tunnel) {
sangho27462c62015-05-14 00:39:53 -0700821 for (Policy policy: policyHandler.getPolicies()) {
822 if (policy.type() == Policy.Type.TUNNEL_FLOW) {
823 TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
824 if (tunnelPolicy.tunnelId().equals(tunnel.id())) {
825 log.warn("Cannot remove the tunnel used by a policy");
sanghobd812f82015-06-29 14:58:47 -0700826 return TunnelHandler.Result.TUNNEL_IN_USE;
sangho27462c62015-05-14 00:39:53 -0700827 }
828 }
829 }
sanghobd812f82015-06-29 14:58:47 -0700830 return tunnelHandler.removeTunnel(tunnel);
sangho27462c62015-05-14 00:39:53 -0700831 }
832
833 @Override
sanghobd812f82015-06-29 14:58:47 -0700834 public PolicyHandler.Result removePolicy(Policy policy) {
835 return policyHandler.removePolicy(policy);
sangho27462c62015-05-14 00:39:53 -0700836 }
837
838 @Override
sanghobd812f82015-06-29 14:58:47 -0700839 public PolicyHandler.Result createPolicy(Policy policy) {
840 return policyHandler.createPolicy(policy);
sangho27462c62015-05-14 00:39:53 -0700841 }
842
843 @Override
844 public List<Policy> getPolicies() {
845 return policyHandler.getPolicies();
846 }
847
Saurav Das07c74602016-04-27 18:35:50 -0700848 @Override
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700849 public Set<L2TunnelDescription> getL2TunnelDescriptions(boolean pending) {
850 return l2TunnelHandler.getL2Descriptions(pending);
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700851 }
852
853 @Override
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800854 public List<L2Tunnel> getL2Tunnels() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700855 return l2TunnelHandler.getL2Tunnels();
856 }
857
858 @Override
Andreas Pantelopoulos4c7de132018-02-22 12:32:42 -0800859 public List<L2TunnelPolicy> getL2Policies() {
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700860 return l2TunnelHandler.getL2Policies();
861 }
862
Saurav Dasdebcf882018-04-06 20:16:01 -0700863 @Override
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700864 @Deprecated
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700865 public L2TunnelHandler.Result addPseudowiresBulk(List<DefaultL2TunnelDescription> bulkPseudowires) {
866
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700867 // get both added and pending pseudowires
868 List<L2TunnelDescription> pseudowires = new ArrayList<>();
869 pseudowires.addAll(l2TunnelHandler.getL2Descriptions(false));
870 pseudowires.addAll(l2TunnelHandler.getL2Descriptions(true));
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700871 pseudowires.addAll(bulkPseudowires);
Andreas Pantelopoulosd988c1a2018-03-15 16:56:09 -0700872
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700873 Set<L2TunnelDescription> newPseudowires = new HashSet(bulkPseudowires);
874
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700875 L2TunnelHandler.Result retRes = L2TunnelHandler.Result.SUCCESS;
876 L2TunnelHandler.Result res;
877 for (DefaultL2TunnelDescription pw : bulkPseudowires) {
878 res = addPseudowire(pw);
879 if (res != L2TunnelHandler.Result.SUCCESS) {
880 log.error("Pseudowire with id {} can not be instantiated !", res);
881 retRes = res;
882 }
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700883 }
Andreas Pantelopoulos96851252018-03-20 13:58:49 -0700884
885 return retRes;
Andreas Pantelopoulosfc4bc2a2018-03-12 16:30:20 -0700886 }
887
888 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800889 public L2TunnelHandler.Result addPseudowire(L2TunnelDescription l2TunnelDescription) {
Andreas Pantelopoulos87a06102018-03-21 16:44:18 -0700890 return l2TunnelHandler.deployPseudowire(l2TunnelDescription);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700891 }
892
893 @Override
Andreas Pantelopouloscdbb22c2018-02-23 14:18:00 -0800894 public L2TunnelHandler.Result removePseudowire(Integer pwId) {
Andreas Pantelopoulos87a06102018-03-21 16:44:18 -0700895 return l2TunnelHandler.tearDownPseudowire(pwId);
Andreas Pantelopoulos5e7be3d2017-10-23 12:18:25 -0700896 }
897
898 @Override
Saurav Das07c74602016-04-27 18:35:50 -0700899 public void rerouteNetwork() {
pierventrec80a5052021-05-20 12:56:38 +0200900 cfgListener.configureNetworkAndDrainEvents();
Saurav Das07c74602016-04-27 18:35:50 -0700901 }
902
Charles Chand7844e52016-10-20 17:02:44 -0700903 @Override
Pier Ventreb6a7f342016-11-26 21:05:22 -0800904 public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() {
905 Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap();
Jonathan Hart61e24e12017-11-30 18:23:42 -0800906 deviceConfiguration.getRouters().forEach(device ->
907 deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device)));
Charles Chand7844e52016-10-20 17:02:44 -0700908 return deviceSubnetMap;
909 }
910
Saurav Das62ae6792017-05-15 15:34:25 -0700911
912 @Override
913 public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() {
914 if (defaultRoutingHandler != null) {
915 return defaultRoutingHandler.getCurrentEmcpSpgMap();
916 } else {
917 return null;
918 }
919 }
920
921 @Override
Charles Chan0b1dd7e2018-08-19 19:21:46 -0700922 public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDstNextObjStore() {
Saurav Das261c3002017-06-13 15:35:54 -0700923 if (dsNextObjStore != null) {
924 return ImmutableMap.copyOf(dsNextObjStore.entrySet());
Saurav Das62ae6792017-05-15 15:34:25 -0700925 } else {
926 return ImmutableMap.of();
927 }
928 }
929
Saurav Dasfbe74572017-08-03 18:30:35 -0700930 @Override
Charles Chan0b1dd7e2018-08-19 19:21:46 -0700931 public ImmutableMap<VlanNextObjectiveStoreKey, Integer> getVlanNextObjStore() {
932 if (vlanNextObjStore != null) {
933 return ImmutableMap.copyOf(vlanNextObjStore.entrySet());
934 } else {
935 return ImmutableMap.of();
936 }
937 }
938
939 @Override
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000940 public ImmutableMap<MacVlanNextObjectiveStoreKey, Integer> getMacVlanNextObjStore() {
941 if (macVlanNextObjStore != null) {
942 return ImmutableMap.copyOf(macVlanNextObjStore.entrySet());
943 } else {
944 return ImmutableMap.of();
945 }
946 }
947
948 @Override
Charles Chan0b1dd7e2018-08-19 19:21:46 -0700949 public ImmutableMap<PortNextObjectiveStoreKey, Integer> getPortNextObjStore() {
950 if (portNextObjStore != null) {
951 return ImmutableMap.copyOf(portNextObjStore.entrySet());
952 } else {
953 return ImmutableMap.of();
954 }
955 }
956
957 @Override
958 public ImmutableMap<String, NextObjective> getPwInitNext() {
959 if (l2TunnelHandler != null) {
960 return l2TunnelHandler.getInitNext();
961 } else {
962 return ImmutableMap.of();
963 }
964 }
965
966 @Override
967 public ImmutableMap<String, NextObjective> getPwTermNext() {
968 if (l2TunnelHandler != null) {
969 return l2TunnelHandler.getTermNext();
970 } else {
971 return ImmutableMap.of();
972 }
973 }
974
975 @Override
976 public void invalidateNextObj(int nextId) {
977 if (dsNextObjStore != null) {
978 dsNextObjStore.entrySet().forEach(e -> {
979 if (e.getValue().nextId() == nextId) {
980 dsNextObjStore.remove(e.getKey());
981 }
982 });
983 }
984 if (vlanNextObjStore != null) {
985 vlanNextObjStore.entrySet().forEach(e -> {
986 if (e.getValue() == nextId) {
987 vlanNextObjStore.remove(e.getKey());
988 }
989 });
990 }
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +0000991 if (macVlanNextObjStore != null) {
992 macVlanNextObjStore.entrySet().forEach(e -> {
993 if (e.getValue() == nextId) {
994 macVlanNextObjStore.remove(e.getKey());
995 }
996 });
997 }
Charles Chan0b1dd7e2018-08-19 19:21:46 -0700998 if (portNextObjStore != null) {
999 portNextObjStore.entrySet().forEach(e -> {
1000 if (e.getValue() == nextId) {
1001 portNextObjStore.remove(e.getKey());
1002 }
1003 });
1004 }
1005 if (mcastHandler != null) {
1006 mcastHandler.removeNextId(nextId);
1007 }
1008 if (l2TunnelHandler != null) {
1009 l2TunnelHandler.removeNextId(nextId);
1010 }
1011 if (xconnectService != null) {
1012 xconnectService.removeNextId(nextId);
1013 }
1014 }
1015
1016 @Override
Saurav Dasfbe74572017-08-03 18:30:35 -07001017 public void verifyGroups(DeviceId id) {
1018 DefaultGroupHandler gh = groupHandlerMap.get(id);
1019 if (gh != null) {
1020 gh.triggerBucketCorrector();
1021 }
1022 }
1023
Saurav Das6430f412018-01-25 09:49:01 -08001024 @Override
1025 public ImmutableMap<Link, Boolean> getSeenLinks() {
1026 return linkHandler.getSeenLinks();
1027 }
1028
1029 @Override
1030 public ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState() {
1031 return linkHandler.getDownedPorts();
1032 }
1033
Pier Luigi0f9635b2018-01-15 18:06:43 +01001034 @Override
1035 public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) {
Charles Chan0b1dd7e2018-08-19 19:21:46 -07001036 return mcastHandler.getNextIds(mcastIp);
Pier Luigi0f9635b2018-01-15 18:06:43 +01001037 }
1038
1039 @Override
Piere99511d2018-04-19 16:47:06 +02001040 public Map<McastRoleStoreKey, McastRole> getMcastRoles(IpAddress mcastIp, ConnectPoint sourcecp) {
1041 return mcastHandler.getMcastRoles(mcastIp, sourcecp);
1042 }
1043
1044 @Override
Pier71c55772018-04-17 17:25:22 +02001045 public Multimap<ConnectPoint, List<ConnectPoint>> getMcastTrees(IpAddress mcastIp,
1046 ConnectPoint sourcecp) {
1047 return mcastHandler.getMcastTrees(mcastIp, sourcecp);
1048 }
1049
1050 @Override
Pierdb27b8d2018-04-17 16:29:56 +02001051 public Map<IpAddress, NodeId> getMcastLeaders(IpAddress mcastIp) {
1052 return mcastHandler.getMcastLeaders(mcastIp);
1053 }
1054
Charles Chanb13e0702018-04-17 18:56:53 -07001055 @Override
Harshada Chaundkar9204f312019-07-02 16:01:24 +00001056 public Map<DeviceId, List<McastFilteringObjStoreKey>> getMcastFilters() {
1057 return mcastHandler.getMcastFilters();
1058 }
1059
1060 @Override
Charles Chanb13e0702018-04-17 18:56:53 -07001061 public Map<Set<DeviceId>, NodeId> getShouldProgram() {
pierventre37dcf4c2021-09-16 18:43:06 +02001062 return ImmutableMap.of();
1063 }
1064
1065 @Override
1066 public Map<DeviceId, Boolean> getShouldProgramCache() {
1067 return ImmutableMap.of();
1068 }
1069
1070 @Override
1071 public Map<DeviceId, NodeId> getShouldProgramLeaders() {
Charles Chanb13e0702018-04-17 18:56:53 -07001072 return defaultRoutingHandler == null ? ImmutableMap.of() :
1073 ImmutableMap.copyOf(defaultRoutingHandler.shouldProgram);
1074 }
1075
1076 @Override
jayakumarthazhath66c9ec12018-10-01 00:51:54 +05301077 public boolean shouldProgram(DeviceId deviceId) {
pierventre37dcf4c2021-09-16 18:43:06 +02001078 return defaultRoutingHandler != null && defaultRoutingHandler.shouldProgram(deviceId);
jayakumarthazhath66c9ec12018-10-01 00:51:54 +05301079 }
1080
1081 @Override
Charles Chan12a8a842020-02-14 13:23:57 -08001082 public boolean isRoutingStable() {
1083 return defaultRoutingHandler.isRoutingStable();
1084 }
1085
1086 @Override
1087 public void initHost(DeviceId deviceId) {
1088 hostEventExecutor.execute(() -> hostHandler.init(deviceId));
1089 }
1090
1091 @Override
1092 public void initRoute(DeviceId deviceId) {
1093 routeEventExecutor.execute(() -> routeHandler.init(deviceId));
1094 }
1095
1096 @Override
Ray Milkeyb85de082017-04-05 09:42:04 -07001097 public ApplicationId appId() {
1098 return appId;
1099 }
1100
1101 /**
1102 * Returns the device configuration.
1103 *
1104 * @return device configuration
1105 */
1106 public DeviceConfiguration deviceConfiguration() {
1107 return deviceConfiguration;
1108 }
1109
1110 /**
Saurav Das261c3002017-06-13 15:35:54 -07001111 * Per device next objective ID store with (device id + destination set) as key.
Charles Chan53de91f2017-08-22 15:07:34 -07001112 * Used to keep track on MPLS group information.
Ray Milkeyb85de082017-04-05 09:42:04 -07001113 *
1114 * @return next objective ID store
1115 */
Saurav Das261c3002017-06-13 15:35:54 -07001116 public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors>
1117 dsNextObjStore() {
1118 return dsNextObjStore;
Ray Milkeyb85de082017-04-05 09:42:04 -07001119 }
1120
1121 /**
Charles Chan53de91f2017-08-22 15:07:34 -07001122 * Per device next objective ID store with (device id + vlanid) as key.
1123 * Used to keep track on L2 flood group information.
Ray Milkeyb85de082017-04-05 09:42:04 -07001124 *
1125 * @return vlan next object store
1126 */
1127 public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() {
1128 return vlanNextObjStore;
1129 }
1130
1131 /**
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001132 * Per device next objective ID store with (device id + MAC address + vlan) as key.
1133 * Used to keep track on L3 Unicast group information for indirect hosts.
1134 *
1135 * @return mac vlan next object store
1136 */
1137 public EventuallyConsistentMap<MacVlanNextObjectiveStoreKey, Integer> macVlanNextObjStore() {
1138 return macVlanNextObjStore;
1139 }
1140
1141 /**
Charles Chan53de91f2017-08-22 15:07:34 -07001142 * Per device next objective ID store with (device id + port + treatment + meta) as key.
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001143 * Used to keep track on L2 interface group and L3 unicast group information for direct hosts.
Ray Milkeyb85de082017-04-05 09:42:04 -07001144 *
1145 * @return port next object store.
1146 */
1147 public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() {
1148 return portNextObjStore;
1149 }
1150
1151 /**
Saurav Das261c3002017-06-13 15:35:54 -07001152 * Returns the MPLS-ECMP configuration which indicates whether ECMP on
1153 * labeled packets should be programmed or not.
Pier Ventre7a78de22016-10-31 15:00:01 -07001154 *
1155 * @return MPLS-ECMP value
1156 */
1157 public boolean getMplsEcmp() {
1158 SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService
1159 .getConfig(this.appId, SegmentRoutingAppConfig.class);
1160 return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp();
1161 }
1162
1163 /**
sangho80f1f892015-05-19 11:57:42 -07001164 * Returns the tunnel object with the tunnel ID.
1165 *
1166 * @param tunnelId Tunnel ID
1167 * @return Tunnel reference
1168 */
sangho27462c62015-05-14 00:39:53 -07001169 public Tunnel getTunnel(String tunnelId) {
1170 return tunnelHandler.getTunnel(tunnelId);
1171 }
1172
Charles Chan8d316332018-06-19 20:31:57 -07001173 @Override
Pier Luigi69f774d2018-02-28 12:10:50 +01001174 public VlanId getInternalVlanId(ConnectPoint connectPoint) {
Charles Chan098ca202018-05-01 11:50:20 -07001175 VlanId untaggedVlanId = interfaceService.getUntaggedVlanId(connectPoint);
1176 VlanId nativeVlanId = interfaceService.getNativeVlanId(connectPoint);
Charles Chand9265a32017-06-16 15:19:24 -07001177 return untaggedVlanId != null ? untaggedVlanId : nativeVlanId;
1178 }
1179
Charles Chan8d316332018-06-19 20:31:57 -07001180 @Override
1181 public Optional<DeviceId> getPairDeviceId(DeviceId deviceId) {
Charles Chan3ed34d82017-06-22 18:03:14 -07001182 SegmentRoutingDeviceConfig deviceConfig =
1183 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
1184 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId);
1185 }
Charles Chan8d316332018-06-19 20:31:57 -07001186
1187 @Override
Saurav Dasec683dc2018-04-27 18:42:30 -07001188 public Optional<PortNumber> getPairLocalPort(DeviceId deviceId) {
Charles Chan3ed34d82017-06-22 18:03:14 -07001189 SegmentRoutingDeviceConfig deviceConfig =
1190 cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
1191 return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort);
1192 }
1193
Charles Chan12a8a842020-02-14 13:23:57 -08001194 @Override
1195 public Set<PortNumber> getInfraPorts(DeviceId deviceId) {
1196 return deviceService.getPorts(deviceId).stream()
1197 .map(port -> new ConnectPoint(port.element().id(), port.number()))
1198 .filter(cp -> interfaceService.getInterfacesByPort(cp).isEmpty())
1199 .map(ConnectPoint::port)
1200 .collect(Collectors.toSet());
1201 }
1202
1203 @Override
1204 public Set<PortNumber> getEdgePorts(DeviceId deviceId) {
1205 return deviceService.getPorts(deviceId).stream()
1206 .map(port -> new ConnectPoint(port.element().id(), port.number()))
1207 .filter(cp -> !interfaceService.getInterfacesByPort(cp).isEmpty() &&
1208 !cp.port().equals(getPairLocalPort(deviceId).orElse(null)))
1209 .map(ConnectPoint::port)
1210 .collect(Collectors.toSet());
1211 }
1212
pierventre30368ab2021-02-24 23:23:22 +01001213 @Override
1214 public List<DeviceId> getEdgeDeviceIds() {
1215 return deviceConfiguration.getEdgeDeviceIds();
1216 }
1217
pierventre4f68ffa2021-03-09 22:52:14 +01001218 @Override
Charles Chana2401452021-06-03 15:57:48 -07001219 public List<DeviceId> getInfraDeviceIds() {
1220 return deviceConfiguration.getInfraDeviceIds();
1221 }
1222
1223 @Override
pierventre4f68ffa2021-03-09 22:52:14 +01001224 public MacAddress getDeviceMacAddress(DeviceId deviceId) throws DeviceConfigNotFoundException {
1225 return deviceConfiguration.getDeviceMac(deviceId);
1226 }
1227
Charles Chan3ed34d82017-06-22 18:03:14 -07001228 /**
Charles Chanf0ae41e2017-08-23 13:55:39 -07001229 * Returns locations of given resolved route.
1230 *
1231 * @param resolvedRoute resolved route
1232 * @return locations of nexthop. Might be empty if next hop is not found
1233 */
Charles Chan19b70032019-04-17 14:20:26 -07001234 public Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) {
Charles Chanf0ae41e2017-08-23 13:55:39 -07001235 HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan());
1236 return Optional.ofNullable(hostService.getHost(hostId))
1237 .map(Host::locations).orElse(Sets.newHashSet())
1238 .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet());
1239 }
1240
1241 /**
Charles Chan90772a72017-02-08 15:52:08 -08001242 * Returns vlan port map of given device.
1243 *
1244 * @param deviceId device id
1245 * @return vlan-port multimap
1246 */
1247 public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) {
1248 HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create();
1249
1250 interfaceService.getInterfaces().stream()
1251 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
1252 .forEach(intf -> {
1253 vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port());
Charles Chan3ed34d82017-06-22 18:03:14 -07001254 intf.vlanTagged().forEach(vlanTagged ->
1255 vlanPortMap.put(vlanTagged, intf.connectPoint().port())
1256 );
Charles Chan90772a72017-02-08 15:52:08 -08001257 vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port());
1258 });
1259 vlanPortMap.removeAll(VlanId.NONE);
1260
1261 return vlanPortMap;
1262 }
1263
1264 /**
Charles Chan10b0fb72017-02-02 16:20:42 -08001265 * Returns the next objective ID for the given vlan id. It is expected
Saurav Das2d94d312015-11-24 23:21:05 -08001266 * that the next-objective has been pre-created from configuration.
Charles Chan77277672015-10-20 16:24:19 -07001267 *
1268 * @param deviceId Device ID
Charles Chan10b0fb72017-02-02 16:20:42 -08001269 * @param vlanId VLAN ID
Saurav Das2d94d312015-11-24 23:21:05 -08001270 * @return next objective ID or -1 if it was not found
Charles Chan77277672015-10-20 16:24:19 -07001271 */
Charles Chan3ed34d82017-06-22 18:03:14 -07001272 int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) {
Charles Chan77277672015-10-20 16:24:19 -07001273 if (groupHandlerMap.get(deviceId) != null) {
Charles Chan10b0fb72017-02-02 16:20:42 -08001274 log.trace("getVlanNextObjectiveId query in device {}", deviceId);
1275 return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId);
Charles Chan77277672015-10-20 16:24:19 -07001276 } else {
Charles Chan10b0fb72017-02-02 16:20:42 -08001277 log.warn("getVlanNextObjectiveId query - groupHandler for "
Saurav Das2d94d312015-11-24 23:21:05 -08001278 + "device {} not found", deviceId);
1279 return -1;
1280 }
1281 }
1282
1283 /**
1284 * Returns the next objective ID for the given portNumber, given the treatment.
1285 * There could be multiple different treatments to the same outport, which
Saurav Das2cb38292017-03-29 19:09:17 -07001286 * would result in different objectives. If the next object does not exist,
1287 * and should be created, a new one is created and its id is returned.
Saurav Das2d94d312015-11-24 23:21:05 -08001288 *
1289 * @param deviceId Device ID
1290 * @param portNum port number on device for which NextObjective is queried
1291 * @param treatment the actions to apply on the packets (should include outport)
1292 * @param meta metadata passed into the creation of a Next Objective if necessary
Saurav Das2cb38292017-03-29 19:09:17 -07001293 * @param createIfMissing true if a next object should be created if not found
Saurav Das07c74602016-04-27 18:35:50 -07001294 * @return next objective ID or -1 if an error occurred during retrieval or creation
Saurav Das2d94d312015-11-24 23:21:05 -08001295 */
1296 public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum,
1297 TrafficTreatment treatment,
Saurav Das2cb38292017-03-29 19:09:17 -07001298 TrafficSelector meta,
1299 boolean createIfMissing) {
Saurav Das2d94d312015-11-24 23:21:05 -08001300 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
1301 if (ghdlr != null) {
Saurav Das2cb38292017-03-29 19:09:17 -07001302 return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing);
Saurav Das2d94d312015-11-24 23:21:05 -08001303 } else {
Charles Chanb7f75ac2016-01-11 18:28:54 -08001304 log.warn("getPortNextObjectiveId query - groupHandler for device {}"
1305 + " not found", deviceId);
1306 return -1;
1307 }
1308 }
1309
Saurav Das62ae6792017-05-15 15:34:25 -07001310 /**
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001311 * Returns the next Objective ID for the given mac and vlan, given the treatment.
1312 * There could be multiple different treatments to the same outport, which
1313 * would result in different objectives. If the next object does not exist,
1314 * and should be created, a new one is created and its id is returned.
1315 *
1316 * @param deviceId Device ID
1317 * @param macAddr mac of host for which Next ID is required.
1318 * @param vlanId vlan of host for which Next ID is required.
Ruchi Sahota07869322019-05-09 17:26:14 -04001319 * @param port port with which to create the Next Obj.
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001320 * @param createIfMissing true if a next object should be created if not found
1321 * @return next objective ID or -1 if an error occurred during retrieval or creation
1322 */
1323 public int getMacVlanNextObjectiveId(DeviceId deviceId, MacAddress macAddr, VlanId vlanId,
Ruchi Sahota07869322019-05-09 17:26:14 -04001324 PortNumber port, boolean createIfMissing) {
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001325 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
1326 if (ghdlr != null) {
Ruchi Sahota07869322019-05-09 17:26:14 -04001327 return ghdlr.getMacVlanNextObjectiveId(macAddr, vlanId, port, createIfMissing);
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001328 } else {
1329 log.warn("getMacVlanNextObjectiveId query - groupHandler for device {}"
1330 + " not found", deviceId);
1331 return -1;
1332 }
1333 }
1334
1335 /**
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001336 * Updates the next objective for the given nextId .
1337 *
1338 * @param deviceId Device ID
1339 * @param hostMac mac of host for which Next obj is to be updated.
1340 * @param hostVlanId vlan of host for which Next obj is to be updated.
1341 * @param port port with which to update the Next Obj.
1342 * @param nextId of Next Obj which needs to be updated.
1343 */
1344 public void updateMacVlanTreatment(DeviceId deviceId, MacAddress hostMac,
pierventrea3989be2021-01-08 16:43:17 +01001345 VlanId hostVlanId, PortNumber port, int nextId) {
pierventre37dcf4c2021-09-16 18:43:06 +02001346 // Check if we are the leader of this device
pierf0e37ec2019-11-26 11:48:48 +01001347 // just one instance should perform this update
1348 if (!defaultRoutingHandler.shouldProgram(deviceId)) {
1349 log.debug("This instance is not handling the routing towards the "
1350 + "device {}", deviceId);
1351 return;
1352 }
1353 // Get the handler and perform the update
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001354 DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId);
1355 if (ghdlr != null) {
1356 ghdlr.updateL3UcastGroupBucket(hostMac, hostVlanId, port, nextId);
1357 } else {
1358 log.warn("updateL3UcastGroupBucket query - groupHandler for device {}"
1359 + " not found", deviceId);
1360 }
1361 }
1362
1363
1364 /**
Saurav Das62ae6792017-05-15 15:34:25 -07001365 * Returns the group handler object for the specified device id.
1366 *
1367 * @param devId the device identifier
1368 * @return the groupHandler object for the device id, or null if not found
1369 */
Charles Chan3ed34d82017-06-22 18:03:14 -07001370 DefaultGroupHandler getGroupHandler(DeviceId devId) {
Saurav Das62ae6792017-05-15 15:34:25 -07001371 return groupHandlerMap.get(devId);
1372 }
1373
1374 /**
Saurav Dasfbe74572017-08-03 18:30:35 -07001375 * Returns the default routing handler object.
1376 *
1377 * @return the default routing handler object
1378 */
1379 public DefaultRoutingHandler getRoutingHandler() {
1380 return defaultRoutingHandler;
1381 }
1382
sangho80f11cb2015-04-01 13:05:26 -07001383 private class InternalPacketProcessor implements PacketProcessor {
sangho80f11cb2015-04-01 13:05:26 -07001384 @Override
1385 public void process(PacketContext context) {
Charles Chan77cdde42018-05-08 21:35:50 -07001386 packetExecutor.execute(() -> processPacketInternal(context));
1387 }
sangho80f11cb2015-04-01 13:05:26 -07001388
Charles Chan77cdde42018-05-08 21:35:50 -07001389 private void processPacketInternal(PacketContext context) {
sangho80f11cb2015-04-01 13:05:26 -07001390 if (context.isHandled()) {
1391 return;
1392 }
1393
1394 InboundPacket pkt = context.inPacket();
1395 Ethernet ethernet = pkt.parsed();
Pier Luigi37a35432017-02-01 13:50:04 -08001396
1397 if (ethernet == null) {
1398 return;
1399 }
1400
Saurav Das261c3002017-06-13 15:35:54 -07001401 log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
1402 ethernet);
Pier Ventreadb4ae62016-11-23 09:57:42 -08001403 if (ethernet.getEtherType() == TYPE_ARP) {
Saurav Das62ae6792017-05-15 15:34:25 -07001404 log.warn("Received unexpected ARP packet on {}",
1405 context.inPacket().receivedFrom());
Saurav Das368cf212017-03-15 15:15:14 -07001406 log.trace("{}", ethernet);
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001407 return;
sangho80f11cb2015-04-01 13:05:26 -07001408 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
Pier Ventreb6b81d52016-12-02 08:16:05 -08001409 IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
1410 //ipHandler.addToPacketBuffer(ipv4Packet);
1411 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
1412 icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001413 } else {
Charles Chand041ad82017-01-13 17:20:44 -08001414 // NOTE: We don't support IP learning at this moment so this
1415 // is not necessary. Also it causes duplication of DHCP packets.
Pier Ventre6b2c1b32016-12-09 17:26:04 -08001416 // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
sangho80f11cb2015-04-01 13:05:26 -07001417 }
Pier Ventreb6a7f342016-11-26 21:05:22 -08001418 } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
1419 IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
Pier Ventreb6b81d52016-12-02 08:16:05 -08001420 //ipHandler.addToPacketBuffer(ipv6Packet);
Pier Luigi37a35432017-02-01 13:50:04 -08001421 // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
Pier Ventreb6b81d52016-12-02 08:16:05 -08001422 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
1423 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
1424 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
1425 icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
1426 icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
1427 } else {
Saurav Das62ae6792017-05-15 15:34:25 -07001428 log.trace("Received ICMPv6 0x{} - not handled",
Charles Chand3727b72017-03-13 13:10:30 -07001429 Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
Pier Ventreb6b81d52016-12-02 08:16:05 -08001430 }
1431 } else {
1432 // NOTE: We don't support IP learning at this moment so this
1433 // is not necessary. Also it causes duplication of DHCPv6 packets.
1434 // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
1435 }
sangho80f11cb2015-04-01 13:05:26 -07001436 }
1437 }
1438 }
1439
sangho80f11cb2015-04-01 13:05:26 -07001440 private class InternalEventHandler implements Runnable {
Charles Chan52003922018-04-05 16:31:15 -07001441 private Event event;
1442
1443 InternalEventHandler(Event event) {
1444 this.event = event;
1445 }
1446
Srikanth Vavilapalli37a461b2015-04-07 15:12:32 -07001447 @Override
sangho80f11cb2015-04-01 13:05:26 -07001448 public void run() {
Charles Chan52003922018-04-05 16:31:15 -07001449 try {
1450 // TODO We should also change SR routing and PW to listen to TopologyEvents
1451 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1452 event.type() == LinkEvent.Type.LINK_UPDATED) {
1453 linkHandler.processLinkAdded((Link) event.subject());
1454 } else if (event.type() == LinkEvent.Type.LINK_REMOVED) {
1455 linkHandler.processLinkRemoved((Link) event.subject());
1456 } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED ||
1457 event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
1458 event.type() == DeviceEvent.Type.DEVICE_UPDATED) {
1459 DeviceId deviceId = ((Device) event.subject()).id();
1460 if (deviceService.isAvailable(deviceId)) {
1461 log.info("** DEVICE UP Processing device event {} "
1462 + "for available device {}",
1463 event.type(), ((Device) event.subject()).id());
1464 processDeviceAdded((Device) event.subject());
pierventre37dcf4c2021-09-16 18:43:06 +02001465 /*
1466 * This is a mere heuristic as there is not yet stable mastership in ONOS, and it is based on
1467 * the fact that DEVICE is marked online only if there is a master around. processDeviceAdded
1468 * can be called on config change and link events and there is no check of the availability.
1469 * In this scenarios, we could not have a master and pr is broken as nobody can admin enable
1470 * the ports. We keep in processDeviceAdded the code that is already idempotent
1471 */
1472 if (event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED) {
1473 phasedRecoveryService.init(deviceId);
1474 }
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001475 } else {
Charles Chanb8f3af52018-08-29 21:21:51 -07001476 if (event.type() == DeviceEvent.Type.DEVICE_ADDED) {
1477 // Note: For p4 devices, the device will be added but unavailable at the beginning.
1478 // The device will later on being marked as available once the pipeline is pushed
1479 // to the device.
1480 log.info("** DEVICE ADDED but unavailable. Ignore");
1481 return;
1482 }
Charles Chan52003922018-04-05 16:31:15 -07001483 log.info(" ** DEVICE DOWN Processing device event {}"
1484 + " for unavailable device {}",
1485 event.type(), ((Device) event.subject()).id());
1486 processDeviceRemoved((Device) event.subject());
Srikanth Vavilapalli64d96c12015-05-14 20:22:47 -07001487 }
Charles Chan52003922018-04-05 16:31:15 -07001488 } else if (event.type() == DeviceEvent.Type.PORT_ADDED) {
1489 // typically these calls come when device is added first time
1490 // so port filtering rules are handled at the device_added event.
1491 // port added calls represent all ports on the device,
1492 // enabled or not.
1493 log.trace("** PORT ADDED {}/{} -> {}",
1494 ((DeviceEvent) event).subject().id(),
1495 ((DeviceEvent) event).port().number(),
1496 event.type());
1497 } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) {
1498 // these calls happen for every subsequent event
1499 // ports enabled, disabled, switch goes away, comes back
1500 log.info("** PORT UPDATED {}/{} -> {}",
1501 event.subject(),
1502 ((DeviceEvent) event).port(),
1503 event.type());
Saurav Dasec683dc2018-04-27 18:42:30 -07001504 processPortUpdatedInternal(((Device) event.subject()),
Charles Chan52003922018-04-05 16:31:15 -07001505 ((DeviceEvent) event).port());
Harshada Chaundkar9204f312019-07-02 16:01:24 +00001506 mcastHandler.processPortUpdate(((Device) event.subject()),
1507 ((DeviceEvent) event).port());
Charles Chan52003922018-04-05 16:31:15 -07001508 } else if (event.type() == TopologyEvent.Type.TOPOLOGY_CHANGED) {
1509 // Process topology event, needed for all modules relying on
1510 // topology service for path computation
1511 TopologyEvent topologyEvent = (TopologyEvent) event;
1512 log.info("Processing topology event {}, topology age {}, reasons {}",
1513 event.type(), topologyEvent.subject().time(),
1514 topologyEvent.reasons().size());
1515 topologyHandler.processTopologyChange(topologyEvent.reasons());
1516 } else if (event.type() == HostEvent.Type.HOST_ADDED) {
1517 hostHandler.processHostAddedEvent((HostEvent) event);
1518 } else if (event.type() == HostEvent.Type.HOST_MOVED) {
1519 hostHandler.processHostMovedEvent((HostEvent) event);
1520 routeHandler.processHostMovedEvent((HostEvent) event);
Charles Chana2ccb582019-11-25 09:47:22 -08001521 } else if (event.type() == HostEvent.Type.HOST_AUX_MOVED) {
1522 hostHandler.processHostMovedEvent((HostEvent) event);
1523 // TODO RouteHandler also needs to process this event in order to
1524 // support nexthops that has auxLocations
Charles Chan52003922018-04-05 16:31:15 -07001525 } else if (event.type() == HostEvent.Type.HOST_REMOVED) {
1526 hostHandler.processHostRemovedEvent((HostEvent) event);
1527 } else if (event.type() == HostEvent.Type.HOST_UPDATED) {
1528 hostHandler.processHostUpdatedEvent((HostEvent) event);
1529 } else if (event.type() == RouteEvent.Type.ROUTE_ADDED) {
1530 routeHandler.processRouteAdded((RouteEvent) event);
1531 } else if (event.type() == RouteEvent.Type.ROUTE_UPDATED) {
1532 routeHandler.processRouteUpdated((RouteEvent) event);
1533 } else if (event.type() == RouteEvent.Type.ROUTE_REMOVED) {
1534 routeHandler.processRouteRemoved((RouteEvent) event);
1535 } else if (event.type() == RouteEvent.Type.ALTERNATIVE_ROUTES_CHANGED) {
1536 routeHandler.processAlternativeRoutesChanged((RouteEvent) event);
1537 } else if (event.type() == McastEvent.Type.SOURCES_ADDED ||
1538 event.type() == McastEvent.Type.SOURCES_REMOVED ||
1539 event.type() == McastEvent.Type.SINKS_ADDED ||
1540 event.type() == McastEvent.Type.SINKS_REMOVED ||
1541 event.type() == McastEvent.Type.ROUTE_ADDED ||
1542 event.type() == McastEvent.Type.ROUTE_REMOVED) {
1543 mcastHandler.processMcastEvent((McastEvent) event);
1544 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
1545 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1546 Class configClass = netcfgEvent.configClass();
1547 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1548 appCfgHandler.processAppConfigAdded(netcfgEvent);
1549 log.info("App config event .. configuring network");
pierventrec80a5052021-05-20 12:56:38 +02001550 cfgListener.configureNetworkAndDrainEvents();
Charles Chan52003922018-04-05 16:31:15 -07001551 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1552 log.info("Segment Routing Device Config added for {}", event.subject());
pierventrec80a5052021-05-20 12:56:38 +02001553 cfgListener.configureNetworkAndDrainEvents();
Charles Chan52003922018-04-05 16:31:15 -07001554 } else if (configClass.equals(InterfaceConfig.class)) {
1555 log.info("Interface Config added for {}", event.subject());
pierventrec80a5052021-05-20 12:56:38 +02001556 cfgListener.configureNetworkAndDrainEvents();
Charles Chan52003922018-04-05 16:31:15 -07001557 } else {
1558 log.error("Unhandled config class: {}", configClass);
1559 }
1560 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) {
1561 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1562 Class configClass = netcfgEvent.configClass();
1563 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1564 appCfgHandler.processAppConfigUpdated(netcfgEvent);
1565 log.info("App config event .. configuring network");
pierventrec80a5052021-05-20 12:56:38 +02001566 cfgListener.configureNetworkAndDrainEvents();
Charles Chan52003922018-04-05 16:31:15 -07001567 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1568 log.info("Segment Routing Device Config updated for {}", event.subject());
1569 createOrUpdateDeviceConfiguration();
Charles Chan52003922018-04-05 16:31:15 -07001570 } else if (configClass.equals(InterfaceConfig.class)) {
1571 log.info("Interface Config updated for {}", event.subject());
1572 createOrUpdateDeviceConfiguration();
1573 updateInterface((InterfaceConfig) netcfgEvent.config().get(),
1574 (InterfaceConfig) netcfgEvent.prevConfig().get());
1575 } else {
1576 log.error("Unhandled config class: {}", configClass);
1577 }
1578 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) {
1579 NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event;
1580 Class configClass = netcfgEvent.configClass();
1581 if (configClass.equals(SegmentRoutingAppConfig.class)) {
1582 appCfgHandler.processAppConfigRemoved(netcfgEvent);
1583 log.info("App config event .. configuring network");
pierventrec80a5052021-05-20 12:56:38 +02001584 cfgListener.configureNetworkAndDrainEvents();
Charles Chan52003922018-04-05 16:31:15 -07001585 } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) {
1586 // TODO Handle sr device config removal
1587 log.info("SegmentRoutingDeviceConfig removal is not handled in current implementation");
Charles Chan52003922018-04-05 16:31:15 -07001588 } else if (configClass.equals(InterfaceConfig.class)) {
1589 // TODO Handle interface removal
1590 log.info("InterfaceConfig removal is not handled in current implementation");
1591 } else {
1592 log.error("Unhandled config class: {}", configClass);
1593 }
Saurav Das00e553b2018-04-21 17:19:48 -07001594 } else if (event.type() == MastershipEvent.Type.MASTER_CHANGED) {
1595 MastershipEvent me = (MastershipEvent) event;
1596 DeviceId deviceId = me.subject();
pierventre37dcf4c2021-09-16 18:43:06 +02001597 log.info(" ** Mastership changed check full reroute for {} due to change", deviceId);
Saurav Das00e553b2018-04-21 17:19:48 -07001598 defaultRoutingHandler.checkFullRerouteForMasterChange(deviceId, me);
Charles Chana2401452021-06-03 15:57:48 -07001599
pierventre37dcf4c2021-09-16 18:43:06 +02001600 } else if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED ||
1601 event.type() == ClusterEvent.Type.INSTANCE_REMOVED) {
1602 log.info(" ** Cluster event invalidating shouldProgram");
1603 defaultRoutingHandler.invalidateShouldProgram();
Charles Chan52003922018-04-05 16:31:15 -07001604 } else {
1605 log.warn("Unhandled event type: {}", event.type());
sangho80f11cb2015-04-01 13:05:26 -07001606 }
Charles Chan52003922018-04-05 16:31:15 -07001607 } catch (Exception e) {
1608 log.error("SegmentRouting event handler thread thrown an exception: {}",
1609 e.getMessage(), e);
sangho80f11cb2015-04-01 13:05:26 -07001610 }
sangho80f11cb2015-04-01 13:05:26 -07001611 }
1612 }
1613
Saurav Dase6c448a2018-01-18 12:07:33 -08001614 void processDeviceAdded(Device device) {
Saurav Dasb149be12016-06-07 10:08:06 -07001615 log.info("** DEVICE ADDED with ID {}", device.id());
Charles Chan9bd6aea2017-06-27 18:48:32 -07001616
1617 // NOTE: Punt ARP/NDP even when the device is not configured.
1618 // Host learning without network config is required for CORD config generator.
1619 routingRulePopulator.populateIpPunts(device.id());
1620 routingRulePopulator.populateArpNdpPunts(device.id());
1621
Charles Chan319d1a22015-11-03 10:42:14 -08001622 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Saurav Das261c3002017-06-13 15:35:54 -07001623 log.warn("Device configuration unavailable. Device {} will be "
1624 + "processed after configuration.", device.id());
Saurav Das8ec0ec42015-11-03 14:39:27 -08001625 return;
1626 }
Charles Chan72779502016-04-23 17:36:10 -07001627 processDeviceAddedInternal(device.id());
1628 }
1629
1630 private void processDeviceAddedInternal(DeviceId deviceId) {
pierventre37dcf4c2021-09-16 18:43:06 +02001631 // Irrespective of whether the local is leading the programming or not for this device,
Saurav Dasc28b3432015-10-30 17:45:38 -07001632 // we need to create a SR-group-handler instance. This is because in a
1633 // multi-instance setup, any instance can initiate forwarding/next-objectives
1634 // for any switch (even if this instance is a SLAVE or not even connected
1635 // to the switch). To handle this, a default-group-handler instance is necessary
1636 // per switch.
Charles Chan72779502016-04-23 17:36:10 -07001637 log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet());
1638 if (groupHandlerMap.get(deviceId) == null) {
Charles Chan319d1a22015-11-03 10:42:14 -08001639 DefaultGroupHandler groupHandler;
1640 try {
1641 groupHandler = DefaultGroupHandler.
Charles Chan72779502016-04-23 17:36:10 -07001642 createGroupHandler(deviceId,
1643 appId,
1644 deviceConfiguration,
1645 linkService,
1646 flowObjectiveService,
1647 this);
Charles Chan319d1a22015-11-03 10:42:14 -08001648 } catch (DeviceConfigNotFoundException e) {
1649 log.warn(e.getMessage() + " Aborting processDeviceAdded.");
1650 return;
1651 }
Saurav Das2b6a00f2017-12-05 15:00:23 -08001652 log.debug("updating groupHandlerMap with new grpHdlr for device: {}",
Charles Chan72779502016-04-23 17:36:10 -07001653 deviceId);
1654 groupHandlerMap.put(deviceId, groupHandler);
Saurav Das8ec0ec42015-11-03 14:39:27 -08001655 }
Saurav Dasb149be12016-06-07 10:08:06 -07001656
pierventre37dcf4c2021-09-16 18:43:06 +02001657 if (shouldProgram(deviceId)) {
Saurav Dasf9332192017-02-18 14:05:44 -08001658 defaultRoutingHandler.populatePortAddressingRules(deviceId);
Charles Chan72779502016-04-23 17:36:10 -07001659 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
Charles Chan10b0fb72017-02-02 16:20:42 -08001660 groupHandler.createGroupsFromVlanConfig();
Charles Chan72779502016-04-23 17:36:10 -07001661 routingRulePopulator.populateSubnetBroadcastRule(deviceId);
Charles Chan77277672015-10-20 16:24:19 -07001662 }
Charles Chan82ab1932016-01-30 23:22:37 -08001663
Charles Chandebfea32016-10-24 14:52:01 -07001664 appCfgHandler.init(deviceId);
sangho80f11cb2015-04-01 13:05:26 -07001665 }
1666
Saurav Dasc3604f12016-03-23 11:22:49 -07001667 private void processDeviceRemoved(Device device) {
Saurav Das261c3002017-06-13 15:35:54 -07001668 dsNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001669 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan873661e2017-11-30 15:37:50 -08001670 .forEach(entry -> dsNextObjStore.remove(entry.getKey()));
Charles Chan10b0fb72017-02-02 16:20:42 -08001671 vlanNextObjStore.entrySet().stream()
Saurav Dasc3604f12016-03-23 11:22:49 -07001672 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001673 .forEach(entry -> vlanNextObjStore.remove(entry.getKey()));
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +00001674 macVlanNextObjStore.entrySet().stream()
1675 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
1676 .forEach(entry -> macVlanNextObjStore.remove(entry.getKey()));
Saurav Dasc3604f12016-03-23 11:22:49 -07001677 portNextObjStore.entrySet().stream()
1678 .filter(entry -> entry.getKey().deviceId().equals(device.id()))
Charles Chan3ed34d82017-06-22 18:03:14 -07001679 .forEach(entry -> portNextObjStore.remove(entry.getKey()));
Saurav Dase6c448a2018-01-18 12:07:33 -08001680 linkHandler.processDeviceRemoved(device);
Charles Chan17d75d82017-06-15 00:44:51 -07001681
Saurav Dasfbe74572017-08-03 18:30:35 -07001682 DefaultGroupHandler gh = groupHandlerMap.remove(device.id());
1683 if (gh != null) {
1684 gh.shutdown();
1685 }
Saurav Das62ae6792017-05-15 15:34:25 -07001686 // Note that a switch going down is associated with all of its links
1687 // going down as well, but it is treated as a single switch down event
Saurav Dasdebcf882018-04-06 20:16:01 -07001688 // while the link-downs are ignored. We cannot rely on the ordering of
1689 // events - i.e we cannot expect all link-downs to come before the
1690 // switch down - so we purge all seen-links for the switch before
1691 // handling route-path changes for the switch-down
Saurav Das62ae6792017-05-15 15:34:25 -07001692 defaultRoutingHandler
Saurav Dasdc7f2752018-03-18 21:28:15 -07001693 .populateRoutingRulesForLinkStatusChange(null, null, device.id(), true);
Saurav Das6430f412018-01-25 09:49:01 -08001694 defaultRoutingHandler.purgeEcmpGraph(device.id());
pierventre37dcf4c2021-09-16 18:43:06 +02001695 // Removes routes having as target the device down
1696 defaultRoutingHandler.purgeSeenBeforeRoutes(device.id());
Saurav Das97241862018-02-14 14:14:54 -08001697
1698 // Cleanup all internal groupHandler stores for this device. Should be
1699 // done after all rerouting or rehashing has been completed
1700 groupHandlerMap.entrySet()
1701 .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id()));
Charles Chan12a8a842020-02-14 13:23:57 -08001702
1703 phasedRecoveryService.reset(device.id());
Daniele Moro23fbbed2021-07-23 16:31:49 +02001704
1705 // Trigger purgeAll only on devices managed by SR, other devices rely on
1706 // the purgeOnDisconnection device property.
1707 if (deviceConfiguration.isConfigured(device.id())) {
1708 flowObjectiveService.purgeAll(device.id(), appId);
1709 }
Saurav Dasc3604f12016-03-23 11:22:49 -07001710 }
1711
Saurav Das49368392018-04-23 18:42:12 -07001712 /**
1713 * Purge the destinationSet nextObjective store of entries with this device
1714 * as key. Erases app-level knowledge of hashed groups in this device.
1715 *
1716 * @param devId the device identifier
1717 */
Saurav Das00e553b2018-04-21 17:19:48 -07001718 void purgeHashedNextObjectiveStore(DeviceId devId) {
Saurav Das49368392018-04-23 18:42:12 -07001719 log.debug("Purging hashed next-obj store for dev:{}", devId);
Saurav Das00e553b2018-04-21 17:19:48 -07001720 dsNextObjStore.entrySet().stream()
1721 .filter(entry -> entry.getKey().deviceId().equals(devId))
1722 .forEach(entry -> dsNextObjStore.remove(entry.getKey()));
1723 }
1724
Saurav Dasec683dc2018-04-27 18:42:30 -07001725 private void processPortUpdatedInternal(Device device, Port port) {
Saurav Dasf0f592d2016-11-18 15:21:57 -08001726 if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) {
Jon Hall5e41a7b2021-01-28 19:42:45 -08001727 log.warn("Device configuration uploading. Not handling port event for "
Saurav Dasf0f592d2016-11-18 15:21:57 -08001728 + "dev: {} port: {}", device.id(), port.number());
1729 return;
1730 }
Saurav Dasf9332192017-02-18 14:05:44 -08001731
Saurav Dasec683dc2018-04-27 18:42:30 -07001732 if (interfaceService.isConfigured(new ConnectPoint(device.id(), port.number()))) {
1733 lastEdgePortEvent = Instant.now();
1734 }
1735
pierventre633f35b2021-10-11 22:53:04 +02001736 if (!shouldProgram(device.id())) {
pierventre37dcf4c2021-09-16 18:43:06 +02001737 log.debug("Should not program dev:{} .. not handling port updated event "
Saurav Dasf9332192017-02-18 14:05:44 -08001738 + "for port {}", device.id(), port.number());
1739 return;
1740 }
Saurav Dasec683dc2018-04-27 18:42:30 -07001741 processPortUpdated(device.id(), port);
1742 }
Saurav Dasf9332192017-02-18 14:05:44 -08001743
Saurav Dasec683dc2018-04-27 18:42:30 -07001744 /**
1745 * Adds or remove filtering rules for the given switchport. If switchport is
1746 * an edge facing port, additionally handles host probing and broadcast
pierventre37dcf4c2021-09-16 18:43:06 +02001747 * rules. Must be called by the instance leading the programming of the device.
Saurav Dasec683dc2018-04-27 18:42:30 -07001748 *
1749 * @param deviceId the device identifier
1750 * @param port the port to update
1751 */
1752 void processPortUpdated(DeviceId deviceId, Port port) {
Saurav Dasf9332192017-02-18 14:05:44 -08001753 // first we handle filtering rules associated with the port
1754 if (port.isEnabled()) {
1755 log.info("Switchport {}/{} enabled..programming filters",
Saurav Dasec683dc2018-04-27 18:42:30 -07001756 deviceId, port.number());
1757 routingRulePopulator.processSinglePortFilters(deviceId, port.number(), true);
Saurav Dasf9332192017-02-18 14:05:44 -08001758 } else {
1759 log.info("Switchport {}/{} disabled..removing filters",
Saurav Dasec683dc2018-04-27 18:42:30 -07001760 deviceId, port.number());
1761 routingRulePopulator.processSinglePortFilters(deviceId, port.number(), false);
Saurav Dasf9332192017-02-18 14:05:44 -08001762 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001763
1764 // portUpdated calls are for ports that have gone down or up. For switch
1765 // to switch ports, link-events should take care of any re-routing or
1766 // group editing necessary for port up/down. Here we only process edge ports
1767 // that are already configured.
Saurav Dasec683dc2018-04-27 18:42:30 -07001768 ConnectPoint cp = new ConnectPoint(deviceId, port.number());
Charles Chan098ca202018-05-01 11:50:20 -07001769 VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp);
1770 VlanId nativeVlan = interfaceService.getNativeVlanId(cp);
1771 Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp);
Charles Chan10b0fb72017-02-02 16:20:42 -08001772
Saurav Das3fb28272017-03-04 16:08:47 -08001773 if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) {
Saurav Das62ae6792017-05-15 15:34:25 -07001774 log.debug("Not handling port updated event for non-edge port (unconfigured) "
Saurav Dasec683dc2018-04-27 18:42:30 -07001775 + "dev/port: {}/{}", deviceId, port.number());
Saurav Dasf0f592d2016-11-18 15:21:57 -08001776 return;
1777 }
Saurav Das3fb28272017-03-04 16:08:47 -08001778 if (untaggedVlan != null) {
Saurav Dasec683dc2018-04-27 18:42:30 -07001779 processEdgePort(deviceId, port, untaggedVlan, true);
Saurav Das3fb28272017-03-04 16:08:47 -08001780 }
1781 if (nativeVlan != null) {
Saurav Dasec683dc2018-04-27 18:42:30 -07001782 processEdgePort(deviceId, port, nativeVlan, true);
Saurav Das3fb28272017-03-04 16:08:47 -08001783 }
1784 if (!taggedVlans.isEmpty()) {
Saurav Dasec683dc2018-04-27 18:42:30 -07001785 taggedVlans.forEach(tag -> processEdgePort(deviceId, port, tag, false));
Saurav Das3fb28272017-03-04 16:08:47 -08001786 }
Saurav Dasf0f592d2016-11-18 15:21:57 -08001787 }
1788
Saurav Dasec683dc2018-04-27 18:42:30 -07001789 private void processEdgePort(DeviceId deviceId, Port port, VlanId vlanId,
Saurav Das3fb28272017-03-04 16:08:47 -08001790 boolean popVlan) {
Saurav Dasf0f592d2016-11-18 15:21:57 -08001791 boolean portUp = port.isEnabled();
1792 if (portUp) {
Saurav Dasec683dc2018-04-27 18:42:30 -07001793 log.info("Device:EdgePort {}:{} is enabled in vlan: {}", deviceId,
Charles Chan10b0fb72017-02-02 16:20:42 -08001794 port.number(), vlanId);
Charles Chan074fae62018-04-29 18:11:37 -07001795 hostEventExecutor.execute(() -> hostHandler.processPortUp(new ConnectPoint(deviceId, port.number())));
Saurav Dasf0f592d2016-11-18 15:21:57 -08001796 } else {
Saurav Dasec683dc2018-04-27 18:42:30 -07001797 log.info("Device:EdgePort {}:{} is disabled in vlan: {}", deviceId,
Charles Chan10b0fb72017-02-02 16:20:42 -08001798 port.number(), vlanId);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001799 }
1800
Saurav Dasec683dc2018-04-27 18:42:30 -07001801 DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId);
sangho80f11cb2015-04-01 13:05:26 -07001802 if (groupHandler != null) {
Saurav Das3fb28272017-03-04 16:08:47 -08001803 groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp);
Saurav Dasf0f592d2016-11-18 15:21:57 -08001804 } else {
1805 log.warn("Group handler not found for dev:{}. Not handling edge port"
Saurav Dasec683dc2018-04-27 18:42:30 -07001806 + " {} event for port:{}", deviceId,
Saurav Dasf0f592d2016-11-18 15:21:57 -08001807 (portUp) ? "UP" : "DOWN", port.number());
sangho80f11cb2015-04-01 13:05:26 -07001808 }
1809 }
sangho27462c62015-05-14 00:39:53 -07001810
Charles Chan8ca5a122017-10-20 16:06:55 -07001811 private void createOrUpdateDeviceConfiguration() {
1812 if (deviceConfiguration == null) {
Saurav Dase321cff2018-02-09 17:26:45 -08001813 log.info("Creating new DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001814 deviceConfiguration = new DeviceConfiguration(this);
1815 } else {
Saurav Dase321cff2018-02-09 17:26:45 -08001816 log.info("Updating DeviceConfiguration");
Charles Chan8ca5a122017-10-20 16:06:55 -07001817 deviceConfiguration.updateConfig();
1818 }
1819 }
1820
Charles Chanfbcb8812018-04-18 18:41:05 -07001821 private void createOrUpdateDefaultRoutingHandler() {
1822 if (defaultRoutingHandler == null) {
1823 log.info("Creating new DefaultRoutingHandler");
1824 defaultRoutingHandler = new DefaultRoutingHandler(this);
1825 } else {
1826 log.info("Updating DefaultRoutingHandler");
1827 defaultRoutingHandler.update(this);
1828 }
1829 }
1830
Pier Ventreb6a7f342016-11-26 21:05:22 -08001831 /**
1832 * Registers the given connect point with the NRS, this is necessary
1833 * to receive the NDP and ARP packets from the NRS.
1834 *
1835 * @param portToRegister connect point to register
1836 */
1837 public void registerConnectPoint(ConnectPoint portToRegister) {
Charles Chan2e71ef32017-02-23 15:44:08 -08001838 neighbourResolutionService.registerNeighbourHandler(
Pier Ventreb6a7f342016-11-26 21:05:22 -08001839 portToRegister,
1840 neighbourHandler,
1841 appId
1842 );
1843 }
1844
Charles Chan72f556a2015-10-05 17:50:33 -07001845 private class InternalConfigListener implements NetworkConfigListener {
Saurav Das261c3002017-06-13 15:35:54 -07001846 private static final long PROGRAM_DELAY = 2;
Charles Chan46fdfaf2016-11-09 20:51:44 -08001847 SegmentRoutingManager srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001848
Charles Chanb7f75ac2016-01-11 18:28:54 -08001849 /**
1850 * Constructs the internal network config listener.
1851 *
Charles Chan46fdfaf2016-11-09 20:51:44 -08001852 * @param srManager segment routing manager
Charles Chanb7f75ac2016-01-11 18:28:54 -08001853 */
Charles Chan3ed34d82017-06-22 18:03:14 -07001854 InternalConfigListener(SegmentRoutingManager srManager) {
Charles Chan46fdfaf2016-11-09 20:51:44 -08001855 this.srManager = srManager;
Charles Chane7c61022015-10-07 14:21:45 -07001856 }
1857
Charles Chanb7f75ac2016-01-11 18:28:54 -08001858 /**
1859 * Reads network config and initializes related data structure accordingly.
1860 */
Charles Chan873661e2017-11-30 15:37:50 -08001861 void configureNetwork() {
Saurav Dase321cff2018-02-09 17:26:45 -08001862 log.info("Configuring network ...");
Andrea Campanella060cad82018-04-17 12:09:34 +02001863
1864 // Setting handling of network configuration events completable future
1865 // The completable future is needed because of the async behaviour of the configureNetwork,
1866 // listener registration and event arrival
1867 // Enables us to buffer the events and execute them when the configure network is done.
Ray Milkey521e4392018-11-16 15:15:14 -08001868 synchronized (networkConfigCompletionLock) {
1869 networkConfigCompletion = new CompletableFuture<>();
Andrea Campanella060cad82018-04-17 12:09:34 +02001870
Ray Milkey521e4392018-11-16 15:15:14 -08001871 // add a small delay to absorb multiple network config added notifications
1872 if (!programmingScheduled.get()) {
1873 log.info("Buffering config calls for {} secs", PROGRAM_DELAY);
1874 programmingScheduled.set(true);
1875 mainEventExecutor.schedule(new ConfigChange(), PROGRAM_DELAY, TimeUnit.SECONDS);
1876 }
1877
1878 createOrUpdateDeviceConfiguration();
1879
1880 arpHandler = new ArpHandler(srManager);
1881 icmpHandler = new IcmpHandler(srManager);
1882 ipHandler = new IpHandler(srManager);
1883 routingRulePopulator = new RoutingRulePopulator(srManager);
1884 createOrUpdateDefaultRoutingHandler();
1885
1886 tunnelHandler = new TunnelHandler(linkService, deviceConfiguration,
1887 groupHandlerMap, tunnelStore);
1888 policyHandler = new PolicyHandler(appId, deviceConfiguration,
1889 flowObjectiveService,
1890 tunnelHandler, policyStore);
1891 networkConfigCompletion.complete(true);
Andrea Campanella060cad82018-04-17 12:09:34 +02001892 }
1893
Charles Chan72779502016-04-23 17:36:10 -07001894 mcastHandler.init();
Andrea Campanella060cad82018-04-17 12:09:34 +02001895
Charles Chane7c61022015-10-07 14:21:45 -07001896 }
1897
pierventrec80a5052021-05-20 12:56:38 +02001898 /**
1899 * Reads network config, initializes related data structure accordingly
1900 * and drain buffered events if needed.
1901 */
1902 void configureNetworkAndDrainEvents() {
1903 configureNetwork();
1904 drainEvents();
1905 }
1906
Charles Chan72f556a2015-10-05 17:50:33 -07001907 @Override
1908 public void event(NetworkConfigEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07001909 if (mainEventExecutor == null) {
1910 return;
1911 }
Charles Chan3f4aca62018-03-21 16:57:47 -07001912 checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized");
Charles Chan3f4aca62018-03-21 16:57:47 -07001913 switch (event.type()) {
1914 case CONFIG_ADDED:
1915 case CONFIG_UPDATED:
1916 case CONFIG_REMOVED:
Andrea Campanella060cad82018-04-17 12:09:34 +02001917 if (networkConfigCompletion == null || networkConfigCompletion.isDone()) {
Charles Chan152dd942020-07-21 15:33:31 -07001918 log.debug("Process netcfg {}", event);
Andrea Campanella060cad82018-04-17 12:09:34 +02001919 mainEventExecutor.execute(new InternalEventHandler(event));
1920 } else {
Charles Chan152dd942020-07-21 15:33:31 -07001921 log.debug("Queue netcfg {}", event);
Charles Chan39b75522018-04-21 00:44:29 -07001922 queuedEvents.add(event);
Andrea Campanella060cad82018-04-17 12:09:34 +02001923 }
Charles Chan3f4aca62018-03-21 16:57:47 -07001924 break;
1925 default:
1926 break;
Charles Chan72f556a2015-10-05 17:50:33 -07001927 }
1928 }
Saurav Das261c3002017-06-13 15:35:54 -07001929
Charles Chanc4a68c32018-01-03 16:26:32 -08001930 @Override
1931 public boolean isRelevant(NetworkConfigEvent event) {
Saurav Dase321cff2018-02-09 17:26:45 -08001932 if (event.type() == CONFIG_REGISTERED ||
1933 event.type() == CONFIG_UNREGISTERED) {
1934 log.debug("Ignore event {} due to type mismatch", event);
1935 return false;
Charles Chanc4a68c32018-01-03 16:26:32 -08001936 }
Saurav Dase321cff2018-02-09 17:26:45 -08001937
1938 if (!event.configClass().equals(SegmentRoutingDeviceConfig.class) &&
1939 !event.configClass().equals(SegmentRoutingAppConfig.class) &&
Charles Chana01d57c2019-07-19 16:25:38 -07001940 !event.configClass().equals(InterfaceConfig.class)) {
Saurav Dase321cff2018-02-09 17:26:45 -08001941 log.debug("Ignore event {} due to class mismatch", event);
1942 return false;
1943 }
1944
1945 return true;
Charles Chanc4a68c32018-01-03 16:26:32 -08001946 }
1947
Saurav Das261c3002017-06-13 15:35:54 -07001948 private final class ConfigChange implements Runnable {
1949 @Override
1950 public void run() {
1951 programmingScheduled.set(false);
Saurav Dase321cff2018-02-09 17:26:45 -08001952 log.info("Reacting to config changes after buffer delay");
Saurav Das261c3002017-06-13 15:35:54 -07001953 for (Device device : deviceService.getDevices()) {
1954 processDeviceAdded(device);
pierventre37f18d02022-05-12 22:18:20 +02001955 // Config changes can happen later and not close to the startup - let's react
1956 // only if the phased recovery is not running and we should program the device
1957 if (shouldProgram(device.id()) &&
1958 phasedRecoveryService.getPhase(device.id()) == Phase.EDGE) {
1959 // This should fix the unicast fwd
1960 initHost(device.id());
1961 initRoute(device.id());
1962 // This should fix port based tables, unicast and bdrcast fwd
1963 for (Port port : deviceService.getPorts(device.id())) {
1964 processPortUpdatedInternal(device, port);
1965 }
1966 } else {
1967 log.debug("Skipping init of hosts and routes after config changes" +
1968 " - not handling programming for dev:{} or phased" +
1969 " recovery is still running", device.id());
1970 }
Saurav Das261c3002017-06-13 15:35:54 -07001971 }
1972 defaultRoutingHandler.startPopulationProcess();
1973 }
1974 }
Charles Chan72f556a2015-10-05 17:50:33 -07001975 }
Charles Chanf4586112015-11-09 16:37:23 -08001976
Charles Chan3f4aca62018-03-21 16:57:47 -07001977 private class InternalLinkListener implements LinkListener {
1978 @Override
1979 public void event(LinkEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07001980 if (mainEventExecutor == null) {
1981 return;
1982 }
Charles Chan3f4aca62018-03-21 16:57:47 -07001983 if (event.type() == LinkEvent.Type.LINK_ADDED ||
1984 event.type() == LinkEvent.Type.LINK_UPDATED ||
1985 event.type() == LinkEvent.Type.LINK_REMOVED) {
1986 log.trace("Schedule Link event {}", event);
Andrea Campanella060cad82018-04-17 12:09:34 +02001987 if (networkConfigCompletion == null || networkConfigCompletion.isDone()) {
1988 mainEventExecutor.execute(new InternalEventHandler(event));
1989 } else {
Charles Chan39b75522018-04-21 00:44:29 -07001990 queuedEvents.add(event);
Andrea Campanella060cad82018-04-17 12:09:34 +02001991 }
Charles Chan3f4aca62018-03-21 16:57:47 -07001992 }
1993 }
1994 }
1995
1996 private class InternalDeviceListener implements DeviceListener {
1997 @Override
1998 public void event(DeviceEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07001999 if (mainEventExecutor == null) {
2000 return;
2001 }
Charles Chan3f4aca62018-03-21 16:57:47 -07002002 switch (event.type()) {
2003 case DEVICE_ADDED:
2004 case PORT_UPDATED:
2005 case PORT_ADDED:
2006 case DEVICE_UPDATED:
2007 case DEVICE_AVAILABILITY_CHANGED:
2008 log.trace("Schedule Device event {}", event);
Andrea Campanella060cad82018-04-17 12:09:34 +02002009 if (networkConfigCompletion == null || networkConfigCompletion.isDone()) {
2010 mainEventExecutor.execute(new InternalEventHandler(event));
2011 } else {
Charles Chan39b75522018-04-21 00:44:29 -07002012 queuedEvents.add(event);
Andrea Campanella060cad82018-04-17 12:09:34 +02002013 }
Charles Chan3f4aca62018-03-21 16:57:47 -07002014 break;
2015 default:
2016 }
2017 }
2018 }
2019
2020 private class InternalTopologyListener implements TopologyListener {
2021 @Override
2022 public void event(TopologyEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07002023 if (mainEventExecutor == null) {
2024 return;
2025 }
Charles Chan3f4aca62018-03-21 16:57:47 -07002026 switch (event.type()) {
2027 case TOPOLOGY_CHANGED:
2028 log.trace("Schedule Topology event {}", event);
Andrea Campanella060cad82018-04-17 12:09:34 +02002029 if (networkConfigCompletion == null || networkConfigCompletion.isDone()) {
2030 mainEventExecutor.execute(new InternalEventHandler(event));
2031 } else {
Charles Chan39b75522018-04-21 00:44:29 -07002032 queuedEvents.add(event);
Andrea Campanella060cad82018-04-17 12:09:34 +02002033 }
Charles Chan3f4aca62018-03-21 16:57:47 -07002034 break;
2035 default:
2036 }
2037 }
2038 }
2039
Charles Chanf4586112015-11-09 16:37:23 -08002040 private class InternalHostListener implements HostListener {
Charles Chanf4586112015-11-09 16:37:23 -08002041 @Override
2042 public void event(HostEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07002043 if (hostEventExecutor == null) {
2044 return;
2045 }
Charles Chanf4586112015-11-09 16:37:23 -08002046 switch (event.type()) {
2047 case HOST_ADDED:
Charles Chanf4586112015-11-09 16:37:23 -08002048 case HOST_MOVED:
Charles Chanf4586112015-11-09 16:37:23 -08002049 case HOST_REMOVED:
Charles Chanf4586112015-11-09 16:37:23 -08002050 case HOST_UPDATED:
Charles Chan3f4aca62018-03-21 16:57:47 -07002051 log.trace("Schedule Host event {}", event);
Charles Chandbbbb8a2018-04-07 11:35:08 -07002052 hostEventExecutor.execute(new InternalEventHandler(event));
Charles Chanf4586112015-11-09 16:37:23 -08002053 break;
2054 default:
2055 log.warn("Unsupported host event type: {}", event.type());
2056 break;
2057 }
2058 }
2059 }
2060
Charles Chanc91c8782016-03-30 17:54:24 -07002061 private class InternalMcastListener implements McastListener {
2062 @Override
2063 public void event(McastEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07002064 if (mcastEventExecutor == null) {
2065 return;
2066 }
Charles Chanc91c8782016-03-30 17:54:24 -07002067 switch (event.type()) {
Pier1f87aca2018-03-14 16:47:32 -07002068 case SOURCES_ADDED:
2069 case SOURCES_REMOVED:
2070 case SINKS_ADDED:
2071 case SINKS_REMOVED:
Charles Chanc91c8782016-03-30 17:54:24 -07002072 case ROUTE_REMOVED:
Pierdb27b8d2018-04-17 16:29:56 +02002073 case ROUTE_ADDED:
Charles Chan3f4aca62018-03-21 16:57:47 -07002074 log.trace("Schedule Mcast event {}", event);
Charles Chandbbbb8a2018-04-07 11:35:08 -07002075 mcastEventExecutor.execute(new InternalEventHandler(event));
Pier Luigi6786b922018-02-02 16:19:11 +01002076 break;
Charles Chanc91c8782016-03-30 17:54:24 -07002077 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07002078 log.warn("Unsupported mcast event type: {}", event.type());
Charles Chanc91c8782016-03-30 17:54:24 -07002079 break;
2080 }
2081 }
2082 }
Charles Chan41f5ec02016-06-13 18:54:31 -07002083
Charles Chandebfea32016-10-24 14:52:01 -07002084 private class InternalRouteEventListener implements RouteListener {
2085 @Override
2086 public void event(RouteEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07002087 if (routeEventExecutor == null) {
2088 return;
2089 }
Charles Chandebfea32016-10-24 14:52:01 -07002090 switch (event.type()) {
2091 case ROUTE_ADDED:
Charles Chandebfea32016-10-24 14:52:01 -07002092 case ROUTE_UPDATED:
Charles Chandebfea32016-10-24 14:52:01 -07002093 case ROUTE_REMOVED:
Charles Chan910be6a2017-08-23 14:46:43 -07002094 case ALTERNATIVE_ROUTES_CHANGED:
Charles Chan3f4aca62018-03-21 16:57:47 -07002095 log.trace("Schedule Route event {}", event);
Charles Chandbbbb8a2018-04-07 11:35:08 -07002096 routeEventExecutor.execute(new InternalEventHandler(event));
Charles Chan910be6a2017-08-23 14:46:43 -07002097 break;
Charles Chandebfea32016-10-24 14:52:01 -07002098 default:
Charles Chan3f4aca62018-03-21 16:57:47 -07002099 log.warn("Unsupported route event type: {}", event.type());
Charles Chandebfea32016-10-24 14:52:01 -07002100 break;
2101 }
2102 }
2103 }
Saurav Das62ae6792017-05-15 15:34:25 -07002104
Charles Chanfbcb8812018-04-18 18:41:05 -07002105 private class InternalMastershipListener implements MastershipListener {
2106 @Override
2107 public void event(MastershipEvent event) {
Ray Milkeyaee4d3e2018-05-11 09:59:19 -07002108 if (mainEventExecutor == null) {
2109 return;
2110 }
Charles Chanfbcb8812018-04-18 18:41:05 -07002111 switch (event.type()) {
Saurav Das00e553b2018-04-21 17:19:48 -07002112 case MASTER_CHANGED:
2113 log.debug("Mastership event: {}/{}", event.subject(),
2114 event.roleInfo());
2115 mainEventExecutor.execute(new InternalEventHandler(event));
2116 break;
2117 case BACKUPS_CHANGED:
2118 case SUSPENDED:
2119 default:
2120 log.debug("Mastership event type {} not handled", event.type());
2121 break;
Charles Chanfbcb8812018-04-18 18:41:05 -07002122 }
2123 }
2124 }
2125
Saurav Das00e553b2018-04-21 17:19:48 -07002126 class InternalClusterListener implements ClusterEventListener {
2127 private Instant lastClusterEvent = Instant.EPOCH;
2128
2129 long timeSinceLastClusterEvent() {
2130 return Instant.now().toEpochMilli() - lastClusterEvent.toEpochMilli();
2131 }
2132
2133 @Override
2134 public void event(ClusterEvent event) {
pierventre60cea362021-11-10 12:37:11 +01002135 if (event.instanceType() == ClusterEvent.InstanceType.STORAGE) {
2136 log.debug("Skipping cluster event for {}", event.subject().id().id());
2137 return;
2138 }
2139
Saurav Das00e553b2018-04-21 17:19:48 -07002140 switch (event.type()) {
2141 case INSTANCE_ACTIVATED:
2142 case INSTANCE_ADDED:
2143 case INSTANCE_READY:
2144 log.debug("Cluster event {} ignored", event.type());
2145 break;
2146 case INSTANCE_DEACTIVATED:
2147 case INSTANCE_REMOVED:
2148 log.info("** Cluster event {}", event.type());
2149 lastClusterEvent = Instant.now();
pierventre37dcf4c2021-09-16 18:43:06 +02002150 mainEventExecutor.execute(new InternalEventHandler(event));
Saurav Das00e553b2018-04-21 17:19:48 -07002151 break;
2152 default:
2153 break;
2154 }
2155
2156 }
2157
2158 }
2159
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002160 private void updateInterface(InterfaceConfig conf, InterfaceConfig prevConf) {
2161 try {
2162 Set<Interface> intfs = conf.getInterfaces();
2163 Set<Interface> prevIntfs = prevConf.getInterfaces();
2164
2165 // Now we only handle one interface config at each port.
2166 if (intfs.size() != 1 || prevIntfs.size() != 1) {
2167 log.warn("Interface update aborted - one at a time is allowed, " +
2168 "but {} / {}(prev) received.", intfs.size(), prevIntfs.size());
2169 return;
2170 }
2171
Andrea Campanella060cad82018-04-17 12:09:34 +02002172 //The system is in an incoherent state, abort
2173 if (defaultRoutingHandler == null) {
2174 log.warn("Interface update aborted, defaultRoutingHandler is null");
2175 return;
2176 }
2177
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002178 Interface intf = intfs.stream().findFirst().get();
2179 Interface prevIntf = prevIntfs.stream().findFirst().get();
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002180 DeviceId deviceId = intf.connectPoint().deviceId();
2181 PortNumber portNum = intf.connectPoint().port();
pierventre0dcbf0e2021-10-11 13:07:09 +02002182
2183 if (!shouldProgram(deviceId)) {
2184 log.debug("Not leading the programming of {} skip update interface {}",
2185 deviceId, intf);
2186 return;
2187 }
2188
pierventrea3989be2021-01-08 16:43:17 +01002189 // We need to do nexthop update al least one time for each
2190 // interface config change. There is no difference when it is done;
2191 boolean updateNexthop = false;
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002192
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002193 removeSubnetConfig(prevIntf.connectPoint(),
2194 Sets.difference(new HashSet<>(prevIntf.ipAddressesList()),
2195 new HashSet<>(intf.ipAddressesList())));
2196
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002197 if (!prevIntf.vlanNative().equals(VlanId.NONE)
2198 && !prevIntf.vlanNative().equals(intf.vlanUntagged())
2199 && !prevIntf.vlanNative().equals(intf.vlanNative())) {
2200 if (intf.vlanTagged().contains(prevIntf.vlanNative())) {
2201 // Update filtering objective and L2IG group bucket
2202 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanNative(), false);
2203 } else {
pierventrea3989be2021-01-08 16:43:17 +01002204 // RemoveVlanNative - affected scenarios:
2205 // (T,N)->U; (T*,N)->U; (T,N)->(T,N); (T,N)->T
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002206 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanNative(), true, false);
pierventrea3989be2021-01-08 16:43:17 +01002207 // Update the nexthops of the indirect routes
2208 updateNexthop = true;
2209 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002210 }
2211 }
2212
2213 if (!prevIntf.vlanUntagged().equals(VlanId.NONE)
2214 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
2215 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
2216 if (intf.vlanTagged().contains(prevIntf.vlanUntagged())) {
pierventrea3989be2021-01-08 16:43:17 +01002217 // Update filtering objective and L2IG group bucket - affected scenarios:
2218 // U->(T*,N); U->T*
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002219 updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanUntagged(), false);
pierventrea3989be2021-01-08 16:43:17 +01002220 if (!updateNexthop) {
2221 updateNexthop = true;
2222 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
2223 }
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002224 } else {
pierventrea3989be2021-01-08 16:43:17 +01002225 // RemoveVlanUntagged - affected scenarios:
2226 // U->U; U->(T,N); U->T
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002227 updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanUntagged(), true, false);
pierventrea3989be2021-01-08 16:43:17 +01002228 if (!updateNexthop) {
2229 updateNexthop = true;
2230 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
2231 }
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002232 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002233 }
2234
2235 if (!prevIntf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
pierventrea3989be2021-01-08 16:43:17 +01002236 // RemoveVlanTagged - affected scenarios:
2237 // T->U; T->T; (T,N*)->U; (T,N)->(T,N)
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002238 Sets.difference(prevIntf.vlanTagged(), intf.vlanTagged()).stream()
2239 .filter(i -> !intf.vlanUntagged().equals(i))
2240 .filter(i -> !intf.vlanNative().equals(i))
2241 .forEach(vlanId -> updateVlanConfigInternal(
2242 deviceId, portNum, vlanId, false, false));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002243 }
2244
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002245 if (!intf.vlanNative().equals(VlanId.NONE)
2246 && !prevIntf.vlanNative().equals(intf.vlanNative())
2247 && !prevIntf.vlanUntagged().equals(intf.vlanNative())) {
2248 if (prevIntf.vlanTagged().contains(intf.vlanNative())) {
2249 // Update filtering objective and L2IG group bucket
2250 updatePortVlanTreatment(deviceId, portNum, intf.vlanNative(), true);
2251 } else {
pierventrea3989be2021-01-08 16:43:17 +01002252 // AddVlanNative - affected scenarios
2253 // U->(T,N); U->(T*,N); T->(T,N)
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002254 updateVlanConfigInternal(deviceId, portNum, intf.vlanNative(), true, true);
pierventrea3989be2021-01-08 16:43:17 +01002255 if (!updateNexthop) {
2256 updateNexthop = true;
2257 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
2258 }
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002259 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002260 }
2261
2262 if (!intf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) {
pierventrea3989be2021-01-08 16:43:17 +01002263 // AddVlanTagged - affected scenarios
2264 // U->T; U->(T,N*); T->T; (T,N)->(T,N)
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002265 Sets.difference(intf.vlanTagged(), prevIntf.vlanTagged()).stream()
2266 .filter(i -> !prevIntf.vlanUntagged().equals(i))
2267 .filter(i -> !prevIntf.vlanNative().equals(i))
2268 .forEach(vlanId -> updateVlanConfigInternal(
2269 deviceId, portNum, vlanId, false, true)
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002270 );
pierventrea3989be2021-01-08 16:43:17 +01002271
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002272 }
2273
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002274 if (!intf.vlanUntagged().equals(VlanId.NONE)
2275 && !prevIntf.vlanUntagged().equals(intf.vlanUntagged())
2276 && !prevIntf.vlanNative().equals(intf.vlanUntagged())) {
2277 if (prevIntf.vlanTagged().contains(intf.vlanUntagged())) {
pierventrea3989be2021-01-08 16:43:17 +01002278 // Update filtering objective and L2IG group bucket - affected scenarios
2279 // (T*,N)->U; T*->U
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002280 updatePortVlanTreatment(deviceId, portNum, intf.vlanUntagged(), true);
pierventrea3989be2021-01-08 16:43:17 +01002281 if (!updateNexthop) {
2282 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
2283 }
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002284 } else {
pierventrea3989be2021-01-08 16:43:17 +01002285 // AddVlanUntagged - affected scenarios
2286 // U->U; (T,N)->U; T->U
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002287 updateVlanConfigInternal(deviceId, portNum, intf.vlanUntagged(), true, true);
pierventrea3989be2021-01-08 16:43:17 +01002288 if (!updateNexthop) {
2289 routeEventExecutor.execute(() -> routeHandler.processIntfVlanUpdatedEvent(deviceId, portNum));
2290 }
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002291 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002292 }
2293 addSubnetConfig(prevIntf.connectPoint(),
2294 Sets.difference(new HashSet<>(intf.ipAddressesList()),
2295 new HashSet<>(prevIntf.ipAddressesList())));
2296 } catch (ConfigException e) {
2297 log.error("Error in configuration");
2298 }
2299 }
2300
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002301 private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum,
2302 VlanId vlanId, boolean pushVlan) {
2303 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
2304 if (grpHandler == null) {
2305 log.warn("Failed to retrieve group handler for device {}", deviceId);
2306 return;
2307 }
2308
2309 // Update filtering objective for a single port
2310 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false);
2311 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true);
2312
2313 if (getVlanNextObjectiveId(deviceId, vlanId) != -1) {
2314 // Update L2IG bucket of the port
2315 grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan);
2316 } else {
2317 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
2318 }
2319 }
2320
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002321 private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum,
2322 VlanId vlanId, boolean pushVlan, boolean install) {
2323 DefaultGroupHandler grpHandler = getGroupHandler(deviceId);
2324 if (grpHandler == null) {
2325 log.warn("Failed to retrieve group handler for device {}", deviceId);
2326 return;
2327 }
2328
2329 // Update filtering objective for a single port
2330 routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install);
2331
2332 // Update filtering objective for multicast ingress port
2333 mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install);
2334
2335 int nextId = getVlanNextObjectiveId(deviceId, vlanId);
2336
2337 if (nextId != -1 && !install) {
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002338 // Remove L2 Bridging rule and L3 Unicast rule to the host
pierventrea3989be2021-01-08 16:43:17 +01002339 ScheduledFuture<?> future = hostEventExecutor.schedule(
2340 () -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, vlanId, pushVlan, install),
2341 0, TimeUnit.SECONDS);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002342 // Remove broadcast forwarding rule and corresponding L2FG for VLAN
2343 // only if there is no port configured on that VLAN ID
2344 if (!getVlanPortMap(deviceId).containsKey(vlanId)) {
2345 // Remove broadcast forwarding rule for the VLAN
2346 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
2347 // Remove L2FG for VLAN
2348 grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan);
2349 } else {
Shibu Vijayakumar632dd642018-03-01 15:45:59 -08002350 // Remove a single port from L2FG
2351 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002352 }
pierventrea3989be2021-01-08 16:43:17 +01002353 // Before moving forward we have to be sure that processIntfVlanUpdatedEvent completed;
2354 try {
2355 future.get();
2356 } catch (InterruptedException | ExecutionException e) {
2357 log.warn("Exception caught when executing updateVlanConfigInternal future");
2358 }
Shibu Vijayakumar632dd642018-03-01 15:45:59 -08002359 // Remove L2IG of the port
2360 grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002361 } else if (install) {
Shibu Vijayakumar632dd642018-03-01 15:45:59 -08002362 // Create L2IG of the port
2363 grpHandler.createPortNextObjective(deviceId, portNum, vlanId, pushVlan);
2364 // Create L2 Bridging rule and L3 Unicast rule to the host
2365 hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum,
2366 vlanId, pushVlan, install));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002367 if (nextId != -1) {
2368 // Add a single port to L2FG
Jonghwan Hyuna4ce0aa2018-02-12 16:43:45 +09002369 grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install);
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002370 } else {
2371 // Create L2FG for VLAN
2372 grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum));
2373 routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install);
2374 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002375 } else {
2376 log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum);
2377 }
2378 }
2379
2380 private void removeSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
2381 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
2382 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
2383
2384 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
2385 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
2386 .filter(intf -> !intf.connectPoint().equals(cp))
2387 .flatMap(intf -> intf.ipAddressesList().stream())
2388 .collect(Collectors.toSet());
2389 // 1. Partial subnet population
2390 // Remove routing rules for removed subnet from previous configuration,
2391 // which does not also exist in other interfaces in the same device
2392 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
2393 .map(InterfaceIpAddress::subnetAddress)
2394 .collect(Collectors.toSet());
2395
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002396 Set<IpPrefix> subnetsToBeRevoked = ipPrefixSet.stream()
2397 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
2398 .collect(Collectors.toSet());
2399
2400 // Check if any of the subnets to be revoked is configured in the pairDevice.
2401 // If any, repopulate the subnet with pairDevice connectPoint instead of revoking.
2402 Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId());
2403 if (pairDevice.isPresent()) {
2404 Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get());
2405
2406 Set<IpPrefix> subnetsExistingInPairDevice = subnetsToBeRevoked.stream()
2407 .filter(ipPrefix -> pairDeviceIpPrefix.contains(ipPrefix))
2408 .collect(Collectors.toSet());
2409
2410 // Update the subnets existing in pair device with pair device connect point.
2411 if (!subnetsExistingInPairDevice.isEmpty()) {
2412 // PortNumber of connect point is not relevant in populate subnet and hence providing as ANY.
2413 ConnectPoint pairDeviceCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY);
2414 log.debug("Updating the subnets: {} with pairDevice connectPoint as it exists in the Pair device: {}",
2415 subnetsExistingInPairDevice, pairDeviceCp);
2416 defaultRoutingHandler.populateSubnet(Collections.singleton(pairDeviceCp), subnetsExistingInPairDevice);
2417 }
2418
2419 // Remove only the subnets that are not configured in the pairDevice.
2420 subnetsToBeRevoked = Sets.difference(subnetsToBeRevoked, subnetsExistingInPairDevice);
2421 }
2422
2423 if (!subnetsToBeRevoked.isEmpty()) {
2424 log.debug("Removing subnets for connectPoint: {}, subnets: {}", cp, subnetsToBeRevoked);
pierventre0dcbf0e2021-10-11 13:07:09 +02002425 defaultRoutingHandler.revokeSubnet(subnetsToBeRevoked, cp.deviceId());
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002426 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002427
2428 // 2. Interface IP punts
2429 // Remove IP punts for old Intf address
2430 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
2431 .map(InterfaceIpAddress::ipAddress)
2432 .collect(Collectors.toSet());
2433 ipAddressSet.stream()
2434 .map(InterfaceIpAddress::ipAddress)
2435 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
2436 .forEach(interfaceIpAddress ->
2437 routingRulePopulator.revokeSingleIpPunts(
2438 cp.deviceId(), interfaceIpAddress));
2439
2440 // 3. Host unicast routing rule
2441 // Remove unicast routing rule
Charles Chan074fae62018-04-29 18:11:37 -07002442 hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002443 }
2444
2445 private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
2446 Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().
2447 map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
2448
2449 Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream()
2450 .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId()))
2451 .filter(intf -> !intf.connectPoint().equals(cp))
2452 .flatMap(intf -> intf.ipAddressesList().stream())
2453 .collect(Collectors.toSet());
2454 // 1. Partial subnet population
2455 // Add routing rules for newly added subnet, which does not also exist in
2456 // other interfaces in the same device
2457 Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream()
2458 .map(InterfaceIpAddress::subnetAddress)
2459 .collect(Collectors.toSet());
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002460 Set<IpPrefix> subnetsToBePopulated = ipPrefixSet.stream()
2461 .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix))
2462 .collect(Collectors.toSet());
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002463
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002464 if (!subnetsToBePopulated.isEmpty()) {
2465 log.debug("Adding subnets for connectPoint: {}, subnets: {}", cp, subnetsToBePopulated);
2466
pierventre0dcbf0e2021-10-11 13:07:09 +02002467 // check if pair-device has the same subnet configured
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002468 Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId());
2469 if (pairDevice.isPresent()) {
2470 Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get());
2471
2472 Set<IpPrefix> subnetsToBePopulatedAsDualHomed = subnetsToBePopulated.stream()
pierventre0dcbf0e2021-10-11 13:07:09 +02002473 .filter(pairDeviceIpPrefix::contains)
Shibu Vijayakumar5e26f8c2020-01-07 11:45:09 +00002474 .collect(Collectors.toSet());
2475 Set<IpPrefix> subnetsToBePopulatedAsSingleHomed = Sets.difference(subnetsToBePopulated,
2476 subnetsToBePopulatedAsDualHomed);
2477
2478 if (!subnetsToBePopulatedAsSingleHomed.isEmpty()) {
2479 defaultRoutingHandler.populateSubnet(
2480 Collections.singleton(cp),
2481 subnetsToBePopulatedAsSingleHomed);
2482 }
2483
2484 if (!subnetsToBePopulatedAsDualHomed.isEmpty()) {
2485 Set<ConnectPoint> cpts = new HashSet<>();
2486 cpts.add(cp);
2487 // As Subnets is DualHomed adding the pairDevice also as ConnectPoint.
2488 // PortNumber of connect point is not relevant in populate subnet and hence providing as ANY.
2489 ConnectPoint pairCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY);
2490 cpts.add(pairCp);
2491
2492 log.debug("Adding DualHomed subnets for connectPoint: {} and its pair device: {}, subnets: {}",
2493 cp, pairCp, subnetsToBePopulatedAsDualHomed);
2494
2495 // populating the subnets as DualHomed
2496 defaultRoutingHandler.populateSubnet(
2497 cpts,
2498 subnetsToBePopulated);
2499
2500 // revoking the subnets populated in the device as it is now Dualhomed.
2501 defaultRoutingHandler.revokeSubnet(Collections.singleton(cp.deviceId()),
2502 subnetsToBePopulatedAsDualHomed);
2503 }
2504 } else {
2505 defaultRoutingHandler.populateSubnet(
2506 Collections.singleton(cp),
2507 subnetsToBePopulated);
2508 }
2509 }
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002510
2511 // 2. Interface IP punts
2512 // Add IP punts for new Intf address
2513 Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream()
2514 .map(InterfaceIpAddress::ipAddress)
2515 .collect(Collectors.toSet());
2516 ipAddressSet.stream()
2517 .map(InterfaceIpAddress::ipAddress)
2518 .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress))
2519 .forEach(interfaceIpAddress ->
2520 routingRulePopulator.populateSingleIpPunts(
2521 cp.deviceId(), interfaceIpAddress));
2522
2523 // 3. Host unicast routing rule
2524 // Add unicast routing rule
Charles Chan074fae62018-04-29 18:11:37 -07002525 hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true));
Jonghwan Hyune5ef7622017-08-25 17:48:36 -07002526 }
sangho80f11cb2015-04-01 13:05:26 -07002527}