sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 18 | import com.google.common.collect.HashMultimap; |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import com.google.common.collect.Multimap; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 22 | import com.google.common.collect.Sets; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 23 | import org.onlab.packet.Ethernet; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 24 | import org.onlab.packet.ICMP6; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 25 | import org.onlab.packet.IPv4; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 26 | import org.onlab.packet.IPv6; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 27 | import org.onlab.packet.IpAddress; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 28 | import org.onlab.packet.IpPrefix; |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 29 | import org.onlab.packet.MacAddress; |
Carmelo Cascone | 6100426 | 2020-01-16 13:36:02 -0800 | [diff] [blame] | 30 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 31 | import org.onlab.util.KryoNamespace; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 32 | import org.onlab.util.Tools; |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 33 | import org.onosproject.cfg.ComponentConfigService; |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 34 | import org.onosproject.cluster.ClusterEvent; |
| 35 | import org.onosproject.cluster.ClusterEventListener; |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 36 | import org.onosproject.cluster.ClusterService; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 37 | import org.onosproject.cluster.LeadershipService; |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 38 | import org.onosproject.cluster.NodeId; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 39 | import org.onosproject.core.ApplicationId; |
| 40 | import org.onosproject.core.CoreService; |
| 41 | import org.onosproject.event.Event; |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 42 | import org.onosproject.mastership.MastershipEvent; |
| 43 | import org.onosproject.mastership.MastershipListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 44 | import org.onosproject.mastership.MastershipService; |
Pier | 1f87aca | 2018-03-14 16:47:32 -0700 | [diff] [blame] | 45 | import org.onosproject.mcast.api.McastEvent; |
| 46 | import org.onosproject.mcast.api.McastListener; |
| 47 | import org.onosproject.mcast.api.MulticastRouteService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 48 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 49 | import org.onosproject.net.Device; |
| 50 | import org.onosproject.net.DeviceId; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 51 | import org.onosproject.net.Host; |
| 52 | import org.onosproject.net.HostId; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 53 | import org.onosproject.net.Link; |
| 54 | import org.onosproject.net.Port; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 55 | import org.onosproject.net.PortNumber; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 56 | import org.onosproject.net.config.ConfigException; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 57 | import org.onosproject.net.config.ConfigFactory; |
| 58 | import org.onosproject.net.config.NetworkConfigEvent; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 59 | import org.onosproject.net.config.NetworkConfigListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 60 | import org.onosproject.net.config.NetworkConfigRegistry; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 61 | import org.onosproject.net.config.basics.InterfaceConfig; |
| 62 | import org.onosproject.net.config.basics.McastConfig; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 63 | import org.onosproject.net.config.basics.SubjectFactories; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 64 | import org.onosproject.net.device.DeviceAdminService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 65 | import org.onosproject.net.device.DeviceEvent; |
| 66 | import org.onosproject.net.device.DeviceListener; |
| 67 | import org.onosproject.net.device.DeviceService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 68 | import org.onosproject.net.flow.TrafficSelector; |
| 69 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 70 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 71 | import org.onosproject.net.flowobjective.NextObjective; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 72 | import org.onosproject.net.host.HostEvent; |
| 73 | import org.onosproject.net.host.HostListener; |
Charles Chan | c6bcdf9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 74 | import org.onosproject.net.host.HostProbingService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 75 | import org.onosproject.net.host.HostService; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 76 | import org.onosproject.net.host.InterfaceIpAddress; |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 77 | import org.onosproject.net.intent.WorkPartitionService; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 78 | import org.onosproject.net.intf.Interface; |
| 79 | import org.onosproject.net.intf.InterfaceService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 80 | import org.onosproject.net.link.LinkEvent; |
| 81 | import org.onosproject.net.link.LinkListener; |
| 82 | import org.onosproject.net.link.LinkService; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 83 | import org.onosproject.net.neighbour.NeighbourResolutionService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 84 | import org.onosproject.net.packet.InboundPacket; |
| 85 | import org.onosproject.net.packet.PacketContext; |
| 86 | import org.onosproject.net.packet.PacketProcessor; |
| 87 | import org.onosproject.net.packet.PacketService; |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 88 | import org.onosproject.net.topology.TopologyEvent; |
| 89 | import org.onosproject.net.topology.TopologyListener; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 90 | import org.onosproject.net.topology.TopologyService; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 91 | import org.onosproject.routeservice.ResolvedRoute; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 92 | import org.onosproject.routeservice.RouteEvent; |
| 93 | import org.onosproject.routeservice.RouteListener; |
| 94 | import org.onosproject.routeservice.RouteService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 95 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 96 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 97 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 98 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 99 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 100 | import org.onosproject.segmentrouting.grouphandler.DestinationSet; |
| 101 | import org.onosproject.segmentrouting.grouphandler.NextNeighbors; |
Harshada Chaundkar | 9204f31 | 2019-07-02 16:01:24 +0000 | [diff] [blame] | 102 | import org.onosproject.segmentrouting.mcast.McastFilteringObjStoreKey; |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 103 | import org.onosproject.segmentrouting.mcast.McastHandler; |
| 104 | import org.onosproject.segmentrouting.mcast.McastRole; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 105 | import org.onosproject.segmentrouting.mcast.McastRoleStoreKey; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 106 | import org.onosproject.segmentrouting.mcast.McastStoreKey; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 107 | import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel; |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 108 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 109 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 110 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 111 | import org.onosproject.segmentrouting.pwaas.L2Tunnel; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 112 | import org.onosproject.segmentrouting.pwaas.L2TunnelDescription; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 113 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 114 | import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 115 | import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey; |
Carmelo Cascone | 6100426 | 2020-01-16 13:36:02 -0800 | [diff] [blame] | 116 | import org.onosproject.segmentrouting.storekey.MacVlanNextObjectiveStoreKey; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 117 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 118 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 119 | import org.onosproject.segmentrouting.storekey.XConnectStoreKey; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 120 | import org.onosproject.segmentrouting.xconnect.api.XconnectService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 121 | import org.onosproject.store.serializers.KryoNamespaces; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 122 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 123 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
| 124 | import org.onosproject.store.service.StorageService; |
| 125 | import org.onosproject.store.service.WallClockTimestamp; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 126 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 127 | import org.osgi.service.component.annotations.Activate; |
| 128 | import org.osgi.service.component.annotations.Component; |
| 129 | import org.osgi.service.component.annotations.Deactivate; |
| 130 | import org.osgi.service.component.annotations.Modified; |
| 131 | import org.osgi.service.component.annotations.Reference; |
| 132 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Charles Chan | b4f9cd1 | 2019-02-27 11:46:32 -0800 | [diff] [blame] | 133 | import org.osgi.service.component.annotations.ReferencePolicy; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 134 | import org.slf4j.Logger; |
| 135 | import org.slf4j.LoggerFactory; |
| 136 | |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 137 | import java.time.Instant; |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 138 | import java.util.ArrayList; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 139 | import java.util.Collections; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 140 | import java.util.Dictionary; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 141 | import java.util.HashSet; |
| 142 | import java.util.List; |
| 143 | import java.util.Map; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 144 | import java.util.Optional; |
| 145 | import java.util.Set; |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 146 | import java.util.concurrent.CompletableFuture; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 147 | import java.util.concurrent.ConcurrentHashMap; |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 148 | import java.util.concurrent.CopyOnWriteArrayList; |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 149 | import java.util.concurrent.ExecutorService; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 150 | import java.util.concurrent.Executors; |
| 151 | import java.util.concurrent.ScheduledExecutorService; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 152 | import java.util.concurrent.TimeUnit; |
| 153 | import java.util.concurrent.atomic.AtomicBoolean; |
| 154 | import java.util.stream.Collectors; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 155 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 156 | import static com.google.common.base.Preconditions.checkState; |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 157 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 158 | import static org.onlab.util.Tools.groupedThreads; |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 159 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REGISTERED; |
| 160 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UNREGISTERED; |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 161 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.ACTIVE_PROBING_DEFAULT; |
| 162 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.DEFAULT_INTERNAL_VLAN_DEFAULT; |
| 163 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ACTIVE_PROBING; |
| 164 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_DEFAULT_INTERNAL_VLAN; |
| 165 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_PW_TRANSPORT_VLAN; |
| 166 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_RESPOND_TO_UNKNOWN_HOSTS; |
| 167 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ROUTE_DOUBLE_TAGGED_HOSTS; |
psneha | 86e60d3 | 2019-03-26 06:31:41 -0400 | [diff] [blame] | 168 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ROUTE_SIMPLIFICATION; |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 169 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_SINGLE_HOMED_DOWN; |
Ray Milkey | e96d0de | 2018-11-02 17:12:21 -0700 | [diff] [blame] | 170 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_SYMMETRIC_PROBING; |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 171 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PW_TRANSPORT_VLAN_DEFAULT; |
| 172 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.RESPOND_TO_UNKNOWN_HOSTS_DEFAULT; |
| 173 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT; |
psneha | 86e60d3 | 2019-03-26 06:31:41 -0400 | [diff] [blame] | 174 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.ROUTE_SIMPLIFICATION_DEFAULT; |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 175 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.SINGLE_HOMED_DOWN_DEFAULT; |
Ray Milkey | e96d0de | 2018-11-02 17:12:21 -0700 | [diff] [blame] | 176 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.SYMMETRIC_PROBING_DEFAULT; |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 177 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 178 | /** |
| 179 | * Segment routing manager. |
| 180 | */ |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 181 | @Component( |
| 182 | immediate = true, |
| 183 | service = SegmentRoutingService.class, |
| 184 | property = { |
| 185 | PROP_ACTIVE_PROBING + ":Boolean=" + ACTIVE_PROBING_DEFAULT, |
| 186 | PROP_SINGLE_HOMED_DOWN + ":Boolean=" + SINGLE_HOMED_DOWN_DEFAULT, |
| 187 | PROP_RESPOND_TO_UNKNOWN_HOSTS + ":Boolean=" + RESPOND_TO_UNKNOWN_HOSTS_DEFAULT, |
| 188 | PROP_ROUTE_DOUBLE_TAGGED_HOSTS + ":Boolean=" + ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT, |
| 189 | PROP_DEFAULT_INTERNAL_VLAN + ":Integer=" + DEFAULT_INTERNAL_VLAN_DEFAULT, |
| 190 | PROP_PW_TRANSPORT_VLAN + ":Integer=" + PW_TRANSPORT_VLAN_DEFAULT, |
psneha | 86e60d3 | 2019-03-26 06:31:41 -0400 | [diff] [blame] | 191 | PROP_SYMMETRIC_PROBING + ":Boolean=" + SYMMETRIC_PROBING_DEFAULT, |
| 192 | PROP_ROUTE_SIMPLIFICATION + ":Boolean=" + ROUTE_SIMPLIFICATION_DEFAULT |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 193 | } |
| 194 | ) |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 195 | public class SegmentRoutingManager implements SegmentRoutingService { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 196 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 197 | private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 198 | private static final String NOT_MASTER = "Current instance is not the master of {}. Ignore."; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 199 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 200 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 201 | private ComponentConfigService compCfgService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 202 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 203 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | cf78982 | 2019-03-22 10:04:27 -0700 | [diff] [blame] | 204 | public NeighbourResolutionService neighbourResolutionService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 205 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 206 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 207 | public CoreService coreService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 208 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 209 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 210 | PacketService packetService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 211 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 212 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 213 | HostService hostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 214 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 215 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | c6bcdf9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 216 | HostProbingService probingService; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 217 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 218 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 219 | public DeviceService deviceService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 220 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 221 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 222 | DeviceAdminService deviceAdminService; |
| 223 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 224 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 225 | public FlowObjectiveService flowObjectiveService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 226 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 227 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 228 | public LinkService linkService; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 229 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 230 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 231 | public MastershipService mastershipService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 232 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 233 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 234 | public StorageService storageService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 235 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 236 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 237 | public MulticastRouteService multicastRouteService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 238 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 239 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8316381 | 2018-01-09 13:45:07 -0800 | [diff] [blame] | 240 | public TopologyService topologyService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 241 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 242 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 19b7003 | 2019-04-17 14:20:26 -0700 | [diff] [blame] | 243 | public RouteService routeService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 244 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 245 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 246 | public NetworkConfigRegistry cfgService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 247 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 248 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 249 | public InterfaceService interfaceService; |
| 250 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 251 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 252 | public ClusterService clusterService; |
| 253 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 254 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 255 | public WorkPartitionService workPartitionService; |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 256 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 257 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 258 | public LeadershipService leadershipService; |
| 259 | |
Charles Chan | b4f9cd1 | 2019-02-27 11:46:32 -0800 | [diff] [blame] | 260 | @Reference(cardinality = ReferenceCardinality.OPTIONAL, |
Charles Chan | b4f9cd1 | 2019-02-27 11:46:32 -0800 | [diff] [blame] | 261 | policy = ReferencePolicy.DYNAMIC) |
Carmelo Cascone | 6100426 | 2020-01-16 13:36:02 -0800 | [diff] [blame] | 262 | public volatile XconnectService xconnectService; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 263 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 264 | /** Enable active probing to discover dual-homed hosts. */ |
| 265 | boolean activeProbing = ACTIVE_PROBING_DEFAULT; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 266 | |
Ray Milkey | e96d0de | 2018-11-02 17:12:21 -0700 | [diff] [blame] | 267 | /** Enable only send probe on the same port number of the pair device. */ |
| 268 | boolean symmetricProbing = SYMMETRIC_PROBING_DEFAULT; |
Mayank Tiwari | f794240 | 2018-10-29 18:27:35 -0400 | [diff] [blame] | 269 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 270 | /** Enable administratively taking down single-homed hosts. */ |
| 271 | boolean singleHomedDown = SINGLE_HOMED_DOWN_DEFAULT; |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 272 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 273 | /** Enable this to respond to ARP/NDP requests from unknown hosts. */ |
| 274 | boolean respondToUnknownHosts = RESPOND_TO_UNKNOWN_HOSTS_DEFAULT; |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 275 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 276 | /** Program flows and groups to pop and route double tagged hosts. */ |
| 277 | boolean routeDoubleTaggedHosts = ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT; |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 278 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 279 | /** internal vlan assigned by default to unconfigured ports. */ |
| 280 | private int defaultInternalVlan = DEFAULT_INTERNAL_VLAN_DEFAULT; |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 281 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 282 | /** vlan used for transport of pseudowires between switches. */ |
| 283 | private int pwTransportVlan = PW_TRANSPORT_VLAN_DEFAULT; |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 284 | |
psneha | 86e60d3 | 2019-03-26 06:31:41 -0400 | [diff] [blame] | 285 | /** Enabling route simplification. */ |
| 286 | boolean routeSimplification = ROUTE_SIMPLIFICATION_DEFAULT; |
| 287 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 288 | ArpHandler arpHandler = null; |
| 289 | IcmpHandler icmpHandler = null; |
| 290 | IpHandler ipHandler = null; |
| 291 | RoutingRulePopulator routingRulePopulator = null; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 292 | ApplicationId appId; |
| 293 | DeviceConfiguration deviceConfiguration = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 294 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 295 | DefaultRoutingHandler defaultRoutingHandler = null; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 296 | private TunnelHandler tunnelHandler = null; |
| 297 | private PolicyHandler policyHandler = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 298 | private InternalPacketProcessor processor = null; |
| 299 | private InternalLinkListener linkListener = null; |
| 300 | private InternalDeviceListener deviceListener = null; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 301 | private AppConfigHandler appCfgHandler = null; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 302 | McastHandler mcastHandler = null; |
| 303 | HostHandler hostHandler = null; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 304 | private RouteHandler routeHandler = null; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 305 | LinkHandler linkHandler = null; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 306 | private SegmentRoutingNeighbourDispatcher neighbourHandler = null; |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 307 | private DefaultL2TunnelHandler l2TunnelHandler = null; |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 308 | private TopologyHandler topologyHandler = null; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 309 | private final InternalHostListener hostListener = new InternalHostListener(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 310 | private final InternalConfigListener cfgListener = new InternalConfigListener(this); |
| 311 | private final InternalMcastListener mcastListener = new InternalMcastListener(); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 312 | private final InternalRouteEventListener routeListener = new InternalRouteEventListener(); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 313 | private final InternalTopologyListener topologyListener = new InternalTopologyListener(); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 314 | private final InternalMastershipListener mastershipListener = new InternalMastershipListener(); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 315 | final InternalClusterListener clusterListener = new InternalClusterListener(); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 316 | //Completable future for network configuration process to buffer config events handling during activation |
| 317 | private CompletableFuture<Boolean> networkConfigCompletion = null; |
Ray Milkey | 521e439 | 2018-11-16 15:15:14 -0800 | [diff] [blame] | 318 | private final Object networkConfigCompletionLock = new Object(); |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 319 | private List<Event> queuedEvents = new CopyOnWriteArrayList<>(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 320 | |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 321 | // Handles device, link, topology and network config events |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 322 | private ScheduledExecutorService mainEventExecutor; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 323 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 324 | // Handles host, route and mcast events respectively |
| 325 | private ScheduledExecutorService hostEventExecutor; |
| 326 | private ScheduledExecutorService routeEventExecutor; |
| 327 | private ScheduledExecutorService mcastEventExecutor; |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 328 | private ExecutorService packetExecutor; |
Charles Chan | a7601c9 | 2019-01-23 15:03:17 -0800 | [diff] [blame] | 329 | ExecutorService neighborExecutor; |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 330 | |
| 331 | Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<>(); |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 332 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 333 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 334 | * Used to keep track on MPLS group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 335 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 336 | private EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 337 | dsNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 338 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 339 | * Per device next objective ID store with (device id + vlanid) as key. |
| 340 | * Used to keep track on L2 flood group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 341 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 342 | private EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 343 | vlanNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 344 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 345 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 346 | * Used to keep track on L2 interface group and L3 unicast group information for direct hosts. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 347 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 348 | private EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 349 | portNextObjStore = null; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 350 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 351 | /** |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 352 | * Per device next objective ID store with (device id + MAC address + vlan) as key. |
| 353 | * Used to keep track of L3 unicast group for indirect hosts. |
| 354 | */ |
| 355 | private EventuallyConsistentMap<MacVlanNextObjectiveStoreKey, Integer> |
| 356 | macVlanNextObjStore = null; |
| 357 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 358 | private EventuallyConsistentMap<String, Tunnel> tunnelStore = null; |
| 359 | private EventuallyConsistentMap<String, Policy> policyStore = null; |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 360 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 361 | private AtomicBoolean programmingScheduled = new AtomicBoolean(); |
| 362 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 363 | private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 364 | new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>( |
| 365 | SubjectFactories.DEVICE_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 366 | SegmentRoutingDeviceConfig.class, "segmentrouting") { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 367 | @Override |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 368 | public SegmentRoutingDeviceConfig createConfig() { |
| 369 | return new SegmentRoutingDeviceConfig(); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 370 | } |
| 371 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 372 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 373 | private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 374 | new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>( |
| 375 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 376 | SegmentRoutingAppConfig.class, "segmentrouting") { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 377 | @Override |
| 378 | public SegmentRoutingAppConfig createConfig() { |
| 379 | return new SegmentRoutingAppConfig(); |
| 380 | } |
| 381 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 382 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 383 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 384 | new ConfigFactory<ApplicationId, McastConfig>( |
| 385 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 386 | McastConfig.class, "multicast") { |
| 387 | @Override |
| 388 | public McastConfig createConfig() { |
| 389 | return new McastConfig(); |
| 390 | } |
| 391 | }; |
| 392 | |
Charles Chan | 1963f4f | 2016-02-18 14:22:42 -0800 | [diff] [blame] | 393 | /** |
| 394 | * Segment Routing App ID. |
| 395 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 396 | public static final String APP_NAME = "org.onosproject.segmentrouting"; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 397 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 398 | /** |
| 399 | * Minumum and maximum value of dummy VLAN ID to be allocated. |
| 400 | */ |
| 401 | public static final int MIN_DUMMY_VLAN_ID = 2; |
| 402 | public static final int MAX_DUMMY_VLAN_ID = 4093; |
| 403 | |
Charles Chan | a7601c9 | 2019-01-23 15:03:17 -0800 | [diff] [blame] | 404 | private static final int DEFAULT_POOL_SIZE = 32; |
| 405 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 406 | Instant lastEdgePortEvent = Instant.EPOCH; |
| 407 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 408 | @Activate |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 409 | protected void activate(ComponentContext context) { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 410 | appId = coreService.registerApplication(APP_NAME); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 411 | |
Charles Chan | a7601c9 | 2019-01-23 15:03:17 -0800 | [diff] [blame] | 412 | mainEventExecutor = Executors.newSingleThreadScheduledExecutor( |
| 413 | groupedThreads("onos/sr", "event-main-%d", log)); |
| 414 | hostEventExecutor = Executors.newSingleThreadScheduledExecutor( |
| 415 | groupedThreads("onos/sr", "event-host-%d", log)); |
| 416 | routeEventExecutor = Executors.newSingleThreadScheduledExecutor( |
| 417 | groupedThreads("onos/sr", "event-route-%d", log)); |
| 418 | mcastEventExecutor = Executors.newSingleThreadScheduledExecutor( |
| 419 | groupedThreads("onos/sr", "event-mcast-%d", log)); |
| 420 | packetExecutor = Executors.newSingleThreadExecutor(groupedThreads("onos/sr", "packet-%d", log)); |
| 421 | neighborExecutor = Executors.newFixedThreadPool(DEFAULT_POOL_SIZE, |
| 422 | groupedThreads("onos/sr", "neighbor-%d", log)); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 423 | |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 424 | log.debug("Creating EC map nsnextobjectivestore"); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 425 | EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 426 | nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 427 | dsNextObjStore = nsNextObjMapBuilder |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 428 | .withName("nsnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 429 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 430 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 431 | .build(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 432 | log.trace("Current size {}", dsNextObjStore.size()); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 433 | |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 434 | log.debug("Creating EC map vlannextobjectivestore"); |
| 435 | EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer> |
| 436 | vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 437 | vlanNextObjStore = vlanNextObjMapBuilder |
| 438 | .withName("vlannextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 439 | .withSerializer(createSerializer()) |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 440 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 441 | .build(); |
| 442 | |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 443 | log.debug("Creating EC map macvlannextobjectivestore"); |
| 444 | EventuallyConsistentMapBuilder<MacVlanNextObjectiveStoreKey, Integer> |
| 445 | macVlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 446 | macVlanNextObjStore = macVlanNextObjMapBuilder |
| 447 | .withName("macvlannextobjectivestore") |
| 448 | .withSerializer(createSerializer()) |
| 449 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 450 | .build(); |
| 451 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 452 | log.debug("Creating EC map subnetnextobjectivestore"); |
| 453 | EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer> |
| 454 | portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 455 | portNextObjStore = portNextObjMapBuilder |
| 456 | .withName("portnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 457 | .withSerializer(createSerializer()) |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 458 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 459 | .build(); |
| 460 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 461 | EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder = |
| 462 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 463 | tunnelStore = tunnelMapBuilder |
| 464 | .withName("tunnelstore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 465 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 466 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 467 | .build(); |
| 468 | |
| 469 | EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder = |
| 470 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 471 | policyStore = policyMapBuilder |
| 472 | .withName("policystore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 473 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 474 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 475 | .build(); |
| 476 | |
Charles Chan | 9797980 | 2020-02-26 15:04:44 -0800 | [diff] [blame] | 477 | processor = new InternalPacketProcessor(); |
| 478 | linkListener = new InternalLinkListener(); |
| 479 | deviceListener = new InternalDeviceListener(); |
| 480 | appCfgHandler = new AppConfigHandler(this); |
| 481 | mcastHandler = new McastHandler(this); |
| 482 | hostHandler = new HostHandler(this); |
| 483 | linkHandler = new LinkHandler(this); |
| 484 | routeHandler = new RouteHandler(this); |
| 485 | neighbourHandler = new SegmentRoutingNeighbourDispatcher(this); |
| 486 | l2TunnelHandler = new DefaultL2TunnelHandler(this); |
| 487 | topologyHandler = new TopologyHandler(this); |
| 488 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 489 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 490 | "purgeOnDisconnection", "true", false); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 491 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 492 | "purgeOnDisconnection", "true", false); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 493 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 494 | "requestInterceptsEnabled", "false", false); |
Charles Chan | c1909e1 | 2017-08-08 15:13:37 -0700 | [diff] [blame] | 495 | compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 496 | "requestInterceptsEnabled", "false", false); |
Charles Chan | 9597f8d | 2017-07-24 15:56:10 -0700 | [diff] [blame] | 497 | compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 498 | "arpEnabled", "false", false); |
Pier Luigi | 0ebeb31 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 499 | compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 500 | "greedyLearningIpv6", "true", false); |
Charles Chan | cf8ea47 | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 501 | compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 502 | "forceUnprovision", "true", false); |
Charles Chan | c7b73c7 | 2017-08-10 16:57:28 -0700 | [diff] [blame] | 503 | compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 504 | "distributed", "true", false); |
Charles Chan | 804772f | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 505 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 506 | "multihomingEnabled", "true", false); |
Charles Chan | 0c9c19f | 2017-11-29 19:54:20 -0800 | [diff] [blame] | 507 | compCfgService.preSetProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 508 | "staleLinkAge", "15000", false); |
Charles Chan | 0c9c19f | 2017-11-29 19:54:20 -0800 | [diff] [blame] | 509 | compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 510 | "allowDuplicateIps", "false", false); |
Yi Tseng | a7da8d8 | 2018-08-19 03:09:54 +0800 | [diff] [blame] | 511 | // For P4 switches |
| 512 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 513 | "fallbackFlowPollFrequency", "4", false); |
Yi Tseng | a7da8d8 | 2018-08-19 03:09:54 +0800 | [diff] [blame] | 514 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Charles Chan | 0fa51db | 2019-04-10 17:12:20 -0700 | [diff] [blame] | 515 | "fallbackGroupPollFrequency", "3", false); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 516 | compCfgService.registerProperties(getClass()); |
| 517 | modified(context); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 518 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 519 | cfgService.addListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 520 | cfgService.registerConfigFactory(deviceConfigFactory); |
| 521 | cfgService.registerConfigFactory(appConfigFactory); |
| 522 | cfgService.registerConfigFactory(mcastConfigFactory); |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 523 | log.info("Configuring network before adding listeners"); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 524 | |
Charles Chan | 6961f22 | 2018-01-04 14:26:07 -0800 | [diff] [blame] | 525 | cfgListener.configureNetwork(); |
| 526 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 527 | hostService.addListener(hostListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 528 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
| 529 | linkService.addListener(linkListener); |
| 530 | deviceService.addListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 531 | multicastRouteService.addListener(mcastListener); |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 532 | routeService.addListener(routeListener); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 533 | topologyService.addListener(topologyListener); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 534 | mastershipService.addListener(mastershipListener); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 535 | clusterService.addListener(clusterListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 536 | |
Charles Chan | c12c3d0 | 2018-03-09 15:53:44 -0800 | [diff] [blame] | 537 | linkHandler.init(); |
Andreas Pantelopoulos | 75eef06 | 2018-01-11 07:53:48 -0800 | [diff] [blame] | 538 | l2TunnelHandler.init(); |
| 539 | |
Ray Milkey | 521e439 | 2018-11-16 15:15:14 -0800 | [diff] [blame] | 540 | synchronized (networkConfigCompletionLock) { |
| 541 | networkConfigCompletion.whenComplete((value, ex) -> { |
| 542 | //setting to null for easier fall through |
| 543 | networkConfigCompletion = null; |
| 544 | //process all queued events |
| 545 | queuedEvents.forEach(event -> { |
| 546 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 547 | }); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 548 | }); |
Ray Milkey | 521e439 | 2018-11-16 15:15:14 -0800 | [diff] [blame] | 549 | } |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 550 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 551 | log.info("Started"); |
| 552 | } |
| 553 | |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 554 | KryoNamespace.Builder createSerializer() { |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 555 | return new KryoNamespace.Builder() |
| 556 | .register(KryoNamespaces.API) |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 557 | .register(DestinationSetNextObjectiveStoreKey.class, |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 558 | VlanNextObjectiveStoreKey.class, |
| 559 | DestinationSet.class, |
Andreas Pantelopoulos | 92998c9 | 2018-05-29 13:11:14 -0700 | [diff] [blame] | 560 | DestinationSet.DestinationSetType.class, |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 561 | NextNeighbors.class, |
| 562 | Tunnel.class, |
| 563 | DefaultTunnel.class, |
| 564 | Policy.class, |
| 565 | TunnelPolicy.class, |
| 566 | Policy.Type.class, |
| 567 | PortNextObjectiveStoreKey.class, |
| 568 | XConnectStoreKey.class, |
| 569 | L2Tunnel.class, |
| 570 | L2TunnelPolicy.class, |
| 571 | DefaultL2Tunnel.class, |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 572 | DefaultL2TunnelPolicy.class, |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 573 | MacVlanNextObjectiveStoreKey.class |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 574 | ); |
| 575 | } |
| 576 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 577 | @Deactivate |
| 578 | protected void deactivate() { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 579 | mainEventExecutor.shutdown(); |
| 580 | hostEventExecutor.shutdown(); |
| 581 | routeEventExecutor.shutdown(); |
| 582 | mcastEventExecutor.shutdown(); |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 583 | packetExecutor.shutdown(); |
Charles Chan | a7601c9 | 2019-01-23 15:03:17 -0800 | [diff] [blame] | 584 | neighborExecutor.shutdown(); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 585 | |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 586 | mainEventExecutor = null; |
| 587 | hostEventExecutor = null; |
| 588 | routeEventExecutor = null; |
| 589 | mcastEventExecutor = null; |
| 590 | packetExecutor = null; |
Charles Chan | a7601c9 | 2019-01-23 15:03:17 -0800 | [diff] [blame] | 591 | neighborExecutor = null; |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 592 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 593 | cfgService.removeListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 594 | cfgService.unregisterConfigFactory(deviceConfigFactory); |
| 595 | cfgService.unregisterConfigFactory(appConfigFactory); |
| 596 | cfgService.unregisterConfigFactory(mcastConfigFactory); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 597 | compCfgService.unregisterProperties(getClass(), false); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 598 | |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 599 | hostService.removeListener(hostListener); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 600 | packetService.removeProcessor(processor); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 601 | linkService.removeListener(linkListener); |
| 602 | deviceService.removeListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 603 | multicastRouteService.removeListener(mcastListener); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 604 | routeService.removeListener(routeListener); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 605 | topologyService.removeListener(topologyListener); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 606 | mastershipService.removeListener(mastershipListener); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 607 | clusterService.removeListener(clusterListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 608 | |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 609 | neighbourResolutionService.unregisterNeighbourHandlers(appId); |
| 610 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 611 | processor = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 612 | linkListener = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 613 | deviceListener = null; |
Charles Chan | 05bb170 | 2018-04-19 13:10:01 -0700 | [diff] [blame] | 614 | groupHandlerMap.forEach((k, v) -> v.shutdown()); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 615 | groupHandlerMap.clear(); |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 616 | defaultRoutingHandler.shutdown(); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 617 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 618 | dsNextObjStore.destroy(); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 619 | vlanNextObjStore.destroy(); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 620 | macVlanNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 621 | portNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 622 | tunnelStore.destroy(); |
| 623 | policyStore.destroy(); |
Pier Luigi | 35dab3f | 2018-01-25 16:16:02 +0100 | [diff] [blame] | 624 | |
| 625 | mcastHandler.terminate(); |
pier | cf55792 | 2019-05-17 20:47:06 +0200 | [diff] [blame] | 626 | hostHandler.terminate(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 627 | log.info("Stopped"); |
| 628 | } |
| 629 | |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 630 | @Modified |
| 631 | private void modified(ComponentContext context) { |
| 632 | Dictionary<?, ?> properties = context.getProperties(); |
| 633 | if (properties == null) { |
| 634 | return; |
| 635 | } |
| 636 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 637 | String strActiveProbing = Tools.get(properties, PROP_ACTIVE_PROBING); |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 638 | boolean expectActiveProbing = Boolean.parseBoolean(strActiveProbing); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 639 | if (expectActiveProbing != activeProbing) { |
| 640 | activeProbing = expectActiveProbing; |
| 641 | log.info("{} active probing", activeProbing ? "Enabling" : "Disabling"); |
| 642 | } |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 643 | |
Ray Milkey | e96d0de | 2018-11-02 17:12:21 -0700 | [diff] [blame] | 644 | |
| 645 | String strSymmetricProbing = Tools.get(properties, PROP_SYMMETRIC_PROBING); |
| 646 | boolean expectSymmetricProbing = Boolean.parseBoolean(strSymmetricProbing); |
Mayank Tiwari | f794240 | 2018-10-29 18:27:35 -0400 | [diff] [blame] | 647 | if (expectSymmetricProbing != symmetricProbing) { |
| 648 | symmetricProbing = expectSymmetricProbing; |
| 649 | log.info("{} symmetric probing", symmetricProbing ? "Enabling" : "Disabling"); |
| 650 | } |
| 651 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 652 | String strSingleHomedDown = Tools.get(properties, PROP_SINGLE_HOMED_DOWN); |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 653 | boolean expectSingleHomedDown = Boolean.parseBoolean(strSingleHomedDown); |
| 654 | if (expectSingleHomedDown != singleHomedDown) { |
| 655 | singleHomedDown = expectSingleHomedDown; |
| 656 | log.info("{} downing of single homed hosts for lost uplinks", |
| 657 | singleHomedDown ? "Enabling" : "Disabling"); |
| 658 | if (singleHomedDown && linkHandler != null) { |
| 659 | hostService.getHosts().forEach(host -> host.locations() |
| 660 | .forEach(loc -> { |
| 661 | if (interfaceService.isConfigured(loc)) { |
| 662 | linkHandler.checkUplinksForHost(loc); |
| 663 | } |
| 664 | })); |
| 665 | } else { |
| 666 | log.warn("Disabling singleHomedDown does not re-enable already " |
| 667 | + "downed ports for single-homed hosts"); |
| 668 | } |
| 669 | } |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 670 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 671 | String strRespondToUnknownHosts = Tools.get(properties, PROP_RESPOND_TO_UNKNOWN_HOSTS); |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 672 | boolean expectRespondToUnknownHosts = Boolean.parseBoolean(strRespondToUnknownHosts); |
| 673 | if (expectRespondToUnknownHosts != respondToUnknownHosts) { |
| 674 | respondToUnknownHosts = expectRespondToUnknownHosts; |
| 675 | log.info("{} responding to ARPs/NDPs from unknown hosts", respondToUnknownHosts ? "Enabling" : "Disabling"); |
| 676 | } |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 677 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 678 | String strRouteDoubleTaggedHosts = Tools.get(properties, PROP_ROUTE_DOUBLE_TAGGED_HOSTS); |
Charles Chan | fbca55e | 2018-07-24 16:40:35 -0700 | [diff] [blame] | 679 | boolean expectRouteDoubleTaggedHosts = Boolean.parseBoolean(strRouteDoubleTaggedHosts); |
| 680 | if (expectRouteDoubleTaggedHosts != routeDoubleTaggedHosts) { |
| 681 | routeDoubleTaggedHosts = expectRouteDoubleTaggedHosts; |
| 682 | log.info("{} routing for double tagged hosts", routeDoubleTaggedHosts ? "Enabling" : "Disabling"); |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 683 | |
Charles Chan | fbca55e | 2018-07-24 16:40:35 -0700 | [diff] [blame] | 684 | if (routeDoubleTaggedHosts) { |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 685 | hostHandler.populateAllDoubleTaggedHost(); |
| 686 | } else { |
| 687 | hostHandler.revokeAllDoubleTaggedHost(); |
| 688 | } |
| 689 | } |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 690 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 691 | String strDefaultInternalVlan = Tools.get(properties, PROP_DEFAULT_INTERNAL_VLAN); |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 692 | int defIntVlan = Integer.parseInt(strDefaultInternalVlan); |
| 693 | if (defIntVlan != defaultInternalVlan) { |
| 694 | if (canUseVlanId(defIntVlan)) { |
| 695 | log.warn("Default internal vlan value changed from {} to {}.. " |
| 696 | + "re-programming filtering rules, but NOT any groups already " |
| 697 | + "created with the former value", defaultInternalVlan, defIntVlan); |
| 698 | VlanId oldDefIntVlan = VlanId.vlanId((short) defaultInternalVlan); |
| 699 | defaultInternalVlan = defIntVlan; |
| 700 | routingRulePopulator |
| 701 | .updateSpecialVlanFilteringRules(true, oldDefIntVlan, |
| 702 | VlanId.vlanId((short) defIntVlan)); |
| 703 | } else { |
| 704 | log.warn("Cannot change default internal vlan to unusable " |
| 705 | + "value {}", defIntVlan); |
| 706 | } |
| 707 | } |
| 708 | |
Ray Milkey | 48d10c0 | 2018-10-24 10:04:03 -0700 | [diff] [blame] | 709 | String strPwTxpVlan = Tools.get(properties, PROP_PW_TRANSPORT_VLAN); |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 710 | int pwTxpVlan = Integer.parseInt(strPwTxpVlan); |
| 711 | if (pwTxpVlan != pwTransportVlan) { |
| 712 | if (canUseVlanId(pwTxpVlan)) { |
| 713 | log.warn("Pseudowire transport vlan value changed from {} to {}.. " |
| 714 | + "re-programming filtering rules, but NOT any groups already " |
| 715 | + "created with the former value", pwTransportVlan, |
| 716 | pwTxpVlan); |
| 717 | VlanId oldPwTxpVlan = VlanId.vlanId((short) pwTransportVlan); |
| 718 | pwTransportVlan = pwTxpVlan; |
| 719 | routingRulePopulator |
| 720 | .updateSpecialVlanFilteringRules(false, oldPwTxpVlan, |
| 721 | VlanId.vlanId((short) pwTxpVlan)); |
| 722 | } else { |
| 723 | log.warn("Cannot change pseudowire transport vlan to unusable " |
| 724 | + "value {}", pwTxpVlan); |
| 725 | } |
| 726 | } |
| 727 | |
psneha | 86e60d3 | 2019-03-26 06:31:41 -0400 | [diff] [blame] | 728 | String strRouteSimplification = Tools.get(properties, PROP_ROUTE_SIMPLIFICATION); |
| 729 | boolean expectRouteSimplification = Boolean.parseBoolean(strRouteSimplification); |
| 730 | if (expectRouteSimplification != routeSimplification) { |
| 731 | routeSimplification = expectRouteSimplification; |
| 732 | log.info("{} route simplification", routeSimplification ? "Enabling" : "Disabling"); |
| 733 | } |
| 734 | |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Returns true if given vlan id is not being used in the system currently, |
| 739 | * either as one of the default system wide vlans or as one of the |
| 740 | * configured interface vlans. |
| 741 | * |
| 742 | * @param vlanId given vlan id |
| 743 | * @return true if vlan is not currently in use |
| 744 | */ |
| 745 | public boolean canUseVlanId(int vlanId) { |
| 746 | if (vlanId >= 4095 || vlanId <= 1) { |
| 747 | log.error("Vlan id {} value is not in valid range 2 <--> 4094", |
| 748 | vlanId); |
| 749 | return false; |
| 750 | } |
| 751 | |
| 752 | VlanId vid = VlanId.vlanId((short) vlanId); |
| 753 | if (getDefaultInternalVlan().equals(vid) || getPwTransportVlan().equals(vid)) { |
| 754 | log.warn("Vlan id {} value is already in use system-wide. " |
| 755 | + "DefaultInternalVlan:{} PwTransportVlan:{} ", vlanId, |
| 756 | getDefaultInternalVlan(), getPwTransportVlan()); |
| 757 | return false; |
| 758 | } |
| 759 | |
| 760 | if (interfaceService.inUse(vid)) { |
| 761 | log.warn("Vlan id {} value is already in use on a configured " |
| 762 | + "interface in the system", vlanId); |
| 763 | return false; |
| 764 | } |
| 765 | return true; |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Returns the VlanId assigned internally by default to unconfigured ports. |
| 770 | * |
| 771 | * @return the default internal vlan id |
| 772 | */ |
| 773 | public VlanId getDefaultInternalVlan() { |
| 774 | return VlanId.vlanId((short) defaultInternalVlan); |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Returns the Vlan id used to transport pseudowire traffic across the |
| 779 | * network. |
| 780 | * |
| 781 | * @return the pseudowire transport vlan id |
| 782 | */ |
| 783 | public VlanId getPwTransportVlan() { |
| 784 | return VlanId.vlanId((short) pwTransportVlan); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 785 | } |
| 786 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 787 | @Override |
| 788 | public List<Tunnel> getTunnels() { |
| 789 | return tunnelHandler.getTunnels(); |
| 790 | } |
| 791 | |
| 792 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 793 | public TunnelHandler.Result createTunnel(Tunnel tunnel) { |
| 794 | return tunnelHandler.createTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 798 | public TunnelHandler.Result removeTunnel(Tunnel tunnel) { |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 799 | for (Policy policy: policyHandler.getPolicies()) { |
| 800 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
| 801 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
| 802 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { |
| 803 | log.warn("Cannot remove the tunnel used by a policy"); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 804 | return TunnelHandler.Result.TUNNEL_IN_USE; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | } |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 808 | return tunnelHandler.removeTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 812 | public PolicyHandler.Result removePolicy(Policy policy) { |
| 813 | return policyHandler.removePolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 817 | public PolicyHandler.Result createPolicy(Policy policy) { |
| 818 | return policyHandler.createPolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | @Override |
| 822 | public List<Policy> getPolicies() { |
| 823 | return policyHandler.getPolicies(); |
| 824 | } |
| 825 | |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 826 | @Override |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 827 | public Set<L2TunnelDescription> getL2TunnelDescriptions(boolean pending) { |
| 828 | return l2TunnelHandler.getL2Descriptions(pending); |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | @Override |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 832 | public List<L2Tunnel> getL2Tunnels() { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 833 | return l2TunnelHandler.getL2Tunnels(); |
| 834 | } |
| 835 | |
| 836 | @Override |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 837 | public List<L2TunnelPolicy> getL2Policies() { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 838 | return l2TunnelHandler.getL2Policies(); |
| 839 | } |
| 840 | |
Saurav Das | debcf88 | 2018-04-06 20:16:01 -0700 | [diff] [blame] | 841 | @Override |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 842 | @Deprecated |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 843 | public L2TunnelHandler.Result addPseudowiresBulk(List<DefaultL2TunnelDescription> bulkPseudowires) { |
| 844 | |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 845 | // get both added and pending pseudowires |
| 846 | List<L2TunnelDescription> pseudowires = new ArrayList<>(); |
| 847 | pseudowires.addAll(l2TunnelHandler.getL2Descriptions(false)); |
| 848 | pseudowires.addAll(l2TunnelHandler.getL2Descriptions(true)); |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 849 | pseudowires.addAll(bulkPseudowires); |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 850 | |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 851 | Set<L2TunnelDescription> newPseudowires = new HashSet(bulkPseudowires); |
| 852 | |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 853 | L2TunnelHandler.Result retRes = L2TunnelHandler.Result.SUCCESS; |
| 854 | L2TunnelHandler.Result res; |
| 855 | for (DefaultL2TunnelDescription pw : bulkPseudowires) { |
| 856 | res = addPseudowire(pw); |
| 857 | if (res != L2TunnelHandler.Result.SUCCESS) { |
| 858 | log.error("Pseudowire with id {} can not be instantiated !", res); |
| 859 | retRes = res; |
| 860 | } |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 861 | } |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 862 | |
| 863 | return retRes; |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | @Override |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 867 | public L2TunnelHandler.Result addPseudowire(L2TunnelDescription l2TunnelDescription) { |
Andreas Pantelopoulos | 87a0610 | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 868 | return l2TunnelHandler.deployPseudowire(l2TunnelDescription); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | @Override |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 872 | public L2TunnelHandler.Result removePseudowire(Integer pwId) { |
Andreas Pantelopoulos | 87a0610 | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 873 | return l2TunnelHandler.tearDownPseudowire(pwId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | @Override |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 877 | public void rerouteNetwork() { |
| 878 | cfgListener.configureNetwork(); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 881 | @Override |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 882 | public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() { |
| 883 | Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap(); |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 884 | deviceConfiguration.getRouters().forEach(device -> |
| 885 | deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device))); |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 886 | return deviceSubnetMap; |
| 887 | } |
| 888 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 889 | |
| 890 | @Override |
| 891 | public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() { |
| 892 | if (defaultRoutingHandler != null) { |
| 893 | return defaultRoutingHandler.getCurrentEmcpSpgMap(); |
| 894 | } else { |
| 895 | return null; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 900 | public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDstNextObjStore() { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 901 | if (dsNextObjStore != null) { |
| 902 | return ImmutableMap.copyOf(dsNextObjStore.entrySet()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 903 | } else { |
| 904 | return ImmutableMap.of(); |
| 905 | } |
| 906 | } |
| 907 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 908 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 909 | public ImmutableMap<VlanNextObjectiveStoreKey, Integer> getVlanNextObjStore() { |
| 910 | if (vlanNextObjStore != null) { |
| 911 | return ImmutableMap.copyOf(vlanNextObjStore.entrySet()); |
| 912 | } else { |
| 913 | return ImmutableMap.of(); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | @Override |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 918 | public ImmutableMap<MacVlanNextObjectiveStoreKey, Integer> getMacVlanNextObjStore() { |
| 919 | if (macVlanNextObjStore != null) { |
| 920 | return ImmutableMap.copyOf(macVlanNextObjStore.entrySet()); |
| 921 | } else { |
| 922 | return ImmutableMap.of(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 927 | public ImmutableMap<PortNextObjectiveStoreKey, Integer> getPortNextObjStore() { |
| 928 | if (portNextObjStore != null) { |
| 929 | return ImmutableMap.copyOf(portNextObjStore.entrySet()); |
| 930 | } else { |
| 931 | return ImmutableMap.of(); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | @Override |
| 936 | public ImmutableMap<String, NextObjective> getPwInitNext() { |
| 937 | if (l2TunnelHandler != null) { |
| 938 | return l2TunnelHandler.getInitNext(); |
| 939 | } else { |
| 940 | return ImmutableMap.of(); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public ImmutableMap<String, NextObjective> getPwTermNext() { |
| 946 | if (l2TunnelHandler != null) { |
| 947 | return l2TunnelHandler.getTermNext(); |
| 948 | } else { |
| 949 | return ImmutableMap.of(); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | @Override |
| 954 | public void invalidateNextObj(int nextId) { |
| 955 | if (dsNextObjStore != null) { |
| 956 | dsNextObjStore.entrySet().forEach(e -> { |
| 957 | if (e.getValue().nextId() == nextId) { |
| 958 | dsNextObjStore.remove(e.getKey()); |
| 959 | } |
| 960 | }); |
| 961 | } |
| 962 | if (vlanNextObjStore != null) { |
| 963 | vlanNextObjStore.entrySet().forEach(e -> { |
| 964 | if (e.getValue() == nextId) { |
| 965 | vlanNextObjStore.remove(e.getKey()); |
| 966 | } |
| 967 | }); |
| 968 | } |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 969 | if (macVlanNextObjStore != null) { |
| 970 | macVlanNextObjStore.entrySet().forEach(e -> { |
| 971 | if (e.getValue() == nextId) { |
| 972 | macVlanNextObjStore.remove(e.getKey()); |
| 973 | } |
| 974 | }); |
| 975 | } |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 976 | if (portNextObjStore != null) { |
| 977 | portNextObjStore.entrySet().forEach(e -> { |
| 978 | if (e.getValue() == nextId) { |
| 979 | portNextObjStore.remove(e.getKey()); |
| 980 | } |
| 981 | }); |
| 982 | } |
| 983 | if (mcastHandler != null) { |
| 984 | mcastHandler.removeNextId(nextId); |
| 985 | } |
| 986 | if (l2TunnelHandler != null) { |
| 987 | l2TunnelHandler.removeNextId(nextId); |
| 988 | } |
| 989 | if (xconnectService != null) { |
| 990 | xconnectService.removeNextId(nextId); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | @Override |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 995 | public void verifyGroups(DeviceId id) { |
| 996 | DefaultGroupHandler gh = groupHandlerMap.get(id); |
| 997 | if (gh != null) { |
| 998 | gh.triggerBucketCorrector(); |
| 999 | } |
| 1000 | } |
| 1001 | |
Saurav Das | 6430f41 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1002 | @Override |
| 1003 | public ImmutableMap<Link, Boolean> getSeenLinks() { |
| 1004 | return linkHandler.getSeenLinks(); |
| 1005 | } |
| 1006 | |
| 1007 | @Override |
| 1008 | public ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState() { |
| 1009 | return linkHandler.getDownedPorts(); |
| 1010 | } |
| 1011 | |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 1012 | @Override |
| 1013 | public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) { |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 1014 | return mcastHandler.getNextIds(mcastIp); |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | @Override |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 1018 | public Map<McastRoleStoreKey, McastRole> getMcastRoles(IpAddress mcastIp, ConnectPoint sourcecp) { |
| 1019 | return mcastHandler.getMcastRoles(mcastIp, sourcecp); |
| 1020 | } |
| 1021 | |
| 1022 | @Override |
Pier | 71c5577 | 2018-04-17 17:25:22 +0200 | [diff] [blame] | 1023 | public Multimap<ConnectPoint, List<ConnectPoint>> getMcastTrees(IpAddress mcastIp, |
| 1024 | ConnectPoint sourcecp) { |
| 1025 | return mcastHandler.getMcastTrees(mcastIp, sourcecp); |
| 1026 | } |
| 1027 | |
| 1028 | @Override |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 1029 | public Map<IpAddress, NodeId> getMcastLeaders(IpAddress mcastIp) { |
| 1030 | return mcastHandler.getMcastLeaders(mcastIp); |
| 1031 | } |
| 1032 | |
Charles Chan | b13e070 | 2018-04-17 18:56:53 -0700 | [diff] [blame] | 1033 | @Override |
Harshada Chaundkar | 9204f31 | 2019-07-02 16:01:24 +0000 | [diff] [blame] | 1034 | public Map<DeviceId, List<McastFilteringObjStoreKey>> getMcastFilters() { |
| 1035 | return mcastHandler.getMcastFilters(); |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
Charles Chan | b13e070 | 2018-04-17 18:56:53 -0700 | [diff] [blame] | 1039 | public Map<Set<DeviceId>, NodeId> getShouldProgram() { |
| 1040 | return defaultRoutingHandler == null ? ImmutableMap.of() : |
| 1041 | ImmutableMap.copyOf(defaultRoutingHandler.shouldProgram); |
| 1042 | } |
| 1043 | |
| 1044 | @Override |
| 1045 | public Map<DeviceId, Boolean> getShouldProgramCache() { |
| 1046 | return defaultRoutingHandler == null ? ImmutableMap.of() : |
| 1047 | ImmutableMap.copyOf(defaultRoutingHandler.shouldProgramCache); |
| 1048 | } |
| 1049 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1050 | @Override |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1051 | public boolean shouldProgram(DeviceId deviceId) { |
| 1052 | return defaultRoutingHandler.shouldProgram(deviceId); |
| 1053 | } |
| 1054 | |
| 1055 | @Override |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1056 | public ApplicationId appId() { |
| 1057 | return appId; |
| 1058 | } |
| 1059 | |
| 1060 | /** |
| 1061 | * Returns the device configuration. |
| 1062 | * |
| 1063 | * @return device configuration |
| 1064 | */ |
| 1065 | public DeviceConfiguration deviceConfiguration() { |
| 1066 | return deviceConfiguration; |
| 1067 | } |
| 1068 | |
| 1069 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1070 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1071 | * Used to keep track on MPLS group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1072 | * |
| 1073 | * @return next objective ID store |
| 1074 | */ |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1075 | public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
| 1076 | dsNextObjStore() { |
| 1077 | return dsNextObjStore; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1081 | * Per device next objective ID store with (device id + vlanid) as key. |
| 1082 | * Used to keep track on L2 flood group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1083 | * |
| 1084 | * @return vlan next object store |
| 1085 | */ |
| 1086 | public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() { |
| 1087 | return vlanNextObjStore; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1091 | * Per device next objective ID store with (device id + MAC address + vlan) as key. |
| 1092 | * Used to keep track on L3 Unicast group information for indirect hosts. |
| 1093 | * |
| 1094 | * @return mac vlan next object store |
| 1095 | */ |
| 1096 | public EventuallyConsistentMap<MacVlanNextObjectiveStoreKey, Integer> macVlanNextObjStore() { |
| 1097 | return macVlanNextObjStore; |
| 1098 | } |
| 1099 | |
| 1100 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1101 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1102 | * Used to keep track on L2 interface group and L3 unicast group information for direct hosts. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1103 | * |
| 1104 | * @return port next object store. |
| 1105 | */ |
| 1106 | public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() { |
| 1107 | return portNextObjStore; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1111 | * Returns the MPLS-ECMP configuration which indicates whether ECMP on |
| 1112 | * labeled packets should be programmed or not. |
Pier Ventre | 7a78de2 | 2016-10-31 15:00:01 -0700 | [diff] [blame] | 1113 | * |
| 1114 | * @return MPLS-ECMP value |
| 1115 | */ |
| 1116 | public boolean getMplsEcmp() { |
| 1117 | SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService |
| 1118 | .getConfig(this.appId, SegmentRoutingAppConfig.class); |
| 1119 | return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp(); |
| 1120 | } |
| 1121 | |
| 1122 | /** |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 1123 | * Returns the tunnel object with the tunnel ID. |
| 1124 | * |
| 1125 | * @param tunnelId Tunnel ID |
| 1126 | * @return Tunnel reference |
| 1127 | */ |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1128 | public Tunnel getTunnel(String tunnelId) { |
| 1129 | return tunnelHandler.getTunnel(tunnelId); |
| 1130 | } |
| 1131 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1132 | @Override |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 1133 | public VlanId getInternalVlanId(ConnectPoint connectPoint) { |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1134 | VlanId untaggedVlanId = interfaceService.getUntaggedVlanId(connectPoint); |
| 1135 | VlanId nativeVlanId = interfaceService.getNativeVlanId(connectPoint); |
Charles Chan | d9265a3 | 2017-06-16 15:19:24 -0700 | [diff] [blame] | 1136 | return untaggedVlanId != null ? untaggedVlanId : nativeVlanId; |
| 1137 | } |
| 1138 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1139 | @Override |
| 1140 | public Optional<DeviceId> getPairDeviceId(DeviceId deviceId) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1141 | SegmentRoutingDeviceConfig deviceConfig = |
| 1142 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 1143 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId); |
| 1144 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1145 | |
| 1146 | @Override |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1147 | public Optional<PortNumber> getPairLocalPort(DeviceId deviceId) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1148 | SegmentRoutingDeviceConfig deviceConfig = |
| 1149 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 1150 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort); |
| 1151 | } |
| 1152 | |
| 1153 | /** |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 1154 | * Returns locations of given resolved route. |
| 1155 | * |
| 1156 | * @param resolvedRoute resolved route |
| 1157 | * @return locations of nexthop. Might be empty if next hop is not found |
| 1158 | */ |
Charles Chan | 19b7003 | 2019-04-17 14:20:26 -0700 | [diff] [blame] | 1159 | public Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) { |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 1160 | HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan()); |
| 1161 | return Optional.ofNullable(hostService.getHost(hostId)) |
| 1162 | .map(Host::locations).orElse(Sets.newHashSet()) |
| 1163 | .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet()); |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1167 | * Returns vlan port map of given device. |
| 1168 | * |
| 1169 | * @param deviceId device id |
| 1170 | * @return vlan-port multimap |
| 1171 | */ |
| 1172 | public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) { |
| 1173 | HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create(); |
| 1174 | |
| 1175 | interfaceService.getInterfaces().stream() |
| 1176 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
| 1177 | .forEach(intf -> { |
| 1178 | vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port()); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1179 | intf.vlanTagged().forEach(vlanTagged -> |
| 1180 | vlanPortMap.put(vlanTagged, intf.connectPoint().port()) |
| 1181 | ); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1182 | vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port()); |
| 1183 | }); |
| 1184 | vlanPortMap.removeAll(VlanId.NONE); |
| 1185 | |
| 1186 | return vlanPortMap; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1190 | * Returns the next objective ID for the given vlan id. It is expected |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1191 | * that the next-objective has been pre-created from configuration. |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1192 | * |
| 1193 | * @param deviceId Device ID |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1194 | * @param vlanId VLAN ID |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1195 | * @return next objective ID or -1 if it was not found |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1196 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1197 | int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) { |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1198 | if (groupHandlerMap.get(deviceId) != null) { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1199 | log.trace("getVlanNextObjectiveId query in device {}", deviceId); |
| 1200 | return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1201 | } else { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1202 | log.warn("getVlanNextObjectiveId query - groupHandler for " |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1203 | + "device {} not found", deviceId); |
| 1204 | return -1; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * Returns the next objective ID for the given portNumber, given the treatment. |
| 1210 | * There could be multiple different treatments to the same outport, which |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1211 | * would result in different objectives. If the next object does not exist, |
| 1212 | * and should be created, a new one is created and its id is returned. |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1213 | * |
| 1214 | * @param deviceId Device ID |
| 1215 | * @param portNum port number on device for which NextObjective is queried |
| 1216 | * @param treatment the actions to apply on the packets (should include outport) |
| 1217 | * @param meta metadata passed into the creation of a Next Objective if necessary |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1218 | * @param createIfMissing true if a next object should be created if not found |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1219 | * @return next objective ID or -1 if an error occurred during retrieval or creation |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1220 | */ |
| 1221 | public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum, |
| 1222 | TrafficTreatment treatment, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1223 | TrafficSelector meta, |
| 1224 | boolean createIfMissing) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1225 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 1226 | if (ghdlr != null) { |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1227 | return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1228 | } else { |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1229 | log.warn("getPortNextObjectiveId query - groupHandler for device {}" |
| 1230 | + " not found", deviceId); |
| 1231 | return -1; |
| 1232 | } |
| 1233 | } |
| 1234 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1235 | /** |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1236 | * Returns the next Objective ID for the given mac and vlan, given the treatment. |
| 1237 | * There could be multiple different treatments to the same outport, which |
| 1238 | * would result in different objectives. If the next object does not exist, |
| 1239 | * and should be created, a new one is created and its id is returned. |
| 1240 | * |
| 1241 | * @param deviceId Device ID |
| 1242 | * @param macAddr mac of host for which Next ID is required. |
| 1243 | * @param vlanId vlan of host for which Next ID is required. |
Ruchi Sahota | 0786932 | 2019-05-09 17:26:14 -0400 | [diff] [blame] | 1244 | * @param port port with which to create the Next Obj. |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1245 | * @param createIfMissing true if a next object should be created if not found |
| 1246 | * @return next objective ID or -1 if an error occurred during retrieval or creation |
| 1247 | */ |
| 1248 | public int getMacVlanNextObjectiveId(DeviceId deviceId, MacAddress macAddr, VlanId vlanId, |
Ruchi Sahota | 0786932 | 2019-05-09 17:26:14 -0400 | [diff] [blame] | 1249 | PortNumber port, boolean createIfMissing) { |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1250 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 1251 | if (ghdlr != null) { |
Ruchi Sahota | 0786932 | 2019-05-09 17:26:14 -0400 | [diff] [blame] | 1252 | return ghdlr.getMacVlanNextObjectiveId(macAddr, vlanId, port, createIfMissing); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1253 | } else { |
| 1254 | log.warn("getMacVlanNextObjectiveId query - groupHandler for device {}" |
| 1255 | + " not found", deviceId); |
| 1256 | return -1; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | /** |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1261 | * Updates the next objective for the given nextId . |
| 1262 | * |
| 1263 | * @param deviceId Device ID |
| 1264 | * @param hostMac mac of host for which Next obj is to be updated. |
| 1265 | * @param hostVlanId vlan of host for which Next obj is to be updated. |
| 1266 | * @param port port with which to update the Next Obj. |
| 1267 | * @param nextId of Next Obj which needs to be updated. |
| 1268 | */ |
| 1269 | public void updateMacVlanTreatment(DeviceId deviceId, MacAddress hostMac, |
| 1270 | VlanId hostVlanId, PortNumber port, int nextId) { |
pier | f0e37ec | 2019-11-26 11:48:48 +0100 | [diff] [blame] | 1271 | // Check if we are the king of this device |
| 1272 | // just one instance should perform this update |
| 1273 | if (!defaultRoutingHandler.shouldProgram(deviceId)) { |
| 1274 | log.debug("This instance is not handling the routing towards the " |
| 1275 | + "device {}", deviceId); |
| 1276 | return; |
| 1277 | } |
| 1278 | // Get the handler and perform the update |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1279 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 1280 | if (ghdlr != null) { |
| 1281 | ghdlr.updateL3UcastGroupBucket(hostMac, hostVlanId, port, nextId); |
| 1282 | } else { |
| 1283 | log.warn("updateL3UcastGroupBucket query - groupHandler for device {}" |
| 1284 | + " not found", deviceId); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | /** |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1290 | * Returns the group handler object for the specified device id. |
| 1291 | * |
| 1292 | * @param devId the device identifier |
| 1293 | * @return the groupHandler object for the device id, or null if not found |
| 1294 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1295 | DefaultGroupHandler getGroupHandler(DeviceId devId) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1296 | return groupHandlerMap.get(devId); |
| 1297 | } |
| 1298 | |
| 1299 | /** |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1300 | * Returns the default routing handler object. |
| 1301 | * |
| 1302 | * @return the default routing handler object |
| 1303 | */ |
| 1304 | public DefaultRoutingHandler getRoutingHandler() { |
| 1305 | return defaultRoutingHandler; |
| 1306 | } |
| 1307 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1308 | private class InternalPacketProcessor implements PacketProcessor { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1309 | @Override |
| 1310 | public void process(PacketContext context) { |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 1311 | packetExecutor.execute(() -> processPacketInternal(context)); |
| 1312 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1313 | |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 1314 | private void processPacketInternal(PacketContext context) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1315 | if (context.isHandled()) { |
| 1316 | return; |
| 1317 | } |
| 1318 | |
| 1319 | InboundPacket pkt = context.inPacket(); |
| 1320 | Ethernet ethernet = pkt.parsed(); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 1321 | |
| 1322 | if (ethernet == null) { |
| 1323 | return; |
| 1324 | } |
| 1325 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1326 | log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(), |
| 1327 | ethernet); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1328 | if (ethernet.getEtherType() == TYPE_ARP) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1329 | log.warn("Received unexpected ARP packet on {}", |
| 1330 | context.inPacket().receivedFrom()); |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 1331 | log.trace("{}", ethernet); |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 1332 | return; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1333 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) { |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1334 | IPv4 ipv4Packet = (IPv4) ethernet.getPayload(); |
| 1335 | //ipHandler.addToPacketBuffer(ipv4Packet); |
| 1336 | if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) { |
| 1337 | icmpHandler.processIcmp(ethernet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1338 | } else { |
Charles Chan | d041ad8 | 2017-01-13 17:20:44 -0800 | [diff] [blame] | 1339 | // NOTE: We don't support IP learning at this moment so this |
| 1340 | // is not necessary. Also it causes duplication of DHCP packets. |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 1341 | // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1342 | } |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1343 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) { |
| 1344 | IPv6 ipv6Packet = (IPv6) ethernet.getPayload(); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1345 | //ipHandler.addToPacketBuffer(ipv6Packet); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 1346 | // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1347 | if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) { |
| 1348 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
| 1349 | if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST || |
| 1350 | icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) { |
| 1351 | icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom()); |
| 1352 | } else { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1353 | log.trace("Received ICMPv6 0x{} - not handled", |
Charles Chan | d3727b7 | 2017-03-13 13:10:30 -0700 | [diff] [blame] | 1354 | Integer.toHexString(icmp6Packet.getIcmpType() & 0xff)); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1355 | } |
| 1356 | } else { |
| 1357 | // NOTE: We don't support IP learning at this moment so this |
| 1358 | // is not necessary. Also it causes duplication of DHCPv6 packets. |
| 1359 | // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom()); |
| 1360 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | } |
| 1364 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1365 | private class InternalEventHandler implements Runnable { |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1366 | private Event event; |
| 1367 | |
| 1368 | InternalEventHandler(Event event) { |
| 1369 | this.event = event; |
| 1370 | } |
| 1371 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 1372 | @Override |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1373 | public void run() { |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1374 | try { |
| 1375 | // TODO We should also change SR routing and PW to listen to TopologyEvents |
| 1376 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 1377 | event.type() == LinkEvent.Type.LINK_UPDATED) { |
| 1378 | linkHandler.processLinkAdded((Link) event.subject()); |
| 1379 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
| 1380 | linkHandler.processLinkRemoved((Link) event.subject()); |
| 1381 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 1382 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 1383 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
| 1384 | DeviceId deviceId = ((Device) event.subject()).id(); |
| 1385 | if (deviceService.isAvailable(deviceId)) { |
| 1386 | log.info("** DEVICE UP Processing device event {} " |
| 1387 | + "for available device {}", |
| 1388 | event.type(), ((Device) event.subject()).id()); |
| 1389 | processDeviceAdded((Device) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1390 | } else { |
Charles Chan | b8f3af5 | 2018-08-29 21:21:51 -0700 | [diff] [blame] | 1391 | if (event.type() == DeviceEvent.Type.DEVICE_ADDED) { |
| 1392 | // Note: For p4 devices, the device will be added but unavailable at the beginning. |
| 1393 | // The device will later on being marked as available once the pipeline is pushed |
| 1394 | // to the device. |
| 1395 | log.info("** DEVICE ADDED but unavailable. Ignore"); |
| 1396 | return; |
| 1397 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1398 | log.info(" ** DEVICE DOWN Processing device event {}" |
| 1399 | + " for unavailable device {}", |
| 1400 | event.type(), ((Device) event.subject()).id()); |
| 1401 | processDeviceRemoved((Device) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1402 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1403 | } else if (event.type() == DeviceEvent.Type.PORT_ADDED) { |
| 1404 | // typically these calls come when device is added first time |
| 1405 | // so port filtering rules are handled at the device_added event. |
| 1406 | // port added calls represent all ports on the device, |
| 1407 | // enabled or not. |
| 1408 | log.trace("** PORT ADDED {}/{} -> {}", |
| 1409 | ((DeviceEvent) event).subject().id(), |
| 1410 | ((DeviceEvent) event).port().number(), |
| 1411 | event.type()); |
| 1412 | } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) { |
| 1413 | // these calls happen for every subsequent event |
| 1414 | // ports enabled, disabled, switch goes away, comes back |
| 1415 | log.info("** PORT UPDATED {}/{} -> {}", |
| 1416 | event.subject(), |
| 1417 | ((DeviceEvent) event).port(), |
| 1418 | event.type()); |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1419 | processPortUpdatedInternal(((Device) event.subject()), |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1420 | ((DeviceEvent) event).port()); |
Harshada Chaundkar | 9204f31 | 2019-07-02 16:01:24 +0000 | [diff] [blame] | 1421 | mcastHandler.processPortUpdate(((Device) event.subject()), |
| 1422 | ((DeviceEvent) event).port()); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1423 | } else if (event.type() == TopologyEvent.Type.TOPOLOGY_CHANGED) { |
| 1424 | // Process topology event, needed for all modules relying on |
| 1425 | // topology service for path computation |
| 1426 | TopologyEvent topologyEvent = (TopologyEvent) event; |
| 1427 | log.info("Processing topology event {}, topology age {}, reasons {}", |
| 1428 | event.type(), topologyEvent.subject().time(), |
| 1429 | topologyEvent.reasons().size()); |
| 1430 | topologyHandler.processTopologyChange(topologyEvent.reasons()); |
| 1431 | } else if (event.type() == HostEvent.Type.HOST_ADDED) { |
| 1432 | hostHandler.processHostAddedEvent((HostEvent) event); |
| 1433 | } else if (event.type() == HostEvent.Type.HOST_MOVED) { |
| 1434 | hostHandler.processHostMovedEvent((HostEvent) event); |
| 1435 | routeHandler.processHostMovedEvent((HostEvent) event); |
Charles Chan | a2ccb58 | 2019-11-25 09:47:22 -0800 | [diff] [blame] | 1436 | } else if (event.type() == HostEvent.Type.HOST_AUX_MOVED) { |
| 1437 | hostHandler.processHostMovedEvent((HostEvent) event); |
| 1438 | // TODO RouteHandler also needs to process this event in order to |
| 1439 | // support nexthops that has auxLocations |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1440 | } else if (event.type() == HostEvent.Type.HOST_REMOVED) { |
| 1441 | hostHandler.processHostRemovedEvent((HostEvent) event); |
| 1442 | } else if (event.type() == HostEvent.Type.HOST_UPDATED) { |
| 1443 | hostHandler.processHostUpdatedEvent((HostEvent) event); |
| 1444 | } else if (event.type() == RouteEvent.Type.ROUTE_ADDED) { |
| 1445 | routeHandler.processRouteAdded((RouteEvent) event); |
| 1446 | } else if (event.type() == RouteEvent.Type.ROUTE_UPDATED) { |
| 1447 | routeHandler.processRouteUpdated((RouteEvent) event); |
| 1448 | } else if (event.type() == RouteEvent.Type.ROUTE_REMOVED) { |
| 1449 | routeHandler.processRouteRemoved((RouteEvent) event); |
| 1450 | } else if (event.type() == RouteEvent.Type.ALTERNATIVE_ROUTES_CHANGED) { |
| 1451 | routeHandler.processAlternativeRoutesChanged((RouteEvent) event); |
| 1452 | } else if (event.type() == McastEvent.Type.SOURCES_ADDED || |
| 1453 | event.type() == McastEvent.Type.SOURCES_REMOVED || |
| 1454 | event.type() == McastEvent.Type.SINKS_ADDED || |
| 1455 | event.type() == McastEvent.Type.SINKS_REMOVED || |
| 1456 | event.type() == McastEvent.Type.ROUTE_ADDED || |
| 1457 | event.type() == McastEvent.Type.ROUTE_REMOVED) { |
| 1458 | mcastHandler.processMcastEvent((McastEvent) event); |
| 1459 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) { |
| 1460 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1461 | Class configClass = netcfgEvent.configClass(); |
| 1462 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1463 | appCfgHandler.processAppConfigAdded(netcfgEvent); |
| 1464 | log.info("App config event .. configuring network"); |
| 1465 | cfgListener.configureNetwork(); |
| 1466 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1467 | log.info("Segment Routing Device Config added for {}", event.subject()); |
| 1468 | cfgListener.configureNetwork(); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1469 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1470 | log.info("Interface Config added for {}", event.subject()); |
| 1471 | cfgListener.configureNetwork(); |
| 1472 | } else { |
| 1473 | log.error("Unhandled config class: {}", configClass); |
| 1474 | } |
| 1475 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) { |
| 1476 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1477 | Class configClass = netcfgEvent.configClass(); |
| 1478 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1479 | appCfgHandler.processAppConfigUpdated(netcfgEvent); |
| 1480 | log.info("App config event .. configuring network"); |
| 1481 | cfgListener.configureNetwork(); |
| 1482 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1483 | log.info("Segment Routing Device Config updated for {}", event.subject()); |
| 1484 | createOrUpdateDeviceConfiguration(); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1485 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1486 | log.info("Interface Config updated for {}", event.subject()); |
| 1487 | createOrUpdateDeviceConfiguration(); |
| 1488 | updateInterface((InterfaceConfig) netcfgEvent.config().get(), |
| 1489 | (InterfaceConfig) netcfgEvent.prevConfig().get()); |
| 1490 | } else { |
| 1491 | log.error("Unhandled config class: {}", configClass); |
| 1492 | } |
| 1493 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) { |
| 1494 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1495 | Class configClass = netcfgEvent.configClass(); |
| 1496 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1497 | appCfgHandler.processAppConfigRemoved(netcfgEvent); |
| 1498 | log.info("App config event .. configuring network"); |
| 1499 | cfgListener.configureNetwork(); |
| 1500 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1501 | // TODO Handle sr device config removal |
| 1502 | log.info("SegmentRoutingDeviceConfig removal is not handled in current implementation"); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1503 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1504 | // TODO Handle interface removal |
| 1505 | log.info("InterfaceConfig removal is not handled in current implementation"); |
| 1506 | } else { |
| 1507 | log.error("Unhandled config class: {}", configClass); |
| 1508 | } |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1509 | } else if (event.type() == MastershipEvent.Type.MASTER_CHANGED) { |
| 1510 | MastershipEvent me = (MastershipEvent) event; |
| 1511 | DeviceId deviceId = me.subject(); |
| 1512 | Optional<DeviceId> pairDeviceId = getPairDeviceId(deviceId); |
| 1513 | log.info(" ** MASTERSHIP CHANGED Invalidating shouldProgram cache" |
| 1514 | + " for {}/pair={} due to change", deviceId, pairDeviceId); |
| 1515 | defaultRoutingHandler.invalidateShouldProgramCache(deviceId); |
| 1516 | pairDeviceId.ifPresent(defaultRoutingHandler::invalidateShouldProgramCache); |
| 1517 | defaultRoutingHandler.checkFullRerouteForMasterChange(deviceId, me); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1518 | } else { |
| 1519 | log.warn("Unhandled event type: {}", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1520 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1521 | } catch (Exception e) { |
| 1522 | log.error("SegmentRouting event handler thread thrown an exception: {}", |
| 1523 | e.getMessage(), e); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1524 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 1528 | void processDeviceAdded(Device device) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1529 | log.info("** DEVICE ADDED with ID {}", device.id()); |
Charles Chan | 9bd6aea | 2017-06-27 18:48:32 -0700 | [diff] [blame] | 1530 | |
| 1531 | // NOTE: Punt ARP/NDP even when the device is not configured. |
| 1532 | // Host learning without network config is required for CORD config generator. |
| 1533 | routingRulePopulator.populateIpPunts(device.id()); |
| 1534 | routingRulePopulator.populateArpNdpPunts(device.id()); |
| 1535 | |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1536 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1537 | log.warn("Device configuration unavailable. Device {} will be " |
| 1538 | + "processed after configuration.", device.id()); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1539 | return; |
| 1540 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1541 | processDeviceAddedInternal(device.id()); |
| 1542 | } |
| 1543 | |
| 1544 | private void processDeviceAddedInternal(DeviceId deviceId) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1545 | // Irrespective of whether the local is a MASTER or not for this device, |
| 1546 | // we need to create a SR-group-handler instance. This is because in a |
| 1547 | // multi-instance setup, any instance can initiate forwarding/next-objectives |
| 1548 | // for any switch (even if this instance is a SLAVE or not even connected |
| 1549 | // to the switch). To handle this, a default-group-handler instance is necessary |
| 1550 | // per switch. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1551 | log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet()); |
| 1552 | if (groupHandlerMap.get(deviceId) == null) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1553 | DefaultGroupHandler groupHandler; |
| 1554 | try { |
| 1555 | groupHandler = DefaultGroupHandler. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1556 | createGroupHandler(deviceId, |
| 1557 | appId, |
| 1558 | deviceConfiguration, |
| 1559 | linkService, |
| 1560 | flowObjectiveService, |
| 1561 | this); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1562 | } catch (DeviceConfigNotFoundException e) { |
| 1563 | log.warn(e.getMessage() + " Aborting processDeviceAdded."); |
| 1564 | return; |
| 1565 | } |
Saurav Das | 2b6a00f | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 1566 | log.debug("updating groupHandlerMap with new grpHdlr for device: {}", |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1567 | deviceId); |
| 1568 | groupHandlerMap.put(deviceId, groupHandler); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1569 | } |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1570 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1571 | if (mastershipService.isLocalMaster(deviceId)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1572 | defaultRoutingHandler.populatePortAddressingRules(deviceId); |
pier | f331a49 | 2020-01-07 15:39:39 +0100 | [diff] [blame] | 1573 | defaultRoutingHandler.purgeSeenBeforeRoutes(deviceId); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1574 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1575 | groupHandler.createGroupsFromVlanConfig(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1576 | routingRulePopulator.populateSubnetBroadcastRule(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1577 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1578 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1579 | appCfgHandler.init(deviceId); |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 1580 | hostEventExecutor.execute(() -> hostHandler.init(deviceId)); |
| 1581 | routeEventExecutor.execute(() -> routeHandler.init(deviceId)); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1584 | private void processDeviceRemoved(Device device) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1585 | dsNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1586 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 1587 | .forEach(entry -> dsNextObjStore.remove(entry.getKey())); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1588 | vlanNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1589 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1590 | .forEach(entry -> vlanNextObjStore.remove(entry.getKey())); |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 1591 | macVlanNextObjStore.entrySet().stream() |
| 1592 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
| 1593 | .forEach(entry -> macVlanNextObjStore.remove(entry.getKey())); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1594 | portNextObjStore.entrySet().stream() |
| 1595 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1596 | .forEach(entry -> portNextObjStore.remove(entry.getKey())); |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 1597 | linkHandler.processDeviceRemoved(device); |
Charles Chan | 17d75d8 | 2017-06-15 00:44:51 -0700 | [diff] [blame] | 1598 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1599 | DefaultGroupHandler gh = groupHandlerMap.remove(device.id()); |
| 1600 | if (gh != null) { |
| 1601 | gh.shutdown(); |
| 1602 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1603 | // Note that a switch going down is associated with all of its links |
| 1604 | // going down as well, but it is treated as a single switch down event |
Saurav Das | debcf88 | 2018-04-06 20:16:01 -0700 | [diff] [blame] | 1605 | // while the link-downs are ignored. We cannot rely on the ordering of |
| 1606 | // events - i.e we cannot expect all link-downs to come before the |
| 1607 | // switch down - so we purge all seen-links for the switch before |
| 1608 | // handling route-path changes for the switch-down |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1609 | defaultRoutingHandler |
Saurav Das | dc7f275 | 2018-03-18 21:28:15 -0700 | [diff] [blame] | 1610 | .populateRoutingRulesForLinkStatusChange(null, null, device.id(), true); |
Saurav Das | 6430f41 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1611 | defaultRoutingHandler.purgeEcmpGraph(device.id()); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1612 | |
| 1613 | // Cleanup all internal groupHandler stores for this device. Should be |
| 1614 | // done after all rerouting or rehashing has been completed |
| 1615 | groupHandlerMap.entrySet() |
| 1616 | .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id())); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 1619 | /** |
| 1620 | * Purge the destinationSet nextObjective store of entries with this device |
| 1621 | * as key. Erases app-level knowledge of hashed groups in this device. |
| 1622 | * |
| 1623 | * @param devId the device identifier |
| 1624 | */ |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1625 | void purgeHashedNextObjectiveStore(DeviceId devId) { |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 1626 | log.debug("Purging hashed next-obj store for dev:{}", devId); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1627 | dsNextObjStore.entrySet().stream() |
| 1628 | .filter(entry -> entry.getKey().deviceId().equals(devId)) |
| 1629 | .forEach(entry -> dsNextObjStore.remove(entry.getKey())); |
| 1630 | } |
| 1631 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1632 | private void processPortUpdatedInternal(Device device, Port port) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1633 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
| 1634 | log.warn("Device configuration uploading. Not handling port event for" |
| 1635 | + "dev: {} port: {}", device.id(), port.number()); |
| 1636 | return; |
| 1637 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1638 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1639 | if (interfaceService.isConfigured(new ConnectPoint(device.id(), port.number()))) { |
| 1640 | lastEdgePortEvent = Instant.now(); |
| 1641 | } |
| 1642 | |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1643 | if (!mastershipService.isLocalMaster(device.id())) { |
| 1644 | log.debug("Not master for dev:{} .. not handling port updated event" |
| 1645 | + "for port {}", device.id(), port.number()); |
| 1646 | return; |
| 1647 | } |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1648 | processPortUpdated(device.id(), port); |
| 1649 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1650 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1651 | /** |
| 1652 | * Adds or remove filtering rules for the given switchport. If switchport is |
| 1653 | * an edge facing port, additionally handles host probing and broadcast |
| 1654 | * rules. Must be called by local master of device. |
| 1655 | * |
| 1656 | * @param deviceId the device identifier |
| 1657 | * @param port the port to update |
| 1658 | */ |
| 1659 | void processPortUpdated(DeviceId deviceId, Port port) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1660 | // first we handle filtering rules associated with the port |
| 1661 | if (port.isEnabled()) { |
| 1662 | log.info("Switchport {}/{} enabled..programming filters", |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1663 | deviceId, port.number()); |
| 1664 | routingRulePopulator.processSinglePortFilters(deviceId, port.number(), true); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1665 | } else { |
| 1666 | log.info("Switchport {}/{} disabled..removing filters", |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1667 | deviceId, port.number()); |
| 1668 | routingRulePopulator.processSinglePortFilters(deviceId, port.number(), false); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1669 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1670 | |
| 1671 | // portUpdated calls are for ports that have gone down or up. For switch |
| 1672 | // to switch ports, link-events should take care of any re-routing or |
| 1673 | // group editing necessary for port up/down. Here we only process edge ports |
| 1674 | // that are already configured. |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1675 | ConnectPoint cp = new ConnectPoint(deviceId, port.number()); |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1676 | VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp); |
| 1677 | VlanId nativeVlan = interfaceService.getNativeVlanId(cp); |
| 1678 | Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1679 | |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1680 | if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1681 | log.debug("Not handling port updated event for non-edge port (unconfigured) " |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1682 | + "dev/port: {}/{}", deviceId, port.number()); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1683 | return; |
| 1684 | } |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1685 | if (untaggedVlan != null) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1686 | processEdgePort(deviceId, port, untaggedVlan, true); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1687 | } |
| 1688 | if (nativeVlan != null) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1689 | processEdgePort(deviceId, port, nativeVlan, true); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1690 | } |
| 1691 | if (!taggedVlans.isEmpty()) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1692 | taggedVlans.forEach(tag -> processEdgePort(deviceId, port, tag, false)); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1693 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1696 | private void processEdgePort(DeviceId deviceId, Port port, VlanId vlanId, |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1697 | boolean popVlan) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1698 | boolean portUp = port.isEnabled(); |
| 1699 | if (portUp) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1700 | log.info("Device:EdgePort {}:{} is enabled in vlan: {}", deviceId, |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1701 | port.number(), vlanId); |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 1702 | hostEventExecutor.execute(() -> hostHandler.processPortUp(new ConnectPoint(deviceId, port.number()))); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1703 | } else { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1704 | log.info("Device:EdgePort {}:{} is disabled in vlan: {}", deviceId, |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1705 | port.number(), vlanId); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1706 | } |
| 1707 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1708 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1709 | if (groupHandler != null) { |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1710 | groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1711 | } else { |
| 1712 | log.warn("Group handler not found for dev:{}. Not handling edge port" |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1713 | + " {} event for port:{}", deviceId, |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1714 | (portUp) ? "UP" : "DOWN", port.number()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1715 | } |
| 1716 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1717 | |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1718 | private void createOrUpdateDeviceConfiguration() { |
| 1719 | if (deviceConfiguration == null) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1720 | log.info("Creating new DeviceConfiguration"); |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1721 | deviceConfiguration = new DeviceConfiguration(this); |
| 1722 | } else { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1723 | log.info("Updating DeviceConfiguration"); |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1724 | deviceConfiguration.updateConfig(); |
| 1725 | } |
| 1726 | } |
| 1727 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1728 | private void createOrUpdateDefaultRoutingHandler() { |
| 1729 | if (defaultRoutingHandler == null) { |
| 1730 | log.info("Creating new DefaultRoutingHandler"); |
| 1731 | defaultRoutingHandler = new DefaultRoutingHandler(this); |
| 1732 | } else { |
| 1733 | log.info("Updating DefaultRoutingHandler"); |
| 1734 | defaultRoutingHandler.update(this); |
| 1735 | } |
| 1736 | } |
| 1737 | |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1738 | /** |
| 1739 | * Registers the given connect point with the NRS, this is necessary |
| 1740 | * to receive the NDP and ARP packets from the NRS. |
| 1741 | * |
| 1742 | * @param portToRegister connect point to register |
| 1743 | */ |
| 1744 | public void registerConnectPoint(ConnectPoint portToRegister) { |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 1745 | neighbourResolutionService.registerNeighbourHandler( |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1746 | portToRegister, |
| 1747 | neighbourHandler, |
| 1748 | appId |
| 1749 | ); |
| 1750 | } |
| 1751 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1752 | private class InternalConfigListener implements NetworkConfigListener { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1753 | private static final long PROGRAM_DELAY = 2; |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1754 | SegmentRoutingManager srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1755 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1756 | /** |
| 1757 | * Constructs the internal network config listener. |
| 1758 | * |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1759 | * @param srManager segment routing manager |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1760 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1761 | InternalConfigListener(SegmentRoutingManager srManager) { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1762 | this.srManager = srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1765 | /** |
| 1766 | * Reads network config and initializes related data structure accordingly. |
| 1767 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 1768 | void configureNetwork() { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1769 | log.info("Configuring network ..."); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1770 | |
| 1771 | // Setting handling of network configuration events completable future |
| 1772 | // The completable future is needed because of the async behaviour of the configureNetwork, |
| 1773 | // listener registration and event arrival |
| 1774 | // Enables us to buffer the events and execute them when the configure network is done. |
Ray Milkey | 521e439 | 2018-11-16 15:15:14 -0800 | [diff] [blame] | 1775 | synchronized (networkConfigCompletionLock) { |
| 1776 | networkConfigCompletion = new CompletableFuture<>(); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1777 | |
Ray Milkey | 521e439 | 2018-11-16 15:15:14 -0800 | [diff] [blame] | 1778 | // add a small delay to absorb multiple network config added notifications |
| 1779 | if (!programmingScheduled.get()) { |
| 1780 | log.info("Buffering config calls for {} secs", PROGRAM_DELAY); |
| 1781 | programmingScheduled.set(true); |
| 1782 | mainEventExecutor.schedule(new ConfigChange(), PROGRAM_DELAY, TimeUnit.SECONDS); |
| 1783 | } |
| 1784 | |
| 1785 | createOrUpdateDeviceConfiguration(); |
| 1786 | |
| 1787 | arpHandler = new ArpHandler(srManager); |
| 1788 | icmpHandler = new IcmpHandler(srManager); |
| 1789 | ipHandler = new IpHandler(srManager); |
| 1790 | routingRulePopulator = new RoutingRulePopulator(srManager); |
| 1791 | createOrUpdateDefaultRoutingHandler(); |
| 1792 | |
| 1793 | tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
| 1794 | groupHandlerMap, tunnelStore); |
| 1795 | policyHandler = new PolicyHandler(appId, deviceConfiguration, |
| 1796 | flowObjectiveService, |
| 1797 | tunnelHandler, policyStore); |
| 1798 | networkConfigCompletion.complete(true); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1801 | mcastHandler.init(); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1802 | |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1805 | @Override |
| 1806 | public void event(NetworkConfigEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1807 | if (mainEventExecutor == null) { |
| 1808 | return; |
| 1809 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1810 | checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized"); |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1811 | switch (event.type()) { |
| 1812 | case CONFIG_ADDED: |
| 1813 | case CONFIG_UPDATED: |
| 1814 | case CONFIG_REMOVED: |
| 1815 | log.trace("Schedule Network Config event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1816 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1817 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1818 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1819 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1820 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1821 | break; |
| 1822 | default: |
| 1823 | break; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1824 | } |
| 1825 | } |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1826 | |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1827 | @Override |
| 1828 | public boolean isRelevant(NetworkConfigEvent event) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1829 | if (event.type() == CONFIG_REGISTERED || |
| 1830 | event.type() == CONFIG_UNREGISTERED) { |
| 1831 | log.debug("Ignore event {} due to type mismatch", event); |
| 1832 | return false; |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1833 | } |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1834 | |
| 1835 | if (!event.configClass().equals(SegmentRoutingDeviceConfig.class) && |
| 1836 | !event.configClass().equals(SegmentRoutingAppConfig.class) && |
Charles Chan | a01d57c | 2019-07-19 16:25:38 -0700 | [diff] [blame] | 1837 | !event.configClass().equals(InterfaceConfig.class)) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1838 | log.debug("Ignore event {} due to class mismatch", event); |
| 1839 | return false; |
| 1840 | } |
| 1841 | |
| 1842 | return true; |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1843 | } |
| 1844 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1845 | private final class ConfigChange implements Runnable { |
| 1846 | @Override |
| 1847 | public void run() { |
| 1848 | programmingScheduled.set(false); |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1849 | log.info("Reacting to config changes after buffer delay"); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1850 | for (Device device : deviceService.getDevices()) { |
| 1851 | processDeviceAdded(device); |
| 1852 | } |
| 1853 | defaultRoutingHandler.startPopulationProcess(); |
| 1854 | } |
| 1855 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1856 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1857 | |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1858 | private class InternalLinkListener implements LinkListener { |
| 1859 | @Override |
| 1860 | public void event(LinkEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1861 | if (mainEventExecutor == null) { |
| 1862 | return; |
| 1863 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1864 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 1865 | event.type() == LinkEvent.Type.LINK_UPDATED || |
| 1866 | event.type() == LinkEvent.Type.LINK_REMOVED) { |
| 1867 | log.trace("Schedule Link event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1868 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1869 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1870 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1871 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1872 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | private class InternalDeviceListener implements DeviceListener { |
| 1878 | @Override |
| 1879 | public void event(DeviceEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1880 | if (mainEventExecutor == null) { |
| 1881 | return; |
| 1882 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1883 | switch (event.type()) { |
| 1884 | case DEVICE_ADDED: |
| 1885 | case PORT_UPDATED: |
| 1886 | case PORT_ADDED: |
| 1887 | case DEVICE_UPDATED: |
| 1888 | case DEVICE_AVAILABILITY_CHANGED: |
| 1889 | log.trace("Schedule Device event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1890 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1891 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1892 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1893 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1894 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1895 | break; |
| 1896 | default: |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | private class InternalTopologyListener implements TopologyListener { |
| 1902 | @Override |
| 1903 | public void event(TopologyEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1904 | if (mainEventExecutor == null) { |
| 1905 | return; |
| 1906 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1907 | switch (event.type()) { |
| 1908 | case TOPOLOGY_CHANGED: |
| 1909 | log.trace("Schedule Topology event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1910 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1911 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1912 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1913 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1914 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1915 | break; |
| 1916 | default: |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1921 | private class InternalHostListener implements HostListener { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1922 | @Override |
| 1923 | public void event(HostEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1924 | if (hostEventExecutor == null) { |
| 1925 | return; |
| 1926 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1927 | switch (event.type()) { |
| 1928 | case HOST_ADDED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1929 | case HOST_MOVED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1930 | case HOST_REMOVED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1931 | case HOST_UPDATED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1932 | log.trace("Schedule Host event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1933 | hostEventExecutor.execute(new InternalEventHandler(event)); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1934 | break; |
| 1935 | default: |
| 1936 | log.warn("Unsupported host event type: {}", event.type()); |
| 1937 | break; |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1942 | private class InternalMcastListener implements McastListener { |
| 1943 | @Override |
| 1944 | public void event(McastEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1945 | if (mcastEventExecutor == null) { |
| 1946 | return; |
| 1947 | } |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1948 | switch (event.type()) { |
Pier | 1f87aca | 2018-03-14 16:47:32 -0700 | [diff] [blame] | 1949 | case SOURCES_ADDED: |
| 1950 | case SOURCES_REMOVED: |
| 1951 | case SINKS_ADDED: |
| 1952 | case SINKS_REMOVED: |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1953 | case ROUTE_REMOVED: |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 1954 | case ROUTE_ADDED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1955 | log.trace("Schedule Mcast event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1956 | mcastEventExecutor.execute(new InternalEventHandler(event)); |
Pier Luigi | 6786b92 | 2018-02-02 16:19:11 +0100 | [diff] [blame] | 1957 | break; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1958 | default: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1959 | log.warn("Unsupported mcast event type: {}", event.type()); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1960 | break; |
| 1961 | } |
| 1962 | } |
| 1963 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 1964 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1965 | private class InternalRouteEventListener implements RouteListener { |
| 1966 | @Override |
| 1967 | public void event(RouteEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1968 | if (routeEventExecutor == null) { |
| 1969 | return; |
| 1970 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1971 | switch (event.type()) { |
| 1972 | case ROUTE_ADDED: |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1973 | case ROUTE_UPDATED: |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1974 | case ROUTE_REMOVED: |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 1975 | case ALTERNATIVE_ROUTES_CHANGED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1976 | log.trace("Schedule Route event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1977 | routeEventExecutor.execute(new InternalEventHandler(event)); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 1978 | break; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1979 | default: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1980 | log.warn("Unsupported route event type: {}", event.type()); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1981 | break; |
| 1982 | } |
| 1983 | } |
| 1984 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1985 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1986 | private class InternalMastershipListener implements MastershipListener { |
| 1987 | @Override |
| 1988 | public void event(MastershipEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1989 | if (mainEventExecutor == null) { |
| 1990 | return; |
| 1991 | } |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1992 | switch (event.type()) { |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1993 | case MASTER_CHANGED: |
| 1994 | log.debug("Mastership event: {}/{}", event.subject(), |
| 1995 | event.roleInfo()); |
| 1996 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1997 | break; |
| 1998 | case BACKUPS_CHANGED: |
| 1999 | case SUSPENDED: |
| 2000 | default: |
| 2001 | log.debug("Mastership event type {} not handled", event.type()); |
| 2002 | break; |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 2007 | class InternalClusterListener implements ClusterEventListener { |
| 2008 | private Instant lastClusterEvent = Instant.EPOCH; |
| 2009 | |
| 2010 | long timeSinceLastClusterEvent() { |
| 2011 | return Instant.now().toEpochMilli() - lastClusterEvent.toEpochMilli(); |
| 2012 | } |
| 2013 | |
| 2014 | @Override |
| 2015 | public void event(ClusterEvent event) { |
| 2016 | switch (event.type()) { |
| 2017 | case INSTANCE_ACTIVATED: |
| 2018 | case INSTANCE_ADDED: |
| 2019 | case INSTANCE_READY: |
| 2020 | log.debug("Cluster event {} ignored", event.type()); |
| 2021 | break; |
| 2022 | case INSTANCE_DEACTIVATED: |
| 2023 | case INSTANCE_REMOVED: |
| 2024 | log.info("** Cluster event {}", event.type()); |
| 2025 | lastClusterEvent = Instant.now(); |
| 2026 | break; |
| 2027 | default: |
| 2028 | break; |
| 2029 | } |
| 2030 | |
| 2031 | } |
| 2032 | |
| 2033 | } |
| 2034 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2035 | private void updateInterface(InterfaceConfig conf, InterfaceConfig prevConf) { |
| 2036 | try { |
| 2037 | Set<Interface> intfs = conf.getInterfaces(); |
| 2038 | Set<Interface> prevIntfs = prevConf.getInterfaces(); |
| 2039 | |
| 2040 | // Now we only handle one interface config at each port. |
| 2041 | if (intfs.size() != 1 || prevIntfs.size() != 1) { |
| 2042 | log.warn("Interface update aborted - one at a time is allowed, " + |
| 2043 | "but {} / {}(prev) received.", intfs.size(), prevIntfs.size()); |
| 2044 | return; |
| 2045 | } |
| 2046 | |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 2047 | //The system is in an incoherent state, abort |
| 2048 | if (defaultRoutingHandler == null) { |
| 2049 | log.warn("Interface update aborted, defaultRoutingHandler is null"); |
| 2050 | return; |
| 2051 | } |
| 2052 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2053 | Interface intf = intfs.stream().findFirst().get(); |
| 2054 | Interface prevIntf = prevIntfs.stream().findFirst().get(); |
| 2055 | |
| 2056 | DeviceId deviceId = intf.connectPoint().deviceId(); |
| 2057 | PortNumber portNum = intf.connectPoint().port(); |
| 2058 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2059 | removeSubnetConfig(prevIntf.connectPoint(), |
| 2060 | Sets.difference(new HashSet<>(prevIntf.ipAddressesList()), |
| 2061 | new HashSet<>(intf.ipAddressesList()))); |
| 2062 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2063 | if (!prevIntf.vlanNative().equals(VlanId.NONE) |
| 2064 | && !prevIntf.vlanNative().equals(intf.vlanUntagged()) |
| 2065 | && !prevIntf.vlanNative().equals(intf.vlanNative())) { |
| 2066 | if (intf.vlanTagged().contains(prevIntf.vlanNative())) { |
| 2067 | // Update filtering objective and L2IG group bucket |
| 2068 | updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanNative(), false); |
| 2069 | } else { |
| 2070 | // RemoveVlanNative |
| 2071 | updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanNative(), true, false); |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | if (!prevIntf.vlanUntagged().equals(VlanId.NONE) |
| 2076 | && !prevIntf.vlanUntagged().equals(intf.vlanUntagged()) |
| 2077 | && !prevIntf.vlanUntagged().equals(intf.vlanNative())) { |
| 2078 | if (intf.vlanTagged().contains(prevIntf.vlanUntagged())) { |
| 2079 | // Update filtering objective and L2IG group bucket |
| 2080 | updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanUntagged(), false); |
| 2081 | } else { |
| 2082 | // RemoveVlanUntagged |
| 2083 | updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanUntagged(), true, false); |
| 2084 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | if (!prevIntf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) { |
| 2088 | // RemoveVlanTagged |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2089 | Sets.difference(prevIntf.vlanTagged(), intf.vlanTagged()).stream() |
| 2090 | .filter(i -> !intf.vlanUntagged().equals(i)) |
| 2091 | .filter(i -> !intf.vlanNative().equals(i)) |
| 2092 | .forEach(vlanId -> updateVlanConfigInternal( |
| 2093 | deviceId, portNum, vlanId, false, false)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2096 | if (!intf.vlanNative().equals(VlanId.NONE) |
| 2097 | && !prevIntf.vlanNative().equals(intf.vlanNative()) |
| 2098 | && !prevIntf.vlanUntagged().equals(intf.vlanNative())) { |
| 2099 | if (prevIntf.vlanTagged().contains(intf.vlanNative())) { |
| 2100 | // Update filtering objective and L2IG group bucket |
| 2101 | updatePortVlanTreatment(deviceId, portNum, intf.vlanNative(), true); |
| 2102 | } else { |
| 2103 | // AddVlanNative |
| 2104 | updateVlanConfigInternal(deviceId, portNum, intf.vlanNative(), true, true); |
| 2105 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | if (!intf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) { |
| 2109 | // AddVlanTagged |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2110 | Sets.difference(intf.vlanTagged(), prevIntf.vlanTagged()).stream() |
| 2111 | .filter(i -> !prevIntf.vlanUntagged().equals(i)) |
| 2112 | .filter(i -> !prevIntf.vlanNative().equals(i)) |
| 2113 | .forEach(vlanId -> updateVlanConfigInternal( |
| 2114 | deviceId, portNum, vlanId, false, true) |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2115 | ); |
| 2116 | } |
| 2117 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2118 | if (!intf.vlanUntagged().equals(VlanId.NONE) |
| 2119 | && !prevIntf.vlanUntagged().equals(intf.vlanUntagged()) |
| 2120 | && !prevIntf.vlanNative().equals(intf.vlanUntagged())) { |
| 2121 | if (prevIntf.vlanTagged().contains(intf.vlanUntagged())) { |
| 2122 | // Update filtering objective and L2IG group bucket |
| 2123 | updatePortVlanTreatment(deviceId, portNum, intf.vlanUntagged(), true); |
| 2124 | } else { |
| 2125 | // AddVlanUntagged |
| 2126 | updateVlanConfigInternal(deviceId, portNum, intf.vlanUntagged(), true, true); |
| 2127 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2128 | } |
| 2129 | addSubnetConfig(prevIntf.connectPoint(), |
| 2130 | Sets.difference(new HashSet<>(intf.ipAddressesList()), |
| 2131 | new HashSet<>(prevIntf.ipAddressesList()))); |
| 2132 | } catch (ConfigException e) { |
| 2133 | log.error("Error in configuration"); |
| 2134 | } |
| 2135 | } |
| 2136 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2137 | private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum, |
| 2138 | VlanId vlanId, boolean pushVlan) { |
| 2139 | DefaultGroupHandler grpHandler = getGroupHandler(deviceId); |
| 2140 | if (grpHandler == null) { |
| 2141 | log.warn("Failed to retrieve group handler for device {}", deviceId); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | // Update filtering objective for a single port |
| 2146 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false); |
| 2147 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true); |
| 2148 | |
| 2149 | if (getVlanNextObjectiveId(deviceId, vlanId) != -1) { |
| 2150 | // Update L2IG bucket of the port |
| 2151 | grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan); |
| 2152 | } else { |
| 2153 | log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum); |
| 2154 | } |
| 2155 | } |
| 2156 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2157 | private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum, |
| 2158 | VlanId vlanId, boolean pushVlan, boolean install) { |
| 2159 | DefaultGroupHandler grpHandler = getGroupHandler(deviceId); |
| 2160 | if (grpHandler == null) { |
| 2161 | log.warn("Failed to retrieve group handler for device {}", deviceId); |
| 2162 | return; |
| 2163 | } |
| 2164 | |
| 2165 | // Update filtering objective for a single port |
| 2166 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install); |
| 2167 | |
| 2168 | // Update filtering objective for multicast ingress port |
| 2169 | mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install); |
| 2170 | |
| 2171 | int nextId = getVlanNextObjectiveId(deviceId, vlanId); |
| 2172 | |
| 2173 | if (nextId != -1 && !install) { |
| 2174 | // Update next objective for a single port as an output port |
| 2175 | // Remove a single port from L2FG |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2176 | grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2177 | // Remove L2 Bridging rule and L3 Unicast rule to the host |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2178 | hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, |
| 2179 | vlanId, pushVlan, install)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2180 | // Remove broadcast forwarding rule and corresponding L2FG for VLAN |
| 2181 | // only if there is no port configured on that VLAN ID |
| 2182 | if (!getVlanPortMap(deviceId).containsKey(vlanId)) { |
| 2183 | // Remove broadcast forwarding rule for the VLAN |
| 2184 | routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install); |
| 2185 | // Remove L2FG for VLAN |
| 2186 | grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan); |
| 2187 | } else { |
| 2188 | // Remove L2IG of the port |
| 2189 | grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan); |
| 2190 | } |
| 2191 | } else if (install) { |
| 2192 | if (nextId != -1) { |
| 2193 | // Add a single port to L2FG |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2194 | grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2195 | } else { |
| 2196 | // Create L2FG for VLAN |
| 2197 | grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum)); |
| 2198 | routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install); |
| 2199 | } |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2200 | hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, |
| 2201 | vlanId, pushVlan, install)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2202 | } else { |
| 2203 | log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum); |
| 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | private void removeSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) { |
| 2208 | Set<IpPrefix> ipPrefixSet = ipAddressSet.stream(). |
| 2209 | map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet()); |
| 2210 | |
| 2211 | Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream() |
| 2212 | .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId())) |
| 2213 | .filter(intf -> !intf.connectPoint().equals(cp)) |
| 2214 | .flatMap(intf -> intf.ipAddressesList().stream()) |
| 2215 | .collect(Collectors.toSet()); |
| 2216 | // 1. Partial subnet population |
| 2217 | // Remove routing rules for removed subnet from previous configuration, |
| 2218 | // which does not also exist in other interfaces in the same device |
| 2219 | Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream() |
| 2220 | .map(InterfaceIpAddress::subnetAddress) |
| 2221 | .collect(Collectors.toSet()); |
| 2222 | |
Shibu Vijayakumar | 5e26f8c | 2020-01-07 11:45:09 +0000 | [diff] [blame] | 2223 | Set<IpPrefix> subnetsToBeRevoked = ipPrefixSet.stream() |
| 2224 | .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)) |
| 2225 | .collect(Collectors.toSet()); |
| 2226 | |
| 2227 | // Check if any of the subnets to be revoked is configured in the pairDevice. |
| 2228 | // If any, repopulate the subnet with pairDevice connectPoint instead of revoking. |
| 2229 | Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId()); |
| 2230 | if (pairDevice.isPresent()) { |
| 2231 | Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get()); |
| 2232 | |
| 2233 | Set<IpPrefix> subnetsExistingInPairDevice = subnetsToBeRevoked.stream() |
| 2234 | .filter(ipPrefix -> pairDeviceIpPrefix.contains(ipPrefix)) |
| 2235 | .collect(Collectors.toSet()); |
| 2236 | |
| 2237 | // Update the subnets existing in pair device with pair device connect point. |
| 2238 | if (!subnetsExistingInPairDevice.isEmpty()) { |
| 2239 | // PortNumber of connect point is not relevant in populate subnet and hence providing as ANY. |
| 2240 | ConnectPoint pairDeviceCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY); |
| 2241 | log.debug("Updating the subnets: {} with pairDevice connectPoint as it exists in the Pair device: {}", |
| 2242 | subnetsExistingInPairDevice, pairDeviceCp); |
| 2243 | defaultRoutingHandler.populateSubnet(Collections.singleton(pairDeviceCp), subnetsExistingInPairDevice); |
| 2244 | } |
| 2245 | |
| 2246 | // Remove only the subnets that are not configured in the pairDevice. |
| 2247 | subnetsToBeRevoked = Sets.difference(subnetsToBeRevoked, subnetsExistingInPairDevice); |
| 2248 | } |
| 2249 | |
| 2250 | if (!subnetsToBeRevoked.isEmpty()) { |
| 2251 | log.debug("Removing subnets for connectPoint: {}, subnets: {}", cp, subnetsToBeRevoked); |
| 2252 | defaultRoutingHandler.revokeSubnet(subnetsToBeRevoked); |
| 2253 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2254 | |
| 2255 | // 2. Interface IP punts |
| 2256 | // Remove IP punts for old Intf address |
| 2257 | Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream() |
| 2258 | .map(InterfaceIpAddress::ipAddress) |
| 2259 | .collect(Collectors.toSet()); |
| 2260 | ipAddressSet.stream() |
| 2261 | .map(InterfaceIpAddress::ipAddress) |
| 2262 | .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress)) |
| 2263 | .forEach(interfaceIpAddress -> |
| 2264 | routingRulePopulator.revokeSingleIpPunts( |
| 2265 | cp.deviceId(), interfaceIpAddress)); |
| 2266 | |
| 2267 | // 3. Host unicast routing rule |
| 2268 | // Remove unicast routing rule |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2269 | hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) { |
| 2273 | Set<IpPrefix> ipPrefixSet = ipAddressSet.stream(). |
| 2274 | map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet()); |
| 2275 | |
| 2276 | Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream() |
| 2277 | .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId())) |
| 2278 | .filter(intf -> !intf.connectPoint().equals(cp)) |
| 2279 | .flatMap(intf -> intf.ipAddressesList().stream()) |
| 2280 | .collect(Collectors.toSet()); |
| 2281 | // 1. Partial subnet population |
| 2282 | // Add routing rules for newly added subnet, which does not also exist in |
| 2283 | // other interfaces in the same device |
| 2284 | Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream() |
| 2285 | .map(InterfaceIpAddress::subnetAddress) |
| 2286 | .collect(Collectors.toSet()); |
Shibu Vijayakumar | 5e26f8c | 2020-01-07 11:45:09 +0000 | [diff] [blame] | 2287 | Set<IpPrefix> subnetsToBePopulated = ipPrefixSet.stream() |
| 2288 | .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)) |
| 2289 | .collect(Collectors.toSet()); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2290 | |
Shibu Vijayakumar | 5e26f8c | 2020-01-07 11:45:09 +0000 | [diff] [blame] | 2291 | if (!subnetsToBePopulated.isEmpty()) { |
| 2292 | log.debug("Adding subnets for connectPoint: {}, subnets: {}", cp, subnetsToBePopulated); |
| 2293 | |
| 2294 | // check if pair-device has the same subnet configured? |
| 2295 | Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId()); |
| 2296 | if (pairDevice.isPresent()) { |
| 2297 | Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get()); |
| 2298 | |
| 2299 | Set<IpPrefix> subnetsToBePopulatedAsDualHomed = subnetsToBePopulated.stream() |
| 2300 | .filter(ipPrefix -> pairDeviceIpPrefix.contains(ipPrefix)) |
| 2301 | .collect(Collectors.toSet()); |
| 2302 | Set<IpPrefix> subnetsToBePopulatedAsSingleHomed = Sets.difference(subnetsToBePopulated, |
| 2303 | subnetsToBePopulatedAsDualHomed); |
| 2304 | |
| 2305 | if (!subnetsToBePopulatedAsSingleHomed.isEmpty()) { |
| 2306 | defaultRoutingHandler.populateSubnet( |
| 2307 | Collections.singleton(cp), |
| 2308 | subnetsToBePopulatedAsSingleHomed); |
| 2309 | } |
| 2310 | |
| 2311 | if (!subnetsToBePopulatedAsDualHomed.isEmpty()) { |
| 2312 | Set<ConnectPoint> cpts = new HashSet<>(); |
| 2313 | cpts.add(cp); |
| 2314 | // As Subnets is DualHomed adding the pairDevice also as ConnectPoint. |
| 2315 | // PortNumber of connect point is not relevant in populate subnet and hence providing as ANY. |
| 2316 | ConnectPoint pairCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY); |
| 2317 | cpts.add(pairCp); |
| 2318 | |
| 2319 | log.debug("Adding DualHomed subnets for connectPoint: {} and its pair device: {}, subnets: {}", |
| 2320 | cp, pairCp, subnetsToBePopulatedAsDualHomed); |
| 2321 | |
| 2322 | // populating the subnets as DualHomed |
| 2323 | defaultRoutingHandler.populateSubnet( |
| 2324 | cpts, |
| 2325 | subnetsToBePopulated); |
| 2326 | |
| 2327 | // revoking the subnets populated in the device as it is now Dualhomed. |
| 2328 | defaultRoutingHandler.revokeSubnet(Collections.singleton(cp.deviceId()), |
| 2329 | subnetsToBePopulatedAsDualHomed); |
| 2330 | } |
| 2331 | } else { |
| 2332 | defaultRoutingHandler.populateSubnet( |
| 2333 | Collections.singleton(cp), |
| 2334 | subnetsToBePopulated); |
| 2335 | } |
| 2336 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2337 | |
| 2338 | // 2. Interface IP punts |
| 2339 | // Add IP punts for new Intf address |
| 2340 | Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream() |
| 2341 | .map(InterfaceIpAddress::ipAddress) |
| 2342 | .collect(Collectors.toSet()); |
| 2343 | ipAddressSet.stream() |
| 2344 | .map(InterfaceIpAddress::ipAddress) |
| 2345 | .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress)) |
| 2346 | .forEach(interfaceIpAddress -> |
| 2347 | routingRulePopulator.populateSingleIpPunts( |
| 2348 | cp.deviceId(), interfaceIpAddress)); |
| 2349 | |
| 2350 | // 3. Host unicast routing rule |
| 2351 | // Add unicast routing rule |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2352 | hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2353 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 2354 | } |