sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 18 | import com.google.common.collect.HashMultimap; |
| 19 | import com.google.common.collect.ImmutableMap; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import com.google.common.collect.Multimap; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 22 | import com.google.common.collect.Sets; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 23 | import org.onlab.packet.Ethernet; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 24 | import org.onlab.packet.ICMP6; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 25 | import org.onlab.packet.IPv4; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 26 | import org.onlab.packet.IPv6; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 27 | import org.onlab.packet.IpAddress; |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 28 | import org.onlab.packet.IpPrefix; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 30 | import org.onlab.util.KryoNamespace; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 31 | import org.onlab.util.Tools; |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 32 | import org.onosproject.cfg.ComponentConfigService; |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 33 | import org.onosproject.cluster.ClusterEvent; |
| 34 | import org.onosproject.cluster.ClusterEventListener; |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 35 | import org.onosproject.cluster.ClusterService; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 36 | import org.onosproject.cluster.LeadershipService; |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 37 | import org.onosproject.cluster.NodeId; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 38 | import org.onosproject.core.ApplicationId; |
| 39 | import org.onosproject.core.CoreService; |
| 40 | import org.onosproject.event.Event; |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 41 | import org.onosproject.mastership.MastershipEvent; |
| 42 | import org.onosproject.mastership.MastershipListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 43 | import org.onosproject.mastership.MastershipService; |
Pier | 1f87aca | 2018-03-14 16:47:32 -0700 | [diff] [blame] | 44 | import org.onosproject.mcast.api.McastEvent; |
| 45 | import org.onosproject.mcast.api.McastListener; |
| 46 | import org.onosproject.mcast.api.MulticastRouteService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 47 | import org.onosproject.net.ConnectPoint; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 48 | import org.onosproject.net.Device; |
| 49 | import org.onosproject.net.DeviceId; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 50 | import org.onosproject.net.Host; |
| 51 | import org.onosproject.net.HostId; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 52 | import org.onosproject.net.Link; |
| 53 | import org.onosproject.net.Port; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 54 | import org.onosproject.net.PortNumber; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 55 | import org.onosproject.net.config.ConfigException; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 56 | import org.onosproject.net.config.ConfigFactory; |
| 57 | import org.onosproject.net.config.NetworkConfigEvent; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 58 | import org.onosproject.net.config.NetworkConfigListener; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 59 | import org.onosproject.net.config.NetworkConfigRegistry; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 60 | import org.onosproject.net.config.basics.InterfaceConfig; |
| 61 | import org.onosproject.net.config.basics.McastConfig; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 62 | import org.onosproject.net.config.basics.SubjectFactories; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 63 | import org.onosproject.net.device.DeviceAdminService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 64 | import org.onosproject.net.device.DeviceEvent; |
| 65 | import org.onosproject.net.device.DeviceListener; |
| 66 | import org.onosproject.net.device.DeviceService; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 67 | import org.onosproject.net.flow.TrafficSelector; |
| 68 | import org.onosproject.net.flow.TrafficTreatment; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 69 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 70 | import org.onosproject.net.flowobjective.NextObjective; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 71 | import org.onosproject.net.host.HostEvent; |
| 72 | import org.onosproject.net.host.HostListener; |
Charles Chan | c6bcdf9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 73 | import org.onosproject.net.host.HostProbingService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 74 | import org.onosproject.net.host.HostService; |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 75 | import org.onosproject.net.host.InterfaceIpAddress; |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 76 | import org.onosproject.net.intent.WorkPartitionService; |
Ray Milkey | ae0068a | 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 | b6a7f34 | 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; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 82 | import org.onosproject.net.neighbour.NeighbourResolutionService; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 83 | import org.onosproject.net.packet.InboundPacket; |
| 84 | import org.onosproject.net.packet.PacketContext; |
| 85 | import org.onosproject.net.packet.PacketProcessor; |
| 86 | import org.onosproject.net.packet.PacketService; |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 87 | import org.onosproject.net.topology.TopologyEvent; |
| 88 | import org.onosproject.net.topology.TopologyListener; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 89 | import org.onosproject.net.topology.TopologyService; |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 90 | import org.onosproject.routeservice.ResolvedRoute; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 91 | import org.onosproject.routeservice.RouteEvent; |
| 92 | import org.onosproject.routeservice.RouteListener; |
| 93 | import org.onosproject.routeservice.RouteService; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 94 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 95 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 96 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 97 | import org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 98 | import org.onosproject.segmentrouting.config.XConnectConfig; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 99 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 100 | import org.onosproject.segmentrouting.grouphandler.DestinationSet; |
| 101 | import org.onosproject.segmentrouting.grouphandler.NextNeighbors; |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 102 | import org.onosproject.segmentrouting.mcast.McastHandler; |
| 103 | import org.onosproject.segmentrouting.mcast.McastRole; |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 104 | import org.onosproject.segmentrouting.mcast.McastRoleStoreKey; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 105 | import org.onosproject.segmentrouting.mcast.McastStoreKey; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 106 | import org.onosproject.segmentrouting.pwaas.DefaultL2Tunnel; |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 107 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelDescription; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 108 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelHandler; |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 109 | import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 110 | import org.onosproject.segmentrouting.pwaas.L2Tunnel; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 111 | import org.onosproject.segmentrouting.pwaas.L2TunnelDescription; |
Ray Milkey | ae0068a | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 112 | import org.onosproject.segmentrouting.pwaas.L2TunnelHandler; |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 113 | import org.onosproject.segmentrouting.pwaas.L2TunnelPolicy; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 114 | import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 115 | import org.onosproject.segmentrouting.storekey.DummyVlanIdStoreKey; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 116 | import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 117 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 118 | import org.onosproject.segmentrouting.storekey.XConnectStoreKey; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 119 | import org.onosproject.segmentrouting.xconnect.api.XconnectService; |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 120 | import org.onosproject.store.serializers.KryoNamespaces; |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 121 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 122 | import org.onosproject.store.service.EventuallyConsistentMapBuilder; |
| 123 | import org.onosproject.store.service.StorageService; |
| 124 | import org.onosproject.store.service.WallClockTimestamp; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 125 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 126 | import org.osgi.service.component.annotations.Activate; |
| 127 | import org.osgi.service.component.annotations.Component; |
| 128 | import org.osgi.service.component.annotations.Deactivate; |
| 129 | import org.osgi.service.component.annotations.Modified; |
| 130 | import org.osgi.service.component.annotations.Reference; |
| 131 | import org.osgi.service.component.annotations.ReferenceCardinality; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 132 | import org.slf4j.Logger; |
| 133 | import org.slf4j.LoggerFactory; |
| 134 | |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 135 | import java.time.Instant; |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 136 | import java.util.ArrayList; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 137 | import java.util.Collections; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 138 | import java.util.Dictionary; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 139 | import java.util.HashSet; |
| 140 | import java.util.List; |
| 141 | import java.util.Map; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 142 | import java.util.Optional; |
| 143 | import java.util.Set; |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 144 | import java.util.concurrent.CompletableFuture; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 145 | import java.util.concurrent.ConcurrentHashMap; |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 146 | import java.util.concurrent.CopyOnWriteArrayList; |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 147 | import java.util.concurrent.ExecutorService; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 148 | import java.util.concurrent.Executors; |
| 149 | import java.util.concurrent.ScheduledExecutorService; |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 150 | import java.util.concurrent.TimeUnit; |
| 151 | import java.util.concurrent.atomic.AtomicBoolean; |
| 152 | import java.util.stream.Collectors; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 153 | import java.util.stream.IntStream; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 154 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 155 | import static com.google.common.base.Preconditions.checkState; |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 156 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
Yuta HIGUCHI | ebee2f1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 157 | import static org.onlab.util.Tools.groupedThreads; |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 158 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_REGISTERED; |
| 159 | import static org.onosproject.net.config.NetworkConfigEvent.Type.CONFIG_UNREGISTERED; |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 160 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.ACTIVE_PROBING_DEFAULT; |
| 161 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.DEFAULT_INTERNAL_VLAN_DEFAULT; |
| 162 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ACTIVE_PROBING; |
| 163 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_DEFAULT_INTERNAL_VLAN; |
| 164 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_PW_TRANSPORT_VLAN; |
| 165 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_RESPOND_TO_UNKNOWN_HOSTS; |
| 166 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_ROUTE_DOUBLE_TAGGED_HOSTS; |
| 167 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PROP_SINGLE_HOMED_DOWN; |
| 168 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.PW_TRANSPORT_VLAN_DEFAULT; |
| 169 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.RESPOND_TO_UNKNOWN_HOSTS_DEFAULT; |
| 170 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT; |
| 171 | import static org.onosproject.segmentrouting.OsgiPropertyConstants.SINGLE_HOMED_DOWN_DEFAULT; |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 172 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 173 | /** |
| 174 | * Segment routing manager. |
| 175 | */ |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 176 | @Component( |
| 177 | immediate = true, |
| 178 | service = SegmentRoutingService.class, |
| 179 | property = { |
| 180 | PROP_ACTIVE_PROBING + ":Boolean=" + ACTIVE_PROBING_DEFAULT, |
| 181 | PROP_SINGLE_HOMED_DOWN + ":Boolean=" + SINGLE_HOMED_DOWN_DEFAULT, |
| 182 | PROP_RESPOND_TO_UNKNOWN_HOSTS + ":Boolean=" + RESPOND_TO_UNKNOWN_HOSTS_DEFAULT, |
| 183 | PROP_ROUTE_DOUBLE_TAGGED_HOSTS + ":Boolean=" + ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT, |
| 184 | PROP_DEFAULT_INTERNAL_VLAN + ":Integer=" + DEFAULT_INTERNAL_VLAN_DEFAULT, |
| 185 | PROP_PW_TRANSPORT_VLAN + ":Integer=" + PW_TRANSPORT_VLAN_DEFAULT, |
| 186 | } |
| 187 | ) |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 188 | public class SegmentRoutingManager implements SegmentRoutingService { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 189 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 190 | private static Logger log = LoggerFactory.getLogger(SegmentRoutingManager.class); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 191 | private static final String NOT_MASTER = "Current instance is not the master of {}. Ignore."; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 192 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 193 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 194 | private ComponentConfigService compCfgService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 195 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 196 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 197 | private NeighbourResolutionService neighbourResolutionService; |
| 198 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 199 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 200 | public CoreService coreService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 201 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 202 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 203 | PacketService packetService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 204 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 205 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 206 | HostService hostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 207 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 208 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | c6bcdf9 | 2018-06-01 16:33:48 -0700 | [diff] [blame] | 209 | HostProbingService probingService; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 210 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 211 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 212 | public DeviceService deviceService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 213 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 214 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 215 | DeviceAdminService deviceAdminService; |
| 216 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 217 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 218 | public FlowObjectiveService flowObjectiveService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 219 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 220 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 221 | public LinkService linkService; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 222 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 223 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 224 | public MastershipService mastershipService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 225 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 226 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Ventre | f3cf5b9 | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 227 | public StorageService storageService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 228 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 229 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 230 | public MulticastRouteService multicastRouteService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 231 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 232 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8316381 | 2018-01-09 13:45:07 -0800 | [diff] [blame] | 233 | public TopologyService topologyService; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 234 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 235 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 236 | RouteService routeService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 237 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 238 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 239 | public NetworkConfigRegistry cfgService; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 240 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 241 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 242 | public InterfaceService interfaceService; |
| 243 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 244 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 245 | public ClusterService clusterService; |
| 246 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 247 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 248 | public WorkPartitionService workPartitionService; |
Pier Luigi | 580fd8a | 2018-01-16 10:47:50 +0100 | [diff] [blame] | 249 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 250 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 251 | public LeadershipService leadershipService; |
| 252 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 253 | @Reference(cardinality = ReferenceCardinality.OPTIONAL) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 254 | public XconnectService xconnectService; |
| 255 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 256 | /** Enable active probing to discover dual-homed hosts. */ |
| 257 | boolean activeProbing = ACTIVE_PROBING_DEFAULT; |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 258 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 259 | /** Enable administratively taking down single-homed hosts. */ |
| 260 | boolean singleHomedDown = SINGLE_HOMED_DOWN_DEFAULT; |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 261 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 262 | /** Enable this to respond to ARP/NDP requests from unknown hosts. */ |
| 263 | boolean respondToUnknownHosts = RESPOND_TO_UNKNOWN_HOSTS_DEFAULT; |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 264 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 265 | /** Program flows and groups to pop and route double tagged hosts. */ |
| 266 | boolean routeDoubleTaggedHosts = ROUTE_DOUBLE_TAGGED_HOSTS_DEFAULT; |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 267 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 268 | /** internal vlan assigned by default to unconfigured ports. */ |
| 269 | private int defaultInternalVlan = DEFAULT_INTERNAL_VLAN_DEFAULT; |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 270 | |
Ray Milkey | 05edbfc | 2018-10-23 14:23:16 -0700 | [diff] [blame] | 271 | /** vlan used for transport of pseudowires between switches. */ |
| 272 | private int pwTransportVlan = PW_TRANSPORT_VLAN_DEFAULT; |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 273 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 274 | ArpHandler arpHandler = null; |
| 275 | IcmpHandler icmpHandler = null; |
| 276 | IpHandler ipHandler = null; |
| 277 | RoutingRulePopulator routingRulePopulator = null; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 278 | ApplicationId appId; |
| 279 | DeviceConfiguration deviceConfiguration = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 280 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 281 | DefaultRoutingHandler defaultRoutingHandler = null; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 282 | private TunnelHandler tunnelHandler = null; |
| 283 | private PolicyHandler policyHandler = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 284 | private InternalPacketProcessor processor = null; |
| 285 | private InternalLinkListener linkListener = null; |
| 286 | private InternalDeviceListener deviceListener = null; |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 287 | private AppConfigHandler appCfgHandler = null; |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 288 | public XConnectHandler xConnectHandler = null; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 289 | McastHandler mcastHandler = null; |
| 290 | HostHandler hostHandler = null; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 291 | private RouteHandler routeHandler = null; |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 292 | LinkHandler linkHandler = null; |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 293 | private SegmentRoutingNeighbourDispatcher neighbourHandler = null; |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 294 | private DefaultL2TunnelHandler l2TunnelHandler = null; |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 295 | private TopologyHandler topologyHandler = null; |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 296 | private final InternalHostListener hostListener = new InternalHostListener(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 297 | private final InternalConfigListener cfgListener = new InternalConfigListener(this); |
| 298 | private final InternalMcastListener mcastListener = new InternalMcastListener(); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 299 | private final InternalRouteEventListener routeListener = new InternalRouteEventListener(); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 300 | private final InternalTopologyListener topologyListener = new InternalTopologyListener(); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 301 | private final InternalMastershipListener mastershipListener = new InternalMastershipListener(); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 302 | final InternalClusterListener clusterListener = new InternalClusterListener(); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 303 | //Completable future for network configuration process to buffer config events handling during activation |
| 304 | private CompletableFuture<Boolean> networkConfigCompletion = null; |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 305 | private List<Event> queuedEvents = new CopyOnWriteArrayList<>(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 306 | |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 307 | // Handles device, link, topology and network config events |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 308 | private ScheduledExecutorService mainEventExecutor; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 309 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 310 | // Handles host, route and mcast events respectively |
| 311 | private ScheduledExecutorService hostEventExecutor; |
| 312 | private ScheduledExecutorService routeEventExecutor; |
| 313 | private ScheduledExecutorService mcastEventExecutor; |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 314 | private ExecutorService packetExecutor; |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 315 | |
| 316 | Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<>(); |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 317 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 318 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 319 | * Used to keep track on MPLS group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 320 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 321 | private EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 322 | dsNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 323 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 324 | * Per device next objective ID store with (device id + vlanid) as key. |
| 325 | * Used to keep track on L2 flood group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 326 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 327 | private EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 328 | vlanNextObjStore = null; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 329 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 330 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
| 331 | * Used to keep track on L2 interface group and L3 unicast group information. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 332 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 333 | private EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 334 | portNextObjStore = null; |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 335 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 336 | /** |
| 337 | * Per port dummy VLAN ID store with (connect point + ip address) as key. |
| 338 | * Used to keep track on dummy VLAN ID allocation. |
| 339 | */ |
| 340 | private EventuallyConsistentMap<DummyVlanIdStoreKey, VlanId> |
| 341 | dummyVlanIdStore = null; |
| 342 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 343 | private EventuallyConsistentMap<String, Tunnel> tunnelStore = null; |
| 344 | private EventuallyConsistentMap<String, Policy> policyStore = null; |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 345 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 346 | private AtomicBoolean programmingScheduled = new AtomicBoolean(); |
| 347 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 348 | private final ConfigFactory<DeviceId, SegmentRoutingDeviceConfig> deviceConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 349 | new ConfigFactory<DeviceId, SegmentRoutingDeviceConfig>( |
| 350 | SubjectFactories.DEVICE_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 351 | SegmentRoutingDeviceConfig.class, "segmentrouting") { |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 352 | @Override |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 353 | public SegmentRoutingDeviceConfig createConfig() { |
| 354 | return new SegmentRoutingDeviceConfig(); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 355 | } |
| 356 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 357 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 358 | private final ConfigFactory<ApplicationId, SegmentRoutingAppConfig> appConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 359 | new ConfigFactory<ApplicationId, SegmentRoutingAppConfig>( |
| 360 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 361 | SegmentRoutingAppConfig.class, "segmentrouting") { |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 362 | @Override |
| 363 | public SegmentRoutingAppConfig createConfig() { |
| 364 | return new SegmentRoutingAppConfig(); |
| 365 | } |
| 366 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 367 | |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 368 | private final ConfigFactory<ApplicationId, XConnectConfig> xConnectConfigFactory = |
| 369 | new ConfigFactory<ApplicationId, XConnectConfig>( |
| 370 | SubjectFactories.APP_SUBJECT_FACTORY, |
| 371 | XConnectConfig.class, "xconnect") { |
| 372 | @Override |
| 373 | public XConnectConfig createConfig() { |
| 374 | return new XConnectConfig(); |
| 375 | } |
| 376 | }; |
Pier Ventre | 6b19e48 | 2016-11-07 16:21:04 -0800 | [diff] [blame] | 377 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 378 | private ConfigFactory<ApplicationId, McastConfig> mcastConfigFactory = |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 379 | new ConfigFactory<ApplicationId, McastConfig>( |
| 380 | SubjectFactories.APP_SUBJECT_FACTORY, |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 381 | McastConfig.class, "multicast") { |
| 382 | @Override |
| 383 | public McastConfig createConfig() { |
| 384 | return new McastConfig(); |
| 385 | } |
| 386 | }; |
| 387 | |
Charles Chan | 1963f4f | 2016-02-18 14:22:42 -0800 | [diff] [blame] | 388 | /** |
| 389 | * Segment Routing App ID. |
| 390 | */ |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 391 | public static final String APP_NAME = "org.onosproject.segmentrouting"; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 392 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 393 | /** |
| 394 | * Minumum and maximum value of dummy VLAN ID to be allocated. |
| 395 | */ |
| 396 | public static final int MIN_DUMMY_VLAN_ID = 2; |
| 397 | public static final int MAX_DUMMY_VLAN_ID = 4093; |
| 398 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 399 | Instant lastEdgePortEvent = Instant.EPOCH; |
| 400 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 401 | @Activate |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 402 | protected void activate(ComponentContext context) { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 403 | appId = coreService.registerApplication(APP_NAME); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 404 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 405 | mainEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-event-main", "%d", log)); |
| 406 | hostEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-event-host", "%d", log)); |
| 407 | routeEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-event-route", "%d", log)); |
| 408 | mcastEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("sr-event-mcast", "%d", log)); |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 409 | packetExecutor = Executors.newSingleThreadExecutor(groupedThreads("sr-packet", "%d", log)); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 410 | |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 411 | log.debug("Creating EC map nsnextobjectivestore"); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 412 | EventuallyConsistentMapBuilder<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 413 | nsNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 414 | dsNextObjStore = nsNextObjMapBuilder |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 415 | .withName("nsnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 416 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 417 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 418 | .build(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 419 | log.trace("Current size {}", dsNextObjStore.size()); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 420 | |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 421 | log.debug("Creating EC map vlannextobjectivestore"); |
| 422 | EventuallyConsistentMapBuilder<VlanNextObjectiveStoreKey, Integer> |
| 423 | vlanNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 424 | vlanNextObjStore = vlanNextObjMapBuilder |
| 425 | .withName("vlannextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 426 | .withSerializer(createSerializer()) |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 427 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 428 | .build(); |
| 429 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 430 | log.debug("Creating EC map subnetnextobjectivestore"); |
| 431 | EventuallyConsistentMapBuilder<PortNextObjectiveStoreKey, Integer> |
| 432 | portNextObjMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 433 | portNextObjStore = portNextObjMapBuilder |
| 434 | .withName("portnextobjectivestore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 435 | .withSerializer(createSerializer()) |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 436 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 437 | .build(); |
| 438 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 439 | EventuallyConsistentMapBuilder<DummyVlanIdStoreKey, VlanId> |
| 440 | dummyVlanIdMapBuilder = storageService.eventuallyConsistentMapBuilder(); |
| 441 | dummyVlanIdStore = dummyVlanIdMapBuilder |
| 442 | .withName("dummyvlanidstore") |
| 443 | .withSerializer(createSerializer()) |
| 444 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 445 | .build(); |
| 446 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 447 | EventuallyConsistentMapBuilder<String, Tunnel> tunnelMapBuilder = |
| 448 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 449 | tunnelStore = tunnelMapBuilder |
| 450 | .withName("tunnelstore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 451 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 452 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 453 | .build(); |
| 454 | |
| 455 | EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder = |
| 456 | storageService.eventuallyConsistentMapBuilder(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 457 | policyStore = policyMapBuilder |
| 458 | .withName("policystore") |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 459 | .withSerializer(createSerializer()) |
Madan Jampani | 675ae20 | 2015-06-24 19:05:56 -0700 | [diff] [blame] | 460 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 461 | .build(); |
| 462 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 463 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 464 | "purgeOnDisconnection", "true"); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 465 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 466 | "purgeOnDisconnection", "true"); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 467 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
| 468 | "requestInterceptsEnabled", "false"); |
Charles Chan | c1909e1 | 2017-08-08 15:13:37 -0700 | [diff] [blame] | 469 | compCfgService.preSetProperty("org.onosproject.net.neighbour.impl.NeighbourResolutionManager", |
Pier Luigi | bc976df | 2017-01-12 22:46:39 -0800 | [diff] [blame] | 470 | "requestInterceptsEnabled", "false"); |
Charles Chan | 9597f8d | 2017-07-24 15:56:10 -0700 | [diff] [blame] | 471 | compCfgService.preSetProperty("org.onosproject.dhcprelay.DhcpRelayManager", |
Pier Luigi | bc976df | 2017-01-12 22:46:39 -0800 | [diff] [blame] | 472 | "arpEnabled", "false"); |
Pier Luigi | 0ebeb31 | 2017-02-02 22:31:34 -0800 | [diff] [blame] | 473 | compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager", |
| 474 | "greedyLearningIpv6", "true"); |
Charles Chan | cf8ea47 | 2017-02-28 15:15:17 -0800 | [diff] [blame] | 475 | compCfgService.preSetProperty("org.onosproject.routing.cpr.ControlPlaneRedirectManager", |
| 476 | "forceUnprovision", "true"); |
Charles Chan | c7b73c7 | 2017-08-10 16:57:28 -0700 | [diff] [blame] | 477 | compCfgService.preSetProperty("org.onosproject.routeservice.store.RouteStoreImpl", |
Charles Chan | 4c95c0d | 2017-07-20 16:16:25 -0700 | [diff] [blame] | 478 | "distributed", "true"); |
Charles Chan | 804772f | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 479 | compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", |
| 480 | "multihomingEnabled", "true"); |
Charles Chan | 0c9c19f | 2017-11-29 19:54:20 -0800 | [diff] [blame] | 481 | compCfgService.preSetProperty("org.onosproject.provider.lldp.impl.LldpLinkProvider", |
| 482 | "staleLinkAge", "15000"); |
| 483 | compCfgService.preSetProperty("org.onosproject.net.host.impl.HostManager", |
| 484 | "allowDuplicateIps", "false"); |
Yi Tseng | a7da8d8 | 2018-08-19 03:09:54 +0800 | [diff] [blame] | 485 | // For P4 switches |
| 486 | compCfgService.preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Charles Chan | 0229851 | 2018-08-30 17:30:45 -0700 | [diff] [blame] | 487 | "fallbackFlowPollFrequency", "4"); |
Yi Tseng | a7da8d8 | 2018-08-19 03:09:54 +0800 | [diff] [blame] | 488 | compCfgService.preSetProperty("org.onosproject.net.group.impl.GroupManager", |
Charles Chan | 0229851 | 2018-08-30 17:30:45 -0700 | [diff] [blame] | 489 | "fallbackGroupPollFrequency", "3"); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 490 | compCfgService.registerProperties(getClass()); |
| 491 | modified(context); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 492 | |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 493 | processor = new InternalPacketProcessor(); |
| 494 | linkListener = new InternalLinkListener(); |
| 495 | deviceListener = new InternalDeviceListener(); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 496 | appCfgHandler = new AppConfigHandler(this); |
| 497 | xConnectHandler = new XConnectHandler(this); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 498 | mcastHandler = new McastHandler(this); |
| 499 | hostHandler = new HostHandler(this); |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 500 | linkHandler = new LinkHandler(this); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 501 | routeHandler = new RouteHandler(this); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 502 | neighbourHandler = new SegmentRoutingNeighbourDispatcher(this); |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 503 | l2TunnelHandler = new DefaultL2TunnelHandler(this); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 504 | topologyHandler = new TopologyHandler(this); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 505 | |
Charles Chan | d6d2533 | 2016-02-26 22:19:52 -0800 | [diff] [blame] | 506 | cfgService.addListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 507 | cfgService.registerConfigFactory(deviceConfigFactory); |
| 508 | cfgService.registerConfigFactory(appConfigFactory); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 509 | cfgService.registerConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 510 | cfgService.registerConfigFactory(mcastConfigFactory); |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 511 | log.info("Configuring network before adding listeners"); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 512 | |
Charles Chan | 6961f22 | 2018-01-04 14:26:07 -0800 | [diff] [blame] | 513 | cfgListener.configureNetwork(); |
| 514 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 515 | hostService.addListener(hostListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 516 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
| 517 | linkService.addListener(linkListener); |
| 518 | deviceService.addListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 519 | multicastRouteService.addListener(mcastListener); |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 520 | routeService.addListener(routeListener); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 521 | topologyService.addListener(topologyListener); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 522 | mastershipService.addListener(mastershipListener); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 523 | clusterService.addListener(clusterListener); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 524 | |
Charles Chan | c12c3d0 | 2018-03-09 15:53:44 -0800 | [diff] [blame] | 525 | linkHandler.init(); |
Andreas Pantelopoulos | 75eef06 | 2018-01-11 07:53:48 -0800 | [diff] [blame] | 526 | l2TunnelHandler.init(); |
| 527 | |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 528 | networkConfigCompletion.whenComplete((value, ex) -> { |
| 529 | //setting to null for easier fall through |
| 530 | networkConfigCompletion = null; |
| 531 | //process all queued events |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 532 | queuedEvents.forEach(event -> { |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 533 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 534 | }); |
| 535 | }); |
| 536 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 537 | log.info("Started"); |
| 538 | } |
| 539 | |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 540 | KryoNamespace.Builder createSerializer() { |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 541 | return new KryoNamespace.Builder() |
| 542 | .register(KryoNamespaces.API) |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 543 | .register(DestinationSetNextObjectiveStoreKey.class, |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 544 | VlanNextObjectiveStoreKey.class, |
| 545 | DestinationSet.class, |
Andreas Pantelopoulos | 92998c9 | 2018-05-29 13:11:14 -0700 | [diff] [blame] | 546 | DestinationSet.DestinationSetType.class, |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 547 | NextNeighbors.class, |
| 548 | Tunnel.class, |
| 549 | DefaultTunnel.class, |
| 550 | Policy.class, |
| 551 | TunnelPolicy.class, |
| 552 | Policy.Type.class, |
| 553 | PortNextObjectiveStoreKey.class, |
| 554 | XConnectStoreKey.class, |
| 555 | L2Tunnel.class, |
| 556 | L2TunnelPolicy.class, |
| 557 | DefaultL2Tunnel.class, |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 558 | DefaultL2TunnelPolicy.class, |
| 559 | DummyVlanIdStoreKey.class |
Jonathan Hart | 54541d1 | 2016-04-12 15:39:44 -0700 | [diff] [blame] | 560 | ); |
| 561 | } |
| 562 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 563 | @Deactivate |
| 564 | protected void deactivate() { |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 565 | mainEventExecutor.shutdown(); |
| 566 | hostEventExecutor.shutdown(); |
| 567 | routeEventExecutor.shutdown(); |
| 568 | mcastEventExecutor.shutdown(); |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 569 | packetExecutor.shutdown(); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 570 | |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 571 | mainEventExecutor = null; |
| 572 | hostEventExecutor = null; |
| 573 | routeEventExecutor = null; |
| 574 | mcastEventExecutor = null; |
| 575 | packetExecutor = null; |
| 576 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 577 | cfgService.removeListener(cfgListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 578 | cfgService.unregisterConfigFactory(deviceConfigFactory); |
| 579 | cfgService.unregisterConfigFactory(appConfigFactory); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 580 | cfgService.unregisterConfigFactory(xConnectConfigFactory); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 581 | cfgService.unregisterConfigFactory(mcastConfigFactory); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 582 | compCfgService.unregisterProperties(getClass(), false); |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 583 | |
Charles Chan | fd48c22 | 2017-06-19 00:43:31 -0700 | [diff] [blame] | 584 | hostService.removeListener(hostListener); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 585 | packetService.removeProcessor(processor); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 586 | linkService.removeListener(linkListener); |
| 587 | deviceService.removeListener(deviceListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 588 | multicastRouteService.removeListener(mcastListener); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 589 | routeService.removeListener(routeListener); |
Pier Luigi | d8a1516 | 2018-02-15 16:33:08 +0100 | [diff] [blame] | 590 | topologyService.removeListener(topologyListener); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 591 | mastershipService.removeListener(mastershipListener); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 592 | clusterService.removeListener(clusterListener); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 593 | |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 594 | neighbourResolutionService.unregisterNeighbourHandlers(appId); |
| 595 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 596 | processor = null; |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 597 | linkListener = null; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 598 | deviceListener = null; |
Charles Chan | 05bb170 | 2018-04-19 13:10:01 -0700 | [diff] [blame] | 599 | groupHandlerMap.forEach((k, v) -> v.shutdown()); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 600 | groupHandlerMap.clear(); |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 601 | defaultRoutingHandler.shutdown(); |
Charles Chan | 2b078ae | 2015-10-14 11:24:40 -0700 | [diff] [blame] | 602 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 603 | dsNextObjStore.destroy(); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 604 | vlanNextObjStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 605 | portNextObjStore.destroy(); |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 606 | dummyVlanIdStore.destroy(); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 607 | tunnelStore.destroy(); |
| 608 | policyStore.destroy(); |
Pier Luigi | 35dab3f | 2018-01-25 16:16:02 +0100 | [diff] [blame] | 609 | |
| 610 | mcastHandler.terminate(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 611 | log.info("Stopped"); |
| 612 | } |
| 613 | |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 614 | @Modified |
| 615 | private void modified(ComponentContext context) { |
| 616 | Dictionary<?, ?> properties = context.getProperties(); |
| 617 | if (properties == null) { |
| 618 | return; |
| 619 | } |
| 620 | |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 621 | String strActiveProbing = Tools.get(properties, "activeProbing"); |
| 622 | boolean expectActiveProbing = Boolean.parseBoolean(strActiveProbing); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 623 | if (expectActiveProbing != activeProbing) { |
| 624 | activeProbing = expectActiveProbing; |
| 625 | log.info("{} active probing", activeProbing ? "Enabling" : "Disabling"); |
| 626 | } |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 627 | |
| 628 | String strSingleHomedDown = Tools.get(properties, "singleHomedDown"); |
| 629 | boolean expectSingleHomedDown = Boolean.parseBoolean(strSingleHomedDown); |
| 630 | if (expectSingleHomedDown != singleHomedDown) { |
| 631 | singleHomedDown = expectSingleHomedDown; |
| 632 | log.info("{} downing of single homed hosts for lost uplinks", |
| 633 | singleHomedDown ? "Enabling" : "Disabling"); |
| 634 | if (singleHomedDown && linkHandler != null) { |
| 635 | hostService.getHosts().forEach(host -> host.locations() |
| 636 | .forEach(loc -> { |
| 637 | if (interfaceService.isConfigured(loc)) { |
| 638 | linkHandler.checkUplinksForHost(loc); |
| 639 | } |
| 640 | })); |
| 641 | } else { |
| 642 | log.warn("Disabling singleHomedDown does not re-enable already " |
| 643 | + "downed ports for single-homed hosts"); |
| 644 | } |
| 645 | } |
Andreas Pantelopoulos | 6464d86 | 2018-06-18 12:50:35 -0700 | [diff] [blame] | 646 | |
| 647 | String strRespondToUnknownHosts = Tools.get(properties, "respondToUnknownHosts"); |
| 648 | boolean expectRespondToUnknownHosts = Boolean.parseBoolean(strRespondToUnknownHosts); |
| 649 | if (expectRespondToUnknownHosts != respondToUnknownHosts) { |
| 650 | respondToUnknownHosts = expectRespondToUnknownHosts; |
| 651 | log.info("{} responding to ARPs/NDPs from unknown hosts", respondToUnknownHosts ? "Enabling" : "Disabling"); |
| 652 | } |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 653 | |
Charles Chan | fbca55e | 2018-07-24 16:40:35 -0700 | [diff] [blame] | 654 | String strRouteDoubleTaggedHosts = Tools.get(properties, "routeDoubleTaggedHosts"); |
| 655 | boolean expectRouteDoubleTaggedHosts = Boolean.parseBoolean(strRouteDoubleTaggedHosts); |
| 656 | if (expectRouteDoubleTaggedHosts != routeDoubleTaggedHosts) { |
| 657 | routeDoubleTaggedHosts = expectRouteDoubleTaggedHosts; |
| 658 | log.info("{} routing for double tagged hosts", routeDoubleTaggedHosts ? "Enabling" : "Disabling"); |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 659 | |
Charles Chan | fbca55e | 2018-07-24 16:40:35 -0700 | [diff] [blame] | 660 | if (routeDoubleTaggedHosts) { |
Charles Chan | 4eb73bb | 2018-07-19 14:55:31 -0700 | [diff] [blame] | 661 | hostHandler.populateAllDoubleTaggedHost(); |
| 662 | } else { |
| 663 | hostHandler.revokeAllDoubleTaggedHost(); |
| 664 | } |
| 665 | } |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 666 | |
| 667 | String strDefaultInternalVlan = Tools.get(properties, "defaultInternalVlan"); |
| 668 | int defIntVlan = Integer.parseInt(strDefaultInternalVlan); |
| 669 | if (defIntVlan != defaultInternalVlan) { |
| 670 | if (canUseVlanId(defIntVlan)) { |
| 671 | log.warn("Default internal vlan value changed from {} to {}.. " |
| 672 | + "re-programming filtering rules, but NOT any groups already " |
| 673 | + "created with the former value", defaultInternalVlan, defIntVlan); |
| 674 | VlanId oldDefIntVlan = VlanId.vlanId((short) defaultInternalVlan); |
| 675 | defaultInternalVlan = defIntVlan; |
| 676 | routingRulePopulator |
| 677 | .updateSpecialVlanFilteringRules(true, oldDefIntVlan, |
| 678 | VlanId.vlanId((short) defIntVlan)); |
| 679 | } else { |
| 680 | log.warn("Cannot change default internal vlan to unusable " |
| 681 | + "value {}", defIntVlan); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | String strPwTxpVlan = Tools.get(properties, "pwTransportVlan"); |
| 686 | int pwTxpVlan = Integer.parseInt(strPwTxpVlan); |
| 687 | if (pwTxpVlan != pwTransportVlan) { |
| 688 | if (canUseVlanId(pwTxpVlan)) { |
| 689 | log.warn("Pseudowire transport vlan value changed from {} to {}.. " |
| 690 | + "re-programming filtering rules, but NOT any groups already " |
| 691 | + "created with the former value", pwTransportVlan, |
| 692 | pwTxpVlan); |
| 693 | VlanId oldPwTxpVlan = VlanId.vlanId((short) pwTransportVlan); |
| 694 | pwTransportVlan = pwTxpVlan; |
| 695 | routingRulePopulator |
| 696 | .updateSpecialVlanFilteringRules(false, oldPwTxpVlan, |
| 697 | VlanId.vlanId((short) pwTxpVlan)); |
| 698 | } else { |
| 699 | log.warn("Cannot change pseudowire transport vlan to unusable " |
| 700 | + "value {}", pwTxpVlan); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Returns true if given vlan id is not being used in the system currently, |
| 708 | * either as one of the default system wide vlans or as one of the |
| 709 | * configured interface vlans. |
| 710 | * |
| 711 | * @param vlanId given vlan id |
| 712 | * @return true if vlan is not currently in use |
| 713 | */ |
| 714 | public boolean canUseVlanId(int vlanId) { |
| 715 | if (vlanId >= 4095 || vlanId <= 1) { |
| 716 | log.error("Vlan id {} value is not in valid range 2 <--> 4094", |
| 717 | vlanId); |
| 718 | return false; |
| 719 | } |
| 720 | |
| 721 | VlanId vid = VlanId.vlanId((short) vlanId); |
| 722 | if (getDefaultInternalVlan().equals(vid) || getPwTransportVlan().equals(vid)) { |
| 723 | log.warn("Vlan id {} value is already in use system-wide. " |
| 724 | + "DefaultInternalVlan:{} PwTransportVlan:{} ", vlanId, |
| 725 | getDefaultInternalVlan(), getPwTransportVlan()); |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | if (interfaceService.inUse(vid)) { |
| 730 | log.warn("Vlan id {} value is already in use on a configured " |
| 731 | + "interface in the system", vlanId); |
| 732 | return false; |
| 733 | } |
| 734 | return true; |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Returns the VlanId assigned internally by default to unconfigured ports. |
| 739 | * |
| 740 | * @return the default internal vlan id |
| 741 | */ |
| 742 | public VlanId getDefaultInternalVlan() { |
| 743 | return VlanId.vlanId((short) defaultInternalVlan); |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Returns the Vlan id used to transport pseudowire traffic across the |
| 748 | * network. |
| 749 | * |
| 750 | * @return the pseudowire transport vlan id |
| 751 | */ |
| 752 | public VlanId getPwTransportVlan() { |
| 753 | return VlanId.vlanId((short) pwTransportVlan); |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 754 | } |
| 755 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 756 | @Override |
| 757 | public List<Tunnel> getTunnels() { |
| 758 | return tunnelHandler.getTunnels(); |
| 759 | } |
| 760 | |
| 761 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 762 | public TunnelHandler.Result createTunnel(Tunnel tunnel) { |
| 763 | return tunnelHandler.createTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 767 | public TunnelHandler.Result removeTunnel(Tunnel tunnel) { |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 768 | for (Policy policy: policyHandler.getPolicies()) { |
| 769 | if (policy.type() == Policy.Type.TUNNEL_FLOW) { |
| 770 | TunnelPolicy tunnelPolicy = (TunnelPolicy) policy; |
| 771 | if (tunnelPolicy.tunnelId().equals(tunnel.id())) { |
| 772 | log.warn("Cannot remove the tunnel used by a policy"); |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 773 | return TunnelHandler.Result.TUNNEL_IN_USE; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | } |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 777 | return tunnelHandler.removeTunnel(tunnel); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 781 | public PolicyHandler.Result removePolicy(Policy policy) { |
| 782 | return policyHandler.removePolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | @Override |
sangho | bd812f8 | 2015-06-29 14:58:47 -0700 | [diff] [blame] | 786 | public PolicyHandler.Result createPolicy(Policy policy) { |
| 787 | return policyHandler.createPolicy(policy); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | @Override |
| 791 | public List<Policy> getPolicies() { |
| 792 | return policyHandler.getPolicies(); |
| 793 | } |
| 794 | |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 795 | @Override |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 796 | public Set<L2TunnelDescription> getL2TunnelDescriptions(boolean pending) { |
| 797 | return l2TunnelHandler.getL2Descriptions(pending); |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | @Override |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 801 | public List<L2Tunnel> getL2Tunnels() { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 802 | return l2TunnelHandler.getL2Tunnels(); |
| 803 | } |
| 804 | |
| 805 | @Override |
Andreas Pantelopoulos | 4c7de13 | 2018-02-22 12:32:42 -0800 | [diff] [blame] | 806 | public List<L2TunnelPolicy> getL2Policies() { |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 807 | return l2TunnelHandler.getL2Policies(); |
| 808 | } |
| 809 | |
Saurav Das | debcf88 | 2018-04-06 20:16:01 -0700 | [diff] [blame] | 810 | @Override |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 811 | @Deprecated |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 812 | public L2TunnelHandler.Result addPseudowiresBulk(List<DefaultL2TunnelDescription> bulkPseudowires) { |
| 813 | |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 814 | // get both added and pending pseudowires |
| 815 | List<L2TunnelDescription> pseudowires = new ArrayList<>(); |
| 816 | pseudowires.addAll(l2TunnelHandler.getL2Descriptions(false)); |
| 817 | pseudowires.addAll(l2TunnelHandler.getL2Descriptions(true)); |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 818 | pseudowires.addAll(bulkPseudowires); |
Andreas Pantelopoulos | d988c1a | 2018-03-15 16:56:09 -0700 | [diff] [blame] | 819 | |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 820 | Set<L2TunnelDescription> newPseudowires = new HashSet(bulkPseudowires); |
| 821 | |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 822 | L2TunnelHandler.Result retRes = L2TunnelHandler.Result.SUCCESS; |
| 823 | L2TunnelHandler.Result res; |
| 824 | for (DefaultL2TunnelDescription pw : bulkPseudowires) { |
| 825 | res = addPseudowire(pw); |
| 826 | if (res != L2TunnelHandler.Result.SUCCESS) { |
| 827 | log.error("Pseudowire with id {} can not be instantiated !", res); |
| 828 | retRes = res; |
| 829 | } |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 830 | } |
Andreas Pantelopoulos | 9685125 | 2018-03-20 13:58:49 -0700 | [diff] [blame] | 831 | |
| 832 | return retRes; |
Andreas Pantelopoulos | fc4bc2a | 2018-03-12 16:30:20 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | @Override |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 836 | public L2TunnelHandler.Result addPseudowire(L2TunnelDescription l2TunnelDescription) { |
Andreas Pantelopoulos | 87a0610 | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 837 | return l2TunnelHandler.deployPseudowire(l2TunnelDescription); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | @Override |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 841 | public L2TunnelHandler.Result removePseudowire(Integer pwId) { |
Andreas Pantelopoulos | 87a0610 | 2018-03-21 16:44:18 -0700 | [diff] [blame] | 842 | return l2TunnelHandler.tearDownPseudowire(pwId); |
Andreas Pantelopoulos | 5e7be3d | 2017-10-23 12:18:25 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | @Override |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 846 | public void rerouteNetwork() { |
| 847 | cfgListener.configureNetwork(); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 850 | @Override |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 851 | public Map<DeviceId, Set<IpPrefix>> getDeviceSubnetMap() { |
| 852 | Map<DeviceId, Set<IpPrefix>> deviceSubnetMap = Maps.newHashMap(); |
Jonathan Hart | 61e24e1 | 2017-11-30 18:23:42 -0800 | [diff] [blame] | 853 | deviceConfiguration.getRouters().forEach(device -> |
| 854 | deviceSubnetMap.put(device, deviceConfiguration.getSubnets(device))); |
Charles Chan | d7844e5 | 2016-10-20 17:02:44 -0700 | [diff] [blame] | 855 | return deviceSubnetMap; |
| 856 | } |
| 857 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 858 | |
| 859 | @Override |
| 860 | public ImmutableMap<DeviceId, EcmpShortestPathGraph> getCurrentEcmpSpg() { |
| 861 | if (defaultRoutingHandler != null) { |
| 862 | return defaultRoutingHandler.getCurrentEmcpSpgMap(); |
| 863 | } else { |
| 864 | return null; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 869 | public ImmutableMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> getDstNextObjStore() { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 870 | if (dsNextObjStore != null) { |
| 871 | return ImmutableMap.copyOf(dsNextObjStore.entrySet()); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 872 | } else { |
| 873 | return ImmutableMap.of(); |
| 874 | } |
| 875 | } |
| 876 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 877 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 878 | public ImmutableMap<VlanNextObjectiveStoreKey, Integer> getVlanNextObjStore() { |
| 879 | if (vlanNextObjStore != null) { |
| 880 | return ImmutableMap.copyOf(vlanNextObjStore.entrySet()); |
| 881 | } else { |
| 882 | return ImmutableMap.of(); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | @Override |
| 887 | public ImmutableMap<PortNextObjectiveStoreKey, Integer> getPortNextObjStore() { |
| 888 | if (portNextObjStore != null) { |
| 889 | return ImmutableMap.copyOf(portNextObjStore.entrySet()); |
| 890 | } else { |
| 891 | return ImmutableMap.of(); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | @Override |
| 896 | public ImmutableMap<String, NextObjective> getPwInitNext() { |
| 897 | if (l2TunnelHandler != null) { |
| 898 | return l2TunnelHandler.getInitNext(); |
| 899 | } else { |
| 900 | return ImmutableMap.of(); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | @Override |
| 905 | public ImmutableMap<String, NextObjective> getPwTermNext() { |
| 906 | if (l2TunnelHandler != null) { |
| 907 | return l2TunnelHandler.getTermNext(); |
| 908 | } else { |
| 909 | return ImmutableMap.of(); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | @Override |
| 914 | public void invalidateNextObj(int nextId) { |
| 915 | if (dsNextObjStore != null) { |
| 916 | dsNextObjStore.entrySet().forEach(e -> { |
| 917 | if (e.getValue().nextId() == nextId) { |
| 918 | dsNextObjStore.remove(e.getKey()); |
| 919 | } |
| 920 | }); |
| 921 | } |
| 922 | if (vlanNextObjStore != null) { |
| 923 | vlanNextObjStore.entrySet().forEach(e -> { |
| 924 | if (e.getValue() == nextId) { |
| 925 | vlanNextObjStore.remove(e.getKey()); |
| 926 | } |
| 927 | }); |
| 928 | } |
| 929 | if (portNextObjStore != null) { |
| 930 | portNextObjStore.entrySet().forEach(e -> { |
| 931 | if (e.getValue() == nextId) { |
| 932 | portNextObjStore.remove(e.getKey()); |
| 933 | } |
| 934 | }); |
| 935 | } |
| 936 | if (mcastHandler != null) { |
| 937 | mcastHandler.removeNextId(nextId); |
| 938 | } |
| 939 | if (l2TunnelHandler != null) { |
| 940 | l2TunnelHandler.removeNextId(nextId); |
| 941 | } |
| 942 | if (xconnectService != null) { |
| 943 | xconnectService.removeNextId(nextId); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | @Override |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 948 | public void verifyGroups(DeviceId id) { |
| 949 | DefaultGroupHandler gh = groupHandlerMap.get(id); |
| 950 | if (gh != null) { |
| 951 | gh.triggerBucketCorrector(); |
| 952 | } |
| 953 | } |
| 954 | |
Saurav Das | 6430f41 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 955 | @Override |
| 956 | public ImmutableMap<Link, Boolean> getSeenLinks() { |
| 957 | return linkHandler.getSeenLinks(); |
| 958 | } |
| 959 | |
| 960 | @Override |
| 961 | public ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState() { |
| 962 | return linkHandler.getDownedPorts(); |
| 963 | } |
| 964 | |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 965 | @Override |
| 966 | public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) { |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 967 | return mcastHandler.getNextIds(mcastIp); |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | @Override |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 971 | public Map<McastStoreKey, McastRole> getMcastRoles(IpAddress mcastIp) { |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 972 | return mcastHandler.getMcastRoles(mcastIp); |
| 973 | } |
| 974 | |
| 975 | @Override |
Pier | e99511d | 2018-04-19 16:47:06 +0200 | [diff] [blame] | 976 | public Map<McastRoleStoreKey, McastRole> getMcastRoles(IpAddress mcastIp, ConnectPoint sourcecp) { |
| 977 | return mcastHandler.getMcastRoles(mcastIp, sourcecp); |
| 978 | } |
| 979 | |
| 980 | @Override |
Pier Luigi | 0f9635b | 2018-01-15 18:06:43 +0100 | [diff] [blame] | 981 | public Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp) { |
| 982 | return mcastHandler.getMcastPaths(mcastIp); |
| 983 | } |
| 984 | |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 985 | @Override |
Pier | 71c5577 | 2018-04-17 17:25:22 +0200 | [diff] [blame] | 986 | public Multimap<ConnectPoint, List<ConnectPoint>> getMcastTrees(IpAddress mcastIp, |
| 987 | ConnectPoint sourcecp) { |
| 988 | return mcastHandler.getMcastTrees(mcastIp, sourcecp); |
| 989 | } |
| 990 | |
| 991 | @Override |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 992 | public Map<IpAddress, NodeId> getMcastLeaders(IpAddress mcastIp) { |
| 993 | return mcastHandler.getMcastLeaders(mcastIp); |
| 994 | } |
| 995 | |
Charles Chan | b13e070 | 2018-04-17 18:56:53 -0700 | [diff] [blame] | 996 | @Override |
| 997 | public Map<Set<DeviceId>, NodeId> getShouldProgram() { |
| 998 | return defaultRoutingHandler == null ? ImmutableMap.of() : |
| 999 | ImmutableMap.copyOf(defaultRoutingHandler.shouldProgram); |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public Map<DeviceId, Boolean> getShouldProgramCache() { |
| 1004 | return defaultRoutingHandler == null ? ImmutableMap.of() : |
| 1005 | ImmutableMap.copyOf(defaultRoutingHandler.shouldProgramCache); |
| 1006 | } |
| 1007 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1008 | @Override |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1009 | public boolean shouldProgram(DeviceId deviceId) { |
| 1010 | return defaultRoutingHandler.shouldProgram(deviceId); |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1014 | public ApplicationId appId() { |
| 1015 | return appId; |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Returns the device configuration. |
| 1020 | * |
| 1021 | * @return device configuration |
| 1022 | */ |
| 1023 | public DeviceConfiguration deviceConfiguration() { |
| 1024 | return deviceConfiguration; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1028 | * Per device next objective ID store with (device id + destination set) as key. |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1029 | * Used to keep track on MPLS group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1030 | * |
| 1031 | * @return next objective ID store |
| 1032 | */ |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1033 | public EventuallyConsistentMap<DestinationSetNextObjectiveStoreKey, NextNeighbors> |
| 1034 | dsNextObjStore() { |
| 1035 | return dsNextObjStore; |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1039 | * Per device next objective ID store with (device id + vlanid) as key. |
| 1040 | * Used to keep track on L2 flood group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1041 | * |
| 1042 | * @return vlan next object store |
| 1043 | */ |
| 1044 | public EventuallyConsistentMap<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore() { |
| 1045 | return vlanNextObjStore; |
| 1046 | } |
| 1047 | |
| 1048 | /** |
Charles Chan | 53de91f | 2017-08-22 15:07:34 -0700 | [diff] [blame] | 1049 | * Per device next objective ID store with (device id + port + treatment + meta) as key. |
| 1050 | * Used to keep track on L2 interface group and L3 unicast group information. |
Ray Milkey | b85de08 | 2017-04-05 09:42:04 -0700 | [diff] [blame] | 1051 | * |
| 1052 | * @return port next object store. |
| 1053 | */ |
| 1054 | public EventuallyConsistentMap<PortNextObjectiveStoreKey, Integer> portNextObjStore() { |
| 1055 | return portNextObjStore; |
| 1056 | } |
| 1057 | |
| 1058 | /** |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1059 | * Per port dummy VLAN ID store with (connect point + ip address) as key. |
| 1060 | * Used to keep track on dummy VLAN ID allocation. |
| 1061 | * |
| 1062 | * @return dummy vlan id store. |
| 1063 | */ |
| 1064 | public EventuallyConsistentMap<DummyVlanIdStoreKey, VlanId> dummyVlanIdStore() { |
| 1065 | return dummyVlanIdStore; |
| 1066 | } |
| 1067 | |
| 1068 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1069 | * Returns the MPLS-ECMP configuration which indicates whether ECMP on |
| 1070 | * labeled packets should be programmed or not. |
Pier Ventre | 7a78de2 | 2016-10-31 15:00:01 -0700 | [diff] [blame] | 1071 | * |
| 1072 | * @return MPLS-ECMP value |
| 1073 | */ |
| 1074 | public boolean getMplsEcmp() { |
| 1075 | SegmentRoutingAppConfig segmentRoutingAppConfig = cfgService |
| 1076 | .getConfig(this.appId, SegmentRoutingAppConfig.class); |
| 1077 | return segmentRoutingAppConfig != null && segmentRoutingAppConfig.mplsEcmp(); |
| 1078 | } |
| 1079 | |
| 1080 | /** |
sangho | 80f1f89 | 2015-05-19 11:57:42 -0700 | [diff] [blame] | 1081 | * Returns the tunnel object with the tunnel ID. |
| 1082 | * |
| 1083 | * @param tunnelId Tunnel ID |
| 1084 | * @return Tunnel reference |
| 1085 | */ |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1086 | public Tunnel getTunnel(String tunnelId) { |
| 1087 | return tunnelHandler.getTunnel(tunnelId); |
| 1088 | } |
| 1089 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1090 | @Override |
Pier Luigi | 69f774d | 2018-02-28 12:10:50 +0100 | [diff] [blame] | 1091 | public VlanId getInternalVlanId(ConnectPoint connectPoint) { |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1092 | VlanId untaggedVlanId = interfaceService.getUntaggedVlanId(connectPoint); |
| 1093 | VlanId nativeVlanId = interfaceService.getNativeVlanId(connectPoint); |
Charles Chan | d9265a3 | 2017-06-16 15:19:24 -0700 | [diff] [blame] | 1094 | return untaggedVlanId != null ? untaggedVlanId : nativeVlanId; |
| 1095 | } |
| 1096 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1097 | @Override |
| 1098 | public Optional<DeviceId> getPairDeviceId(DeviceId deviceId) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1099 | SegmentRoutingDeviceConfig deviceConfig = |
| 1100 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 1101 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairDeviceId); |
| 1102 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1103 | |
| 1104 | @Override |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1105 | public Optional<PortNumber> getPairLocalPort(DeviceId deviceId) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1106 | SegmentRoutingDeviceConfig deviceConfig = |
| 1107 | cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class); |
| 1108 | return Optional.ofNullable(deviceConfig).map(SegmentRoutingDeviceConfig::pairLocalPort); |
| 1109 | } |
| 1110 | |
| 1111 | /** |
Charles Chan | f0ae41e | 2017-08-23 13:55:39 -0700 | [diff] [blame] | 1112 | * Returns locations of given resolved route. |
| 1113 | * |
| 1114 | * @param resolvedRoute resolved route |
| 1115 | * @return locations of nexthop. Might be empty if next hop is not found |
| 1116 | */ |
| 1117 | Set<ConnectPoint> nextHopLocations(ResolvedRoute resolvedRoute) { |
| 1118 | HostId hostId = HostId.hostId(resolvedRoute.nextHopMac(), resolvedRoute.nextHopVlan()); |
| 1119 | return Optional.ofNullable(hostService.getHost(hostId)) |
| 1120 | .map(Host::locations).orElse(Sets.newHashSet()) |
| 1121 | .stream().map(l -> (ConnectPoint) l).collect(Collectors.toSet()); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1125 | * Returns vlan port map of given device. |
| 1126 | * |
| 1127 | * @param deviceId device id |
| 1128 | * @return vlan-port multimap |
| 1129 | */ |
| 1130 | public Multimap<VlanId, PortNumber> getVlanPortMap(DeviceId deviceId) { |
| 1131 | HashMultimap<VlanId, PortNumber> vlanPortMap = HashMultimap.create(); |
| 1132 | |
| 1133 | interfaceService.getInterfaces().stream() |
| 1134 | .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) |
| 1135 | .forEach(intf -> { |
| 1136 | vlanPortMap.put(intf.vlanUntagged(), intf.connectPoint().port()); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1137 | intf.vlanTagged().forEach(vlanTagged -> |
| 1138 | vlanPortMap.put(vlanTagged, intf.connectPoint().port()) |
| 1139 | ); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1140 | vlanPortMap.put(intf.vlanNative(), intf.connectPoint().port()); |
| 1141 | }); |
| 1142 | vlanPortMap.removeAll(VlanId.NONE); |
| 1143 | |
| 1144 | return vlanPortMap; |
| 1145 | } |
| 1146 | |
| 1147 | /** |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1148 | * Returns the next objective ID for the given vlan id. It is expected |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1149 | * that the next-objective has been pre-created from configuration. |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1150 | * |
| 1151 | * @param deviceId Device ID |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1152 | * @param vlanId VLAN ID |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1153 | * @return next objective ID or -1 if it was not found |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1154 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1155 | int getVlanNextObjectiveId(DeviceId deviceId, VlanId vlanId) { |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1156 | if (groupHandlerMap.get(deviceId) != null) { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1157 | log.trace("getVlanNextObjectiveId query in device {}", deviceId); |
| 1158 | return groupHandlerMap.get(deviceId).getVlanNextObjectiveId(vlanId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1159 | } else { |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1160 | log.warn("getVlanNextObjectiveId query - groupHandler for " |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1161 | + "device {} not found", deviceId); |
| 1162 | return -1; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Returns the next objective ID for the given portNumber, given the treatment. |
| 1168 | * There could be multiple different treatments to the same outport, which |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1169 | * would result in different objectives. If the next object does not exist, |
| 1170 | * and should be created, a new one is created and its id is returned. |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1171 | * |
| 1172 | * @param deviceId Device ID |
| 1173 | * @param portNum port number on device for which NextObjective is queried |
| 1174 | * @param treatment the actions to apply on the packets (should include outport) |
| 1175 | * @param meta metadata passed into the creation of a Next Objective if necessary |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1176 | * @param createIfMissing true if a next object should be created if not found |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1177 | * @return next objective ID or -1 if an error occurred during retrieval or creation |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1178 | */ |
| 1179 | public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum, |
| 1180 | TrafficTreatment treatment, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1181 | TrafficSelector meta, |
| 1182 | boolean createIfMissing) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1183 | DefaultGroupHandler ghdlr = groupHandlerMap.get(deviceId); |
| 1184 | if (ghdlr != null) { |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 1185 | return ghdlr.getPortNextObjectiveId(portNum, treatment, meta, createIfMissing); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1186 | } else { |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1187 | log.warn("getPortNextObjectiveId query - groupHandler for device {}" |
| 1188 | + " not found", deviceId); |
| 1189 | return -1; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1193 | /** |
| 1194 | * Returns the group handler object for the specified device id. |
| 1195 | * |
| 1196 | * @param devId the device identifier |
| 1197 | * @return the groupHandler object for the device id, or null if not found |
| 1198 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1199 | DefaultGroupHandler getGroupHandler(DeviceId devId) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1200 | return groupHandlerMap.get(devId); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1204 | * Returns the default routing handler object. |
| 1205 | * |
| 1206 | * @return the default routing handler object |
| 1207 | */ |
| 1208 | public DefaultRoutingHandler getRoutingHandler() { |
| 1209 | return defaultRoutingHandler; |
| 1210 | } |
| 1211 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1212 | /** |
| 1213 | * Returns new dummy VLAN ID. |
| 1214 | * Dummy VLAN ID should be unique in each connect point. |
| 1215 | * |
| 1216 | * @param cp connect point |
| 1217 | * @param ipAddress IP address |
| 1218 | * @return new dummy VLAN ID. Returns VlanId.NONE if no VLAN ID is available. |
| 1219 | */ |
| 1220 | public synchronized VlanId allocateDummyVlanId(ConnectPoint cp, IpAddress ipAddress) { |
| 1221 | Set<VlanId> usedVlanId = Sets.union(getVlanPortMap(cp.deviceId()).keySet(), |
| 1222 | dummyVlanIdStore.entrySet().stream().filter(entry -> |
| 1223 | (entry.getKey()).connectPoint().equals(cp)) |
| 1224 | .map(Map.Entry::getValue) |
| 1225 | .collect(Collectors.toSet())); |
| 1226 | |
| 1227 | VlanId dummyVlanId = IntStream.range(MIN_DUMMY_VLAN_ID, MAX_DUMMY_VLAN_ID).mapToObj( |
| 1228 | i -> VlanId.vlanId((short) (i & 0xFFFF)) |
| 1229 | ).filter(vlanId -> !usedVlanId.contains(vlanId)).findFirst().orElse(VlanId.NONE); |
| 1230 | |
| 1231 | if (!dummyVlanId.equals(VlanId.NONE)) { |
| 1232 | this.dummyVlanIdStore.put(new DummyVlanIdStoreKey(cp, ipAddress), dummyVlanId); |
| 1233 | log.debug("Dummy VLAN ID {} is allocated to {}, {}", dummyVlanId, cp, ipAddress); |
| 1234 | } else { |
| 1235 | log.error("Failed to allocate dummy VLAN ID for {}, {}", cp, ipAddress); |
| 1236 | } |
| 1237 | return dummyVlanId; |
| 1238 | } |
| 1239 | |
| 1240 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1241 | private class InternalPacketProcessor implements PacketProcessor { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1242 | @Override |
| 1243 | public void process(PacketContext context) { |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 1244 | packetExecutor.execute(() -> processPacketInternal(context)); |
| 1245 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1246 | |
Charles Chan | 77cdde4 | 2018-05-08 21:35:50 -0700 | [diff] [blame] | 1247 | private void processPacketInternal(PacketContext context) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1248 | if (context.isHandled()) { |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | InboundPacket pkt = context.inPacket(); |
| 1253 | Ethernet ethernet = pkt.parsed(); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 1254 | |
| 1255 | if (ethernet == null) { |
| 1256 | return; |
| 1257 | } |
| 1258 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1259 | log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(), |
| 1260 | ethernet); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1261 | if (ethernet.getEtherType() == TYPE_ARP) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1262 | log.warn("Received unexpected ARP packet on {}", |
| 1263 | context.inPacket().receivedFrom()); |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 1264 | log.trace("{}", ethernet); |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 1265 | return; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1266 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) { |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1267 | IPv4 ipv4Packet = (IPv4) ethernet.getPayload(); |
| 1268 | //ipHandler.addToPacketBuffer(ipv4Packet); |
| 1269 | if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) { |
| 1270 | icmpHandler.processIcmp(ethernet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1271 | } else { |
Charles Chan | d041ad8 | 2017-01-13 17:20:44 -0800 | [diff] [blame] | 1272 | // NOTE: We don't support IP learning at this moment so this |
| 1273 | // is not necessary. Also it causes duplication of DHCP packets. |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 1274 | // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1275 | } |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1276 | } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) { |
| 1277 | IPv6 ipv6Packet = (IPv6) ethernet.getPayload(); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1278 | //ipHandler.addToPacketBuffer(ipv6Packet); |
Pier Luigi | 37a3543 | 2017-02-01 13:50:04 -0800 | [diff] [blame] | 1279 | // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1280 | if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) { |
| 1281 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
| 1282 | if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST || |
| 1283 | icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) { |
| 1284 | icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom()); |
| 1285 | } else { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1286 | log.trace("Received ICMPv6 0x{} - not handled", |
Charles Chan | d3727b7 | 2017-03-13 13:10:30 -0700 | [diff] [blame] | 1287 | Integer.toHexString(icmp6Packet.getIcmpType() & 0xff)); |
Pier Ventre | b6b81d5 | 2016-12-02 08:16:05 -0800 | [diff] [blame] | 1288 | } |
| 1289 | } else { |
| 1290 | // NOTE: We don't support IP learning at this moment so this |
| 1291 | // is not necessary. Also it causes duplication of DHCPv6 packets. |
| 1292 | // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom()); |
| 1293 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1298 | private class InternalEventHandler implements Runnable { |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1299 | private Event event; |
| 1300 | |
| 1301 | InternalEventHandler(Event event) { |
| 1302 | this.event = event; |
| 1303 | } |
| 1304 | |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 1305 | @Override |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1306 | public void run() { |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1307 | try { |
| 1308 | // TODO We should also change SR routing and PW to listen to TopologyEvents |
| 1309 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 1310 | event.type() == LinkEvent.Type.LINK_UPDATED) { |
| 1311 | linkHandler.processLinkAdded((Link) event.subject()); |
| 1312 | } else if (event.type() == LinkEvent.Type.LINK_REMOVED) { |
| 1313 | linkHandler.processLinkRemoved((Link) event.subject()); |
| 1314 | } else if (event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 1315 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 1316 | event.type() == DeviceEvent.Type.DEVICE_UPDATED) { |
| 1317 | DeviceId deviceId = ((Device) event.subject()).id(); |
| 1318 | if (deviceService.isAvailable(deviceId)) { |
| 1319 | log.info("** DEVICE UP Processing device event {} " |
| 1320 | + "for available device {}", |
| 1321 | event.type(), ((Device) event.subject()).id()); |
| 1322 | processDeviceAdded((Device) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1323 | } else { |
Charles Chan | b8f3af5 | 2018-08-29 21:21:51 -0700 | [diff] [blame] | 1324 | if (event.type() == DeviceEvent.Type.DEVICE_ADDED) { |
| 1325 | // Note: For p4 devices, the device will be added but unavailable at the beginning. |
| 1326 | // The device will later on being marked as available once the pipeline is pushed |
| 1327 | // to the device. |
| 1328 | log.info("** DEVICE ADDED but unavailable. Ignore"); |
| 1329 | return; |
| 1330 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1331 | log.info(" ** DEVICE DOWN Processing device event {}" |
| 1332 | + " for unavailable device {}", |
| 1333 | event.type(), ((Device) event.subject()).id()); |
| 1334 | processDeviceRemoved((Device) event.subject()); |
Srikanth Vavilapalli | 64d96c1 | 2015-05-14 20:22:47 -0700 | [diff] [blame] | 1335 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1336 | } else if (event.type() == DeviceEvent.Type.PORT_ADDED) { |
| 1337 | // typically these calls come when device is added first time |
| 1338 | // so port filtering rules are handled at the device_added event. |
| 1339 | // port added calls represent all ports on the device, |
| 1340 | // enabled or not. |
| 1341 | log.trace("** PORT ADDED {}/{} -> {}", |
| 1342 | ((DeviceEvent) event).subject().id(), |
| 1343 | ((DeviceEvent) event).port().number(), |
| 1344 | event.type()); |
| 1345 | } else if (event.type() == DeviceEvent.Type.PORT_UPDATED) { |
| 1346 | // these calls happen for every subsequent event |
| 1347 | // ports enabled, disabled, switch goes away, comes back |
| 1348 | log.info("** PORT UPDATED {}/{} -> {}", |
| 1349 | event.subject(), |
| 1350 | ((DeviceEvent) event).port(), |
| 1351 | event.type()); |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1352 | processPortUpdatedInternal(((Device) event.subject()), |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1353 | ((DeviceEvent) event).port()); |
| 1354 | } else if (event.type() == TopologyEvent.Type.TOPOLOGY_CHANGED) { |
| 1355 | // Process topology event, needed for all modules relying on |
| 1356 | // topology service for path computation |
| 1357 | TopologyEvent topologyEvent = (TopologyEvent) event; |
| 1358 | log.info("Processing topology event {}, topology age {}, reasons {}", |
| 1359 | event.type(), topologyEvent.subject().time(), |
| 1360 | topologyEvent.reasons().size()); |
| 1361 | topologyHandler.processTopologyChange(topologyEvent.reasons()); |
| 1362 | } else if (event.type() == HostEvent.Type.HOST_ADDED) { |
| 1363 | hostHandler.processHostAddedEvent((HostEvent) event); |
| 1364 | } else if (event.type() == HostEvent.Type.HOST_MOVED) { |
| 1365 | hostHandler.processHostMovedEvent((HostEvent) event); |
| 1366 | routeHandler.processHostMovedEvent((HostEvent) event); |
| 1367 | } else if (event.type() == HostEvent.Type.HOST_REMOVED) { |
| 1368 | hostHandler.processHostRemovedEvent((HostEvent) event); |
| 1369 | } else if (event.type() == HostEvent.Type.HOST_UPDATED) { |
| 1370 | hostHandler.processHostUpdatedEvent((HostEvent) event); |
| 1371 | } else if (event.type() == RouteEvent.Type.ROUTE_ADDED) { |
| 1372 | routeHandler.processRouteAdded((RouteEvent) event); |
| 1373 | } else if (event.type() == RouteEvent.Type.ROUTE_UPDATED) { |
| 1374 | routeHandler.processRouteUpdated((RouteEvent) event); |
| 1375 | } else if (event.type() == RouteEvent.Type.ROUTE_REMOVED) { |
| 1376 | routeHandler.processRouteRemoved((RouteEvent) event); |
| 1377 | } else if (event.type() == RouteEvent.Type.ALTERNATIVE_ROUTES_CHANGED) { |
| 1378 | routeHandler.processAlternativeRoutesChanged((RouteEvent) event); |
| 1379 | } else if (event.type() == McastEvent.Type.SOURCES_ADDED || |
| 1380 | event.type() == McastEvent.Type.SOURCES_REMOVED || |
| 1381 | event.type() == McastEvent.Type.SINKS_ADDED || |
| 1382 | event.type() == McastEvent.Type.SINKS_REMOVED || |
| 1383 | event.type() == McastEvent.Type.ROUTE_ADDED || |
| 1384 | event.type() == McastEvent.Type.ROUTE_REMOVED) { |
| 1385 | mcastHandler.processMcastEvent((McastEvent) event); |
| 1386 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) { |
| 1387 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1388 | Class configClass = netcfgEvent.configClass(); |
| 1389 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1390 | appCfgHandler.processAppConfigAdded(netcfgEvent); |
| 1391 | log.info("App config event .. configuring network"); |
| 1392 | cfgListener.configureNetwork(); |
| 1393 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1394 | log.info("Segment Routing Device Config added for {}", event.subject()); |
| 1395 | cfgListener.configureNetwork(); |
| 1396 | } else if (configClass.equals(XConnectConfig.class)) { |
| 1397 | xConnectHandler.processXConnectConfigAdded(netcfgEvent); |
| 1398 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1399 | log.info("Interface Config added for {}", event.subject()); |
| 1400 | cfgListener.configureNetwork(); |
| 1401 | } else { |
| 1402 | log.error("Unhandled config class: {}", configClass); |
| 1403 | } |
| 1404 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) { |
| 1405 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1406 | Class configClass = netcfgEvent.configClass(); |
| 1407 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1408 | appCfgHandler.processAppConfigUpdated(netcfgEvent); |
| 1409 | log.info("App config event .. configuring network"); |
| 1410 | cfgListener.configureNetwork(); |
| 1411 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1412 | log.info("Segment Routing Device Config updated for {}", event.subject()); |
| 1413 | createOrUpdateDeviceConfiguration(); |
| 1414 | } else if (configClass.equals(XConnectConfig.class)) { |
| 1415 | xConnectHandler.processXConnectConfigUpdated(netcfgEvent); |
| 1416 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1417 | log.info("Interface Config updated for {}", event.subject()); |
| 1418 | createOrUpdateDeviceConfiguration(); |
| 1419 | updateInterface((InterfaceConfig) netcfgEvent.config().get(), |
| 1420 | (InterfaceConfig) netcfgEvent.prevConfig().get()); |
| 1421 | } else { |
| 1422 | log.error("Unhandled config class: {}", configClass); |
| 1423 | } |
| 1424 | } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) { |
| 1425 | NetworkConfigEvent netcfgEvent = (NetworkConfigEvent) event; |
| 1426 | Class configClass = netcfgEvent.configClass(); |
| 1427 | if (configClass.equals(SegmentRoutingAppConfig.class)) { |
| 1428 | appCfgHandler.processAppConfigRemoved(netcfgEvent); |
| 1429 | log.info("App config event .. configuring network"); |
| 1430 | cfgListener.configureNetwork(); |
| 1431 | } else if (configClass.equals(SegmentRoutingDeviceConfig.class)) { |
| 1432 | // TODO Handle sr device config removal |
| 1433 | log.info("SegmentRoutingDeviceConfig removal is not handled in current implementation"); |
| 1434 | } else if (configClass.equals(XConnectConfig.class)) { |
| 1435 | xConnectHandler.processXConnectConfigRemoved(netcfgEvent); |
| 1436 | } else if (configClass.equals(InterfaceConfig.class)) { |
| 1437 | // TODO Handle interface removal |
| 1438 | log.info("InterfaceConfig removal is not handled in current implementation"); |
| 1439 | } else { |
| 1440 | log.error("Unhandled config class: {}", configClass); |
| 1441 | } |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1442 | } else if (event.type() == MastershipEvent.Type.MASTER_CHANGED) { |
| 1443 | MastershipEvent me = (MastershipEvent) event; |
| 1444 | DeviceId deviceId = me.subject(); |
| 1445 | Optional<DeviceId> pairDeviceId = getPairDeviceId(deviceId); |
| 1446 | log.info(" ** MASTERSHIP CHANGED Invalidating shouldProgram cache" |
| 1447 | + " for {}/pair={} due to change", deviceId, pairDeviceId); |
| 1448 | defaultRoutingHandler.invalidateShouldProgramCache(deviceId); |
| 1449 | pairDeviceId.ifPresent(defaultRoutingHandler::invalidateShouldProgramCache); |
| 1450 | defaultRoutingHandler.checkFullRerouteForMasterChange(deviceId, me); |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1451 | } else { |
| 1452 | log.warn("Unhandled event type: {}", event.type()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1453 | } |
Charles Chan | 5200392 | 2018-04-05 16:31:15 -0700 | [diff] [blame] | 1454 | } catch (Exception e) { |
| 1455 | log.error("SegmentRouting event handler thread thrown an exception: {}", |
| 1456 | e.getMessage(), e); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1457 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 1461 | void processDeviceAdded(Device device) { |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1462 | log.info("** DEVICE ADDED with ID {}", device.id()); |
Charles Chan | 9bd6aea | 2017-06-27 18:48:32 -0700 | [diff] [blame] | 1463 | |
| 1464 | // NOTE: Punt ARP/NDP even when the device is not configured. |
| 1465 | // Host learning without network config is required for CORD config generator. |
| 1466 | routingRulePopulator.populateIpPunts(device.id()); |
| 1467 | routingRulePopulator.populateArpNdpPunts(device.id()); |
| 1468 | |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1469 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1470 | log.warn("Device configuration unavailable. Device {} will be " |
| 1471 | + "processed after configuration.", device.id()); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1472 | return; |
| 1473 | } |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1474 | processDeviceAddedInternal(device.id()); |
| 1475 | } |
| 1476 | |
| 1477 | private void processDeviceAddedInternal(DeviceId deviceId) { |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1478 | // Irrespective of whether the local is a MASTER or not for this device, |
| 1479 | // we need to create a SR-group-handler instance. This is because in a |
| 1480 | // multi-instance setup, any instance can initiate forwarding/next-objectives |
| 1481 | // for any switch (even if this instance is a SLAVE or not even connected |
| 1482 | // to the switch). To handle this, a default-group-handler instance is necessary |
| 1483 | // per switch. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1484 | log.debug("Current groupHandlerMap devs: {}", groupHandlerMap.keySet()); |
| 1485 | if (groupHandlerMap.get(deviceId) == null) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1486 | DefaultGroupHandler groupHandler; |
| 1487 | try { |
| 1488 | groupHandler = DefaultGroupHandler. |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1489 | createGroupHandler(deviceId, |
| 1490 | appId, |
| 1491 | deviceConfiguration, |
| 1492 | linkService, |
| 1493 | flowObjectiveService, |
| 1494 | this); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1495 | } catch (DeviceConfigNotFoundException e) { |
| 1496 | log.warn(e.getMessage() + " Aborting processDeviceAdded."); |
| 1497 | return; |
| 1498 | } |
Saurav Das | 2b6a00f | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 1499 | log.debug("updating groupHandlerMap with new grpHdlr for device: {}", |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1500 | deviceId); |
| 1501 | groupHandlerMap.put(deviceId, groupHandler); |
Saurav Das | 8ec0ec4 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1502 | } |
Saurav Das | b149be1 | 2016-06-07 10:08:06 -0700 | [diff] [blame] | 1503 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1504 | if (mastershipService.isLocalMaster(deviceId)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1505 | defaultRoutingHandler.populatePortAddressingRules(deviceId); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1506 | xConnectHandler.init(deviceId); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1507 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1508 | groupHandler.createGroupsFromVlanConfig(); |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1509 | routingRulePopulator.populateSubnetBroadcastRule(deviceId); |
Charles Chan | 7727767 | 2015-10-20 16:24:19 -0700 | [diff] [blame] | 1510 | } |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1511 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1512 | appCfgHandler.init(deviceId); |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 1513 | hostEventExecutor.execute(() -> hostHandler.init(deviceId)); |
| 1514 | routeEventExecutor.execute(() -> routeHandler.init(deviceId)); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1517 | private void processDeviceRemoved(Device device) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1518 | dsNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1519 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 1520 | .forEach(entry -> dsNextObjStore.remove(entry.getKey())); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1521 | vlanNextObjStore.entrySet().stream() |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1522 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1523 | .forEach(entry -> vlanNextObjStore.remove(entry.getKey())); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1524 | portNextObjStore.entrySet().stream() |
| 1525 | .filter(entry -> entry.getKey().deviceId().equals(device.id())) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1526 | .forEach(entry -> portNextObjStore.remove(entry.getKey())); |
Saurav Das | e6c448a | 2018-01-18 12:07:33 -0800 | [diff] [blame] | 1527 | linkHandler.processDeviceRemoved(device); |
Charles Chan | 17d75d8 | 2017-06-15 00:44:51 -0700 | [diff] [blame] | 1528 | |
Saurav Das | fbe7457 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 1529 | DefaultGroupHandler gh = groupHandlerMap.remove(device.id()); |
| 1530 | if (gh != null) { |
| 1531 | gh.shutdown(); |
| 1532 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1533 | // Note that a switch going down is associated with all of its links |
| 1534 | // going down as well, but it is treated as a single switch down event |
Saurav Das | debcf88 | 2018-04-06 20:16:01 -0700 | [diff] [blame] | 1535 | // while the link-downs are ignored. We cannot rely on the ordering of |
| 1536 | // events - i.e we cannot expect all link-downs to come before the |
| 1537 | // switch down - so we purge all seen-links for the switch before |
| 1538 | // handling route-path changes for the switch-down |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1539 | defaultRoutingHandler |
Saurav Das | dc7f275 | 2018-03-18 21:28:15 -0700 | [diff] [blame] | 1540 | .populateRoutingRulesForLinkStatusChange(null, null, device.id(), true); |
Saurav Das | 6430f41 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1541 | defaultRoutingHandler.purgeEcmpGraph(device.id()); |
Charles Chan | 82f1997 | 2016-05-17 13:13:55 -0700 | [diff] [blame] | 1542 | xConnectHandler.removeDevice(device.id()); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1543 | |
| 1544 | // Cleanup all internal groupHandler stores for this device. Should be |
| 1545 | // done after all rerouting or rehashing has been completed |
| 1546 | groupHandlerMap.entrySet() |
| 1547 | .forEach(entry -> entry.getValue().cleanUpForNeighborDown(device.id())); |
Saurav Das | c3604f1 | 2016-03-23 11:22:49 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 1550 | /** |
| 1551 | * Purge the destinationSet nextObjective store of entries with this device |
| 1552 | * as key. Erases app-level knowledge of hashed groups in this device. |
| 1553 | * |
| 1554 | * @param devId the device identifier |
| 1555 | */ |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1556 | void purgeHashedNextObjectiveStore(DeviceId devId) { |
Saurav Das | 4936839 | 2018-04-23 18:42:12 -0700 | [diff] [blame] | 1557 | log.debug("Purging hashed next-obj store for dev:{}", devId); |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1558 | dsNextObjStore.entrySet().stream() |
| 1559 | .filter(entry -> entry.getKey().deviceId().equals(devId)) |
| 1560 | .forEach(entry -> dsNextObjStore.remove(entry.getKey())); |
| 1561 | } |
| 1562 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1563 | private void processPortUpdatedInternal(Device device, Port port) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1564 | if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { |
| 1565 | log.warn("Device configuration uploading. Not handling port event for" |
| 1566 | + "dev: {} port: {}", device.id(), port.number()); |
| 1567 | return; |
| 1568 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1569 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1570 | if (interfaceService.isConfigured(new ConnectPoint(device.id(), port.number()))) { |
| 1571 | lastEdgePortEvent = Instant.now(); |
| 1572 | } |
| 1573 | |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1574 | if (!mastershipService.isLocalMaster(device.id())) { |
| 1575 | log.debug("Not master for dev:{} .. not handling port updated event" |
| 1576 | + "for port {}", device.id(), port.number()); |
| 1577 | return; |
| 1578 | } |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1579 | processPortUpdated(device.id(), port); |
| 1580 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1581 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1582 | /** |
| 1583 | * Adds or remove filtering rules for the given switchport. If switchport is |
| 1584 | * an edge facing port, additionally handles host probing and broadcast |
| 1585 | * rules. Must be called by local master of device. |
| 1586 | * |
| 1587 | * @param deviceId the device identifier |
| 1588 | * @param port the port to update |
| 1589 | */ |
| 1590 | void processPortUpdated(DeviceId deviceId, Port port) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1591 | // first we handle filtering rules associated with the port |
| 1592 | if (port.isEnabled()) { |
| 1593 | log.info("Switchport {}/{} enabled..programming filters", |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1594 | deviceId, port.number()); |
| 1595 | routingRulePopulator.processSinglePortFilters(deviceId, port.number(), true); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1596 | } else { |
| 1597 | log.info("Switchport {}/{} disabled..removing filters", |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1598 | deviceId, port.number()); |
| 1599 | routingRulePopulator.processSinglePortFilters(deviceId, port.number(), false); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1600 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1601 | |
| 1602 | // portUpdated calls are for ports that have gone down or up. For switch |
| 1603 | // to switch ports, link-events should take care of any re-routing or |
| 1604 | // group editing necessary for port up/down. Here we only process edge ports |
| 1605 | // that are already configured. |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1606 | ConnectPoint cp = new ConnectPoint(deviceId, port.number()); |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1607 | VlanId untaggedVlan = interfaceService.getUntaggedVlanId(cp); |
| 1608 | VlanId nativeVlan = interfaceService.getNativeVlanId(cp); |
| 1609 | Set<VlanId> taggedVlans = interfaceService.getTaggedVlanId(cp); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1610 | |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1611 | if (untaggedVlan == null && nativeVlan == null && taggedVlans.isEmpty()) { |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1612 | log.debug("Not handling port updated event for non-edge port (unconfigured) " |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1613 | + "dev/port: {}/{}", deviceId, port.number()); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1614 | return; |
| 1615 | } |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1616 | if (untaggedVlan != null) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1617 | processEdgePort(deviceId, port, untaggedVlan, true); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1618 | } |
| 1619 | if (nativeVlan != null) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1620 | processEdgePort(deviceId, port, nativeVlan, true); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1621 | } |
| 1622 | if (!taggedVlans.isEmpty()) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1623 | taggedVlans.forEach(tag -> processEdgePort(deviceId, port, tag, false)); |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1624 | } |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1627 | private void processEdgePort(DeviceId deviceId, Port port, VlanId vlanId, |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1628 | boolean popVlan) { |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1629 | boolean portUp = port.isEnabled(); |
| 1630 | if (portUp) { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1631 | log.info("Device:EdgePort {}:{} is enabled in vlan: {}", deviceId, |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1632 | port.number(), vlanId); |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 1633 | hostEventExecutor.execute(() -> hostHandler.processPortUp(new ConnectPoint(deviceId, port.number()))); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1634 | } else { |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1635 | log.info("Device:EdgePort {}:{} is disabled in vlan: {}", deviceId, |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 1636 | port.number(), vlanId); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1639 | DefaultGroupHandler groupHandler = groupHandlerMap.get(deviceId); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1640 | if (groupHandler != null) { |
Saurav Das | 3fb2827 | 2017-03-04 16:08:47 -0800 | [diff] [blame] | 1641 | groupHandler.processEdgePort(port.number(), vlanId, popVlan, portUp); |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1642 | } else { |
| 1643 | log.warn("Group handler not found for dev:{}. Not handling edge port" |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1644 | + " {} event for port:{}", deviceId, |
Saurav Das | f0f592d | 2016-11-18 15:21:57 -0800 | [diff] [blame] | 1645 | (portUp) ? "UP" : "DOWN", port.number()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1646 | } |
| 1647 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1648 | |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1649 | private void createOrUpdateDeviceConfiguration() { |
| 1650 | if (deviceConfiguration == null) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1651 | log.info("Creating new DeviceConfiguration"); |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1652 | deviceConfiguration = new DeviceConfiguration(this); |
| 1653 | } else { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1654 | log.info("Updating DeviceConfiguration"); |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1655 | deviceConfiguration.updateConfig(); |
| 1656 | } |
| 1657 | } |
| 1658 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1659 | private void createOrUpdateDefaultRoutingHandler() { |
| 1660 | if (defaultRoutingHandler == null) { |
| 1661 | log.info("Creating new DefaultRoutingHandler"); |
| 1662 | defaultRoutingHandler = new DefaultRoutingHandler(this); |
| 1663 | } else { |
| 1664 | log.info("Updating DefaultRoutingHandler"); |
| 1665 | defaultRoutingHandler.update(this); |
| 1666 | } |
| 1667 | } |
| 1668 | |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1669 | /** |
| 1670 | * Registers the given connect point with the NRS, this is necessary |
| 1671 | * to receive the NDP and ARP packets from the NRS. |
| 1672 | * |
| 1673 | * @param portToRegister connect point to register |
| 1674 | */ |
| 1675 | public void registerConnectPoint(ConnectPoint portToRegister) { |
Charles Chan | 2e71ef3 | 2017-02-23 15:44:08 -0800 | [diff] [blame] | 1676 | neighbourResolutionService.registerNeighbourHandler( |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 1677 | portToRegister, |
| 1678 | neighbourHandler, |
| 1679 | appId |
| 1680 | ); |
| 1681 | } |
| 1682 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1683 | private class InternalConfigListener implements NetworkConfigListener { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1684 | private static final long PROGRAM_DELAY = 2; |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1685 | SegmentRoutingManager srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1686 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1687 | /** |
| 1688 | * Constructs the internal network config listener. |
| 1689 | * |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1690 | * @param srManager segment routing manager |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1691 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1692 | InternalConfigListener(SegmentRoutingManager srManager) { |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1693 | this.srManager = srManager; |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 1696 | /** |
| 1697 | * Reads network config and initializes related data structure accordingly. |
| 1698 | */ |
Charles Chan | 873661e | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 1699 | void configureNetwork() { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1700 | log.info("Configuring network ..."); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1701 | |
| 1702 | // Setting handling of network configuration events completable future |
| 1703 | // The completable future is needed because of the async behaviour of the configureNetwork, |
| 1704 | // listener registration and event arrival |
| 1705 | // Enables us to buffer the events and execute them when the configure network is done. |
| 1706 | networkConfigCompletion = new CompletableFuture<>(); |
| 1707 | |
| 1708 | // add a small delay to absorb multiple network config added notifications |
| 1709 | if (!programmingScheduled.get()) { |
| 1710 | log.info("Buffering config calls for {} secs", PROGRAM_DELAY); |
| 1711 | programmingScheduled.set(true); |
| 1712 | mainEventExecutor.schedule(new ConfigChange(), PROGRAM_DELAY, TimeUnit.SECONDS); |
| 1713 | } |
| 1714 | |
Charles Chan | 8ca5a12 | 2017-10-20 16:06:55 -0700 | [diff] [blame] | 1715 | createOrUpdateDeviceConfiguration(); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1716 | |
Charles Chan | 46fdfaf | 2016-11-09 20:51:44 -0800 | [diff] [blame] | 1717 | arpHandler = new ArpHandler(srManager); |
| 1718 | icmpHandler = new IcmpHandler(srManager); |
| 1719 | ipHandler = new IpHandler(srManager); |
| 1720 | routingRulePopulator = new RoutingRulePopulator(srManager); |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1721 | createOrUpdateDefaultRoutingHandler(); |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1722 | |
| 1723 | tunnelHandler = new TunnelHandler(linkService, deviceConfiguration, |
| 1724 | groupHandlerMap, tunnelStore); |
| 1725 | policyHandler = new PolicyHandler(appId, deviceConfiguration, |
| 1726 | flowObjectiveService, |
| 1727 | tunnelHandler, policyStore); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1728 | networkConfigCompletion.complete(true); |
| 1729 | |
Charles Chan | 7277950 | 2016-04-23 17:36:10 -0700 | [diff] [blame] | 1730 | mcastHandler.init(); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1731 | |
Charles Chan | e7c6102 | 2015-10-07 14:21:45 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1734 | @Override |
| 1735 | public void event(NetworkConfigEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1736 | if (mainEventExecutor == null) { |
| 1737 | return; |
| 1738 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1739 | checkState(appCfgHandler != null, "NetworkConfigEventHandler is not initialized"); |
| 1740 | checkState(xConnectHandler != null, "XConnectHandler is not initialized"); |
| 1741 | switch (event.type()) { |
| 1742 | case CONFIG_ADDED: |
| 1743 | case CONFIG_UPDATED: |
| 1744 | case CONFIG_REMOVED: |
| 1745 | log.trace("Schedule Network Config event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1746 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1747 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1748 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1749 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1750 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1751 | break; |
| 1752 | default: |
| 1753 | break; |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1756 | |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1757 | @Override |
| 1758 | public boolean isRelevant(NetworkConfigEvent event) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1759 | if (event.type() == CONFIG_REGISTERED || |
| 1760 | event.type() == CONFIG_UNREGISTERED) { |
| 1761 | log.debug("Ignore event {} due to type mismatch", event); |
| 1762 | return false; |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1763 | } |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1764 | |
| 1765 | if (!event.configClass().equals(SegmentRoutingDeviceConfig.class) && |
| 1766 | !event.configClass().equals(SegmentRoutingAppConfig.class) && |
| 1767 | !event.configClass().equals(InterfaceConfig.class) && |
Andreas Pantelopoulos | cdbb22c | 2018-02-23 14:18:00 -0800 | [diff] [blame] | 1768 | !event.configClass().equals(XConnectConfig.class)) { |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1769 | log.debug("Ignore event {} due to class mismatch", event); |
| 1770 | return false; |
| 1771 | } |
| 1772 | |
| 1773 | return true; |
Charles Chan | c4a68c3 | 2018-01-03 16:26:32 -0800 | [diff] [blame] | 1774 | } |
| 1775 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1776 | private final class ConfigChange implements Runnable { |
| 1777 | @Override |
| 1778 | public void run() { |
| 1779 | programmingScheduled.set(false); |
Saurav Das | e321cff | 2018-02-09 17:26:45 -0800 | [diff] [blame] | 1780 | log.info("Reacting to config changes after buffer delay"); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1781 | for (Device device : deviceService.getDevices()) { |
| 1782 | processDeviceAdded(device); |
| 1783 | } |
| 1784 | defaultRoutingHandler.startPopulationProcess(); |
| 1785 | } |
| 1786 | } |
Charles Chan | 72f556a | 2015-10-05 17:50:33 -0700 | [diff] [blame] | 1787 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1788 | |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1789 | private class InternalLinkListener implements LinkListener { |
| 1790 | @Override |
| 1791 | public void event(LinkEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1792 | if (mainEventExecutor == null) { |
| 1793 | return; |
| 1794 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1795 | if (event.type() == LinkEvent.Type.LINK_ADDED || |
| 1796 | event.type() == LinkEvent.Type.LINK_UPDATED || |
| 1797 | event.type() == LinkEvent.Type.LINK_REMOVED) { |
| 1798 | log.trace("Schedule Link event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1799 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1800 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1801 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1802 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1803 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | private class InternalDeviceListener implements DeviceListener { |
| 1809 | @Override |
| 1810 | public void event(DeviceEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1811 | if (mainEventExecutor == null) { |
| 1812 | return; |
| 1813 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1814 | switch (event.type()) { |
| 1815 | case DEVICE_ADDED: |
| 1816 | case PORT_UPDATED: |
| 1817 | case PORT_ADDED: |
| 1818 | case DEVICE_UPDATED: |
| 1819 | case DEVICE_AVAILABILITY_CHANGED: |
| 1820 | log.trace("Schedule Device event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1821 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1822 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1823 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1824 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1825 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1826 | break; |
| 1827 | default: |
| 1828 | } |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | private class InternalTopologyListener implements TopologyListener { |
| 1833 | @Override |
| 1834 | public void event(TopologyEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1835 | if (mainEventExecutor == null) { |
| 1836 | return; |
| 1837 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1838 | switch (event.type()) { |
| 1839 | case TOPOLOGY_CHANGED: |
| 1840 | log.trace("Schedule Topology event {}", event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1841 | if (networkConfigCompletion == null || networkConfigCompletion.isDone()) { |
| 1842 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1843 | } else { |
Charles Chan | 39b7552 | 2018-04-21 00:44:29 -0700 | [diff] [blame] | 1844 | queuedEvents.add(event); |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1845 | } |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1846 | break; |
| 1847 | default: |
| 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1852 | private class InternalHostListener implements HostListener { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1853 | @Override |
| 1854 | public void event(HostEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1855 | if (hostEventExecutor == null) { |
| 1856 | return; |
| 1857 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1858 | switch (event.type()) { |
| 1859 | case HOST_ADDED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1860 | case HOST_MOVED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1861 | case HOST_REMOVED: |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1862 | case HOST_UPDATED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1863 | log.trace("Schedule Host event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1864 | hostEventExecutor.execute(new InternalEventHandler(event)); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1865 | break; |
| 1866 | default: |
| 1867 | log.warn("Unsupported host event type: {}", event.type()); |
| 1868 | break; |
| 1869 | } |
| 1870 | } |
| 1871 | } |
| 1872 | |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1873 | private class InternalMcastListener implements McastListener { |
| 1874 | @Override |
| 1875 | public void event(McastEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1876 | if (mcastEventExecutor == null) { |
| 1877 | return; |
| 1878 | } |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1879 | switch (event.type()) { |
Pier | 1f87aca | 2018-03-14 16:47:32 -0700 | [diff] [blame] | 1880 | case SOURCES_ADDED: |
| 1881 | case SOURCES_REMOVED: |
| 1882 | case SINKS_ADDED: |
| 1883 | case SINKS_REMOVED: |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1884 | case ROUTE_REMOVED: |
Pier | db27b8d | 2018-04-17 16:29:56 +0200 | [diff] [blame] | 1885 | case ROUTE_ADDED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1886 | log.trace("Schedule Mcast event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1887 | mcastEventExecutor.execute(new InternalEventHandler(event)); |
Pier Luigi | 6786b92 | 2018-02-02 16:19:11 +0100 | [diff] [blame] | 1888 | break; |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1889 | default: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1890 | log.warn("Unsupported mcast event type: {}", event.type()); |
Charles Chan | c91c878 | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1891 | break; |
| 1892 | } |
| 1893 | } |
| 1894 | } |
Charles Chan | 41f5ec0 | 2016-06-13 18:54:31 -0700 | [diff] [blame] | 1895 | |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1896 | private class InternalRouteEventListener implements RouteListener { |
| 1897 | @Override |
| 1898 | public void event(RouteEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1899 | if (routeEventExecutor == null) { |
| 1900 | return; |
| 1901 | } |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1902 | switch (event.type()) { |
| 1903 | case ROUTE_ADDED: |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1904 | case ROUTE_UPDATED: |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1905 | case ROUTE_REMOVED: |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 1906 | case ALTERNATIVE_ROUTES_CHANGED: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1907 | log.trace("Schedule Route event {}", event); |
Charles Chan | dbbbb8a | 2018-04-07 11:35:08 -0700 | [diff] [blame] | 1908 | routeEventExecutor.execute(new InternalEventHandler(event)); |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 1909 | break; |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1910 | default: |
Charles Chan | 3f4aca6 | 2018-03-21 16:57:47 -0700 | [diff] [blame] | 1911 | log.warn("Unsupported route event type: {}", event.type()); |
Charles Chan | debfea3 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 1912 | break; |
| 1913 | } |
| 1914 | } |
| 1915 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1916 | |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1917 | private class InternalMastershipListener implements MastershipListener { |
| 1918 | @Override |
| 1919 | public void event(MastershipEvent event) { |
Ray Milkey | aee4d3e | 2018-05-11 09:59:19 -0700 | [diff] [blame] | 1920 | if (mainEventExecutor == null) { |
| 1921 | return; |
| 1922 | } |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1923 | switch (event.type()) { |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1924 | case MASTER_CHANGED: |
| 1925 | log.debug("Mastership event: {}/{}", event.subject(), |
| 1926 | event.roleInfo()); |
| 1927 | mainEventExecutor.execute(new InternalEventHandler(event)); |
| 1928 | break; |
| 1929 | case BACKUPS_CHANGED: |
| 1930 | case SUSPENDED: |
| 1931 | default: |
| 1932 | log.debug("Mastership event type {} not handled", event.type()); |
| 1933 | break; |
Charles Chan | fbcb881 | 2018-04-18 18:41:05 -0700 | [diff] [blame] | 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
Saurav Das | 00e553b | 2018-04-21 17:19:48 -0700 | [diff] [blame] | 1938 | class InternalClusterListener implements ClusterEventListener { |
| 1939 | private Instant lastClusterEvent = Instant.EPOCH; |
| 1940 | |
| 1941 | long timeSinceLastClusterEvent() { |
| 1942 | return Instant.now().toEpochMilli() - lastClusterEvent.toEpochMilli(); |
| 1943 | } |
| 1944 | |
| 1945 | @Override |
| 1946 | public void event(ClusterEvent event) { |
| 1947 | switch (event.type()) { |
| 1948 | case INSTANCE_ACTIVATED: |
| 1949 | case INSTANCE_ADDED: |
| 1950 | case INSTANCE_READY: |
| 1951 | log.debug("Cluster event {} ignored", event.type()); |
| 1952 | break; |
| 1953 | case INSTANCE_DEACTIVATED: |
| 1954 | case INSTANCE_REMOVED: |
| 1955 | log.info("** Cluster event {}", event.type()); |
| 1956 | lastClusterEvent = Instant.now(); |
| 1957 | break; |
| 1958 | default: |
| 1959 | break; |
| 1960 | } |
| 1961 | |
| 1962 | } |
| 1963 | |
| 1964 | } |
| 1965 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1966 | private void updateInterface(InterfaceConfig conf, InterfaceConfig prevConf) { |
| 1967 | try { |
| 1968 | Set<Interface> intfs = conf.getInterfaces(); |
| 1969 | Set<Interface> prevIntfs = prevConf.getInterfaces(); |
| 1970 | |
| 1971 | // Now we only handle one interface config at each port. |
| 1972 | if (intfs.size() != 1 || prevIntfs.size() != 1) { |
| 1973 | log.warn("Interface update aborted - one at a time is allowed, " + |
| 1974 | "but {} / {}(prev) received.", intfs.size(), prevIntfs.size()); |
| 1975 | return; |
| 1976 | } |
| 1977 | |
Andrea Campanella | 060cad8 | 2018-04-17 12:09:34 +0200 | [diff] [blame] | 1978 | //The system is in an incoherent state, abort |
| 1979 | if (defaultRoutingHandler == null) { |
| 1980 | log.warn("Interface update aborted, defaultRoutingHandler is null"); |
| 1981 | return; |
| 1982 | } |
| 1983 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1984 | Interface intf = intfs.stream().findFirst().get(); |
| 1985 | Interface prevIntf = prevIntfs.stream().findFirst().get(); |
| 1986 | |
| 1987 | DeviceId deviceId = intf.connectPoint().deviceId(); |
| 1988 | PortNumber portNum = intf.connectPoint().port(); |
| 1989 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1990 | removeSubnetConfig(prevIntf.connectPoint(), |
| 1991 | Sets.difference(new HashSet<>(prevIntf.ipAddressesList()), |
| 1992 | new HashSet<>(intf.ipAddressesList()))); |
| 1993 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 1994 | if (!prevIntf.vlanNative().equals(VlanId.NONE) |
| 1995 | && !prevIntf.vlanNative().equals(intf.vlanUntagged()) |
| 1996 | && !prevIntf.vlanNative().equals(intf.vlanNative())) { |
| 1997 | if (intf.vlanTagged().contains(prevIntf.vlanNative())) { |
| 1998 | // Update filtering objective and L2IG group bucket |
| 1999 | updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanNative(), false); |
| 2000 | } else { |
| 2001 | // RemoveVlanNative |
| 2002 | updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanNative(), true, false); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | if (!prevIntf.vlanUntagged().equals(VlanId.NONE) |
| 2007 | && !prevIntf.vlanUntagged().equals(intf.vlanUntagged()) |
| 2008 | && !prevIntf.vlanUntagged().equals(intf.vlanNative())) { |
| 2009 | if (intf.vlanTagged().contains(prevIntf.vlanUntagged())) { |
| 2010 | // Update filtering objective and L2IG group bucket |
| 2011 | updatePortVlanTreatment(deviceId, portNum, prevIntf.vlanUntagged(), false); |
| 2012 | } else { |
| 2013 | // RemoveVlanUntagged |
| 2014 | updateVlanConfigInternal(deviceId, portNum, prevIntf.vlanUntagged(), true, false); |
| 2015 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | if (!prevIntf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) { |
| 2019 | // RemoveVlanTagged |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2020 | Sets.difference(prevIntf.vlanTagged(), intf.vlanTagged()).stream() |
| 2021 | .filter(i -> !intf.vlanUntagged().equals(i)) |
| 2022 | .filter(i -> !intf.vlanNative().equals(i)) |
| 2023 | .forEach(vlanId -> updateVlanConfigInternal( |
| 2024 | deviceId, portNum, vlanId, false, false)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2027 | if (!intf.vlanNative().equals(VlanId.NONE) |
| 2028 | && !prevIntf.vlanNative().equals(intf.vlanNative()) |
| 2029 | && !prevIntf.vlanUntagged().equals(intf.vlanNative())) { |
| 2030 | if (prevIntf.vlanTagged().contains(intf.vlanNative())) { |
| 2031 | // Update filtering objective and L2IG group bucket |
| 2032 | updatePortVlanTreatment(deviceId, portNum, intf.vlanNative(), true); |
| 2033 | } else { |
| 2034 | // AddVlanNative |
| 2035 | updateVlanConfigInternal(deviceId, portNum, intf.vlanNative(), true, true); |
| 2036 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | if (!intf.vlanTagged().isEmpty() && !intf.vlanTagged().equals(prevIntf.vlanTagged())) { |
| 2040 | // AddVlanTagged |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2041 | Sets.difference(intf.vlanTagged(), prevIntf.vlanTagged()).stream() |
| 2042 | .filter(i -> !prevIntf.vlanUntagged().equals(i)) |
| 2043 | .filter(i -> !prevIntf.vlanNative().equals(i)) |
| 2044 | .forEach(vlanId -> updateVlanConfigInternal( |
| 2045 | deviceId, portNum, vlanId, false, true) |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2046 | ); |
| 2047 | } |
| 2048 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2049 | if (!intf.vlanUntagged().equals(VlanId.NONE) |
| 2050 | && !prevIntf.vlanUntagged().equals(intf.vlanUntagged()) |
| 2051 | && !prevIntf.vlanNative().equals(intf.vlanUntagged())) { |
| 2052 | if (prevIntf.vlanTagged().contains(intf.vlanUntagged())) { |
| 2053 | // Update filtering objective and L2IG group bucket |
| 2054 | updatePortVlanTreatment(deviceId, portNum, intf.vlanUntagged(), true); |
| 2055 | } else { |
| 2056 | // AddVlanUntagged |
| 2057 | updateVlanConfigInternal(deviceId, portNum, intf.vlanUntagged(), true, true); |
| 2058 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2059 | } |
| 2060 | addSubnetConfig(prevIntf.connectPoint(), |
| 2061 | Sets.difference(new HashSet<>(intf.ipAddressesList()), |
| 2062 | new HashSet<>(prevIntf.ipAddressesList()))); |
| 2063 | } catch (ConfigException e) { |
| 2064 | log.error("Error in configuration"); |
| 2065 | } |
| 2066 | } |
| 2067 | |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2068 | private void updatePortVlanTreatment(DeviceId deviceId, PortNumber portNum, |
| 2069 | VlanId vlanId, boolean pushVlan) { |
| 2070 | DefaultGroupHandler grpHandler = getGroupHandler(deviceId); |
| 2071 | if (grpHandler == null) { |
| 2072 | log.warn("Failed to retrieve group handler for device {}", deviceId); |
| 2073 | return; |
| 2074 | } |
| 2075 | |
| 2076 | // Update filtering objective for a single port |
| 2077 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, !pushVlan, vlanId, false); |
| 2078 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, true); |
| 2079 | |
| 2080 | if (getVlanNextObjectiveId(deviceId, vlanId) != -1) { |
| 2081 | // Update L2IG bucket of the port |
| 2082 | grpHandler.updateL2InterfaceGroupBucket(portNum, vlanId, pushVlan); |
| 2083 | } else { |
| 2084 | log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum); |
| 2085 | } |
| 2086 | } |
| 2087 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2088 | private void updateVlanConfigInternal(DeviceId deviceId, PortNumber portNum, |
| 2089 | VlanId vlanId, boolean pushVlan, boolean install) { |
| 2090 | DefaultGroupHandler grpHandler = getGroupHandler(deviceId); |
| 2091 | if (grpHandler == null) { |
| 2092 | log.warn("Failed to retrieve group handler for device {}", deviceId); |
| 2093 | return; |
| 2094 | } |
| 2095 | |
| 2096 | // Update filtering objective for a single port |
| 2097 | routingRulePopulator.updateSinglePortFilters(deviceId, portNum, pushVlan, vlanId, install); |
| 2098 | |
| 2099 | // Update filtering objective for multicast ingress port |
| 2100 | mcastHandler.updateFilterToDevice(deviceId, portNum, vlanId, install); |
| 2101 | |
| 2102 | int nextId = getVlanNextObjectiveId(deviceId, vlanId); |
| 2103 | |
| 2104 | if (nextId != -1 && !install) { |
| 2105 | // Update next objective for a single port as an output port |
| 2106 | // Remove a single port from L2FG |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2107 | grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2108 | // Remove L2 Bridging rule and L3 Unicast rule to the host |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2109 | hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, |
| 2110 | vlanId, pushVlan, install)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2111 | // Remove broadcast forwarding rule and corresponding L2FG for VLAN |
| 2112 | // only if there is no port configured on that VLAN ID |
| 2113 | if (!getVlanPortMap(deviceId).containsKey(vlanId)) { |
| 2114 | // Remove broadcast forwarding rule for the VLAN |
| 2115 | routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install); |
| 2116 | // Remove L2FG for VLAN |
| 2117 | grpHandler.removeBcastGroupFromVlan(deviceId, portNum, vlanId, pushVlan); |
| 2118 | } else { |
| 2119 | // Remove L2IG of the port |
| 2120 | grpHandler.removePortNextObjective(deviceId, portNum, vlanId, pushVlan); |
| 2121 | } |
| 2122 | } else if (install) { |
| 2123 | if (nextId != -1) { |
| 2124 | // Add a single port to L2FG |
Jonghwan Hyun | a4ce0aa | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 2125 | grpHandler.updateGroupFromVlanConfiguration(vlanId, portNum, nextId, install); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2126 | } else { |
| 2127 | // Create L2FG for VLAN |
| 2128 | grpHandler.createBcastGroupFromVlan(vlanId, Collections.singleton(portNum)); |
| 2129 | routingRulePopulator.updateSubnetBroadcastRule(deviceId, vlanId, install); |
| 2130 | } |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2131 | hostEventExecutor.execute(() -> hostHandler.processIntfVlanUpdatedEvent(deviceId, portNum, |
| 2132 | vlanId, pushVlan, install)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2133 | } else { |
| 2134 | log.warn("Failed to retrieve next objective for vlan {} in device {}:{}", vlanId, deviceId, portNum); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | private void removeSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) { |
| 2139 | Set<IpPrefix> ipPrefixSet = ipAddressSet.stream(). |
| 2140 | map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet()); |
| 2141 | |
| 2142 | Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream() |
| 2143 | .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId())) |
| 2144 | .filter(intf -> !intf.connectPoint().equals(cp)) |
| 2145 | .flatMap(intf -> intf.ipAddressesList().stream()) |
| 2146 | .collect(Collectors.toSet()); |
| 2147 | // 1. Partial subnet population |
| 2148 | // Remove routing rules for removed subnet from previous configuration, |
| 2149 | // which does not also exist in other interfaces in the same device |
| 2150 | Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream() |
| 2151 | .map(InterfaceIpAddress::subnetAddress) |
| 2152 | .collect(Collectors.toSet()); |
| 2153 | |
| 2154 | defaultRoutingHandler.revokeSubnet( |
| 2155 | ipPrefixSet.stream() |
| 2156 | .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)) |
| 2157 | .collect(Collectors.toSet())); |
| 2158 | |
| 2159 | // 2. Interface IP punts |
| 2160 | // Remove IP punts for old Intf address |
| 2161 | Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream() |
| 2162 | .map(InterfaceIpAddress::ipAddress) |
| 2163 | .collect(Collectors.toSet()); |
| 2164 | ipAddressSet.stream() |
| 2165 | .map(InterfaceIpAddress::ipAddress) |
| 2166 | .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress)) |
| 2167 | .forEach(interfaceIpAddress -> |
| 2168 | routingRulePopulator.revokeSingleIpPunts( |
| 2169 | cp.deviceId(), interfaceIpAddress)); |
| 2170 | |
| 2171 | // 3. Host unicast routing rule |
| 2172 | // Remove unicast routing rule |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2173 | hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) { |
| 2177 | Set<IpPrefix> ipPrefixSet = ipAddressSet.stream(). |
| 2178 | map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet()); |
| 2179 | |
| 2180 | Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream() |
| 2181 | .filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId())) |
| 2182 | .filter(intf -> !intf.connectPoint().equals(cp)) |
| 2183 | .flatMap(intf -> intf.ipAddressesList().stream()) |
| 2184 | .collect(Collectors.toSet()); |
| 2185 | // 1. Partial subnet population |
| 2186 | // Add routing rules for newly added subnet, which does not also exist in |
| 2187 | // other interfaces in the same device |
| 2188 | Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream() |
| 2189 | .map(InterfaceIpAddress::subnetAddress) |
| 2190 | .collect(Collectors.toSet()); |
| 2191 | |
| 2192 | defaultRoutingHandler.populateSubnet( |
| 2193 | Collections.singleton(cp), |
| 2194 | ipPrefixSet.stream() |
| 2195 | .filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)) |
| 2196 | .collect(Collectors.toSet())); |
| 2197 | |
| 2198 | // 2. Interface IP punts |
| 2199 | // Add IP punts for new Intf address |
| 2200 | Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream() |
| 2201 | .map(InterfaceIpAddress::ipAddress) |
| 2202 | .collect(Collectors.toSet()); |
| 2203 | ipAddressSet.stream() |
| 2204 | .map(InterfaceIpAddress::ipAddress) |
| 2205 | .filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress)) |
| 2206 | .forEach(interfaceIpAddress -> |
| 2207 | routingRulePopulator.populateSingleIpPunts( |
| 2208 | cp.deviceId(), interfaceIpAddress)); |
| 2209 | |
| 2210 | // 3. Host unicast routing rule |
| 2211 | // Add unicast routing rule |
Charles Chan | 074fae6 | 2018-04-29 18:11:37 -0700 | [diff] [blame] | 2212 | hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true)); |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 2213 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 2214 | } |