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