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