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