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