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