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