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