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