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