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