Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.xconnect.impl; |
| 17 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 21 | import com.google.common.collect.Lists; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 22 | import com.google.common.collect.Sets; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 23 | import org.onlab.packet.Ethernet; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onlab.util.KryoNamespace; |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 27 | import org.onosproject.cluster.ClusterService; |
| 28 | import org.onosproject.cluster.LeadershipService; |
| 29 | import org.onosproject.cluster.NodeId; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 30 | import org.onosproject.codec.CodecService; |
| 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 33 | import org.onosproject.l2lb.api.L2LbService; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 34 | import org.onosproject.mastership.MastershipService; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DeviceId; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 37 | import org.onosproject.net.Host; |
| 38 | import org.onosproject.net.HostLocation; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 39 | import org.onosproject.net.PortNumber; |
| 40 | import org.onosproject.net.config.NetworkConfigService; |
| 41 | import org.onosproject.net.device.DeviceEvent; |
| 42 | import org.onosproject.net.device.DeviceListener; |
| 43 | import org.onosproject.net.device.DeviceService; |
| 44 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 45 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 46 | import org.onosproject.net.flow.TrafficSelector; |
| 47 | import org.onosproject.net.flow.TrafficTreatment; |
| 48 | import org.onosproject.net.flow.criteria.Criteria; |
| 49 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 50 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 51 | import org.onosproject.net.flowobjective.DefaultNextObjective; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 52 | import org.onosproject.net.flowobjective.DefaultNextTreatment; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 53 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
| 54 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 55 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 56 | import org.onosproject.net.flowobjective.ForwardingObjective; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 57 | import org.onosproject.net.flowobjective.IdNextTreatment; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 58 | import org.onosproject.net.flowobjective.NextObjective; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 59 | import org.onosproject.net.flowobjective.NextTreatment; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 60 | import org.onosproject.net.flowobjective.Objective; |
| 61 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 62 | import org.onosproject.net.flowobjective.ObjectiveError; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 63 | import org.onosproject.net.host.HostEvent; |
| 64 | import org.onosproject.net.host.HostListener; |
| 65 | import org.onosproject.net.host.HostService; |
| 66 | import org.onosproject.net.intf.InterfaceService; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 67 | import org.onosproject.segmentrouting.SegmentRoutingService; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 68 | import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 69 | import org.onosproject.segmentrouting.xconnect.api.XconnectCodec; |
| 70 | import org.onosproject.segmentrouting.xconnect.api.XconnectDesc; |
| 71 | import org.onosproject.segmentrouting.xconnect.api.XconnectKey; |
| 72 | import org.onosproject.segmentrouting.xconnect.api.XconnectService; |
| 73 | import org.onosproject.store.serializers.KryoNamespaces; |
| 74 | import org.onosproject.store.service.ConsistentMap; |
| 75 | import org.onosproject.store.service.MapEvent; |
| 76 | import org.onosproject.store.service.MapEventListener; |
| 77 | import org.onosproject.store.service.Serializer; |
| 78 | import org.onosproject.store.service.StorageService; |
| 79 | import org.onosproject.store.service.Versioned; |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 80 | import org.osgi.service.component.annotations.Activate; |
| 81 | import org.osgi.service.component.annotations.Component; |
| 82 | import org.osgi.service.component.annotations.Deactivate; |
| 83 | import org.osgi.service.component.annotations.Reference; |
| 84 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 85 | import org.slf4j.Logger; |
| 86 | import org.slf4j.LoggerFactory; |
| 87 | |
| 88 | import java.io.Serializable; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 89 | import java.util.Collections; |
| 90 | import java.util.List; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 91 | import java.util.Optional; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 92 | import java.util.Set; |
| 93 | import java.util.concurrent.CompletableFuture; |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 94 | import java.util.concurrent.ExecutorService; |
| 95 | import java.util.concurrent.Executors; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 96 | import java.util.function.BiConsumer; |
| 97 | import java.util.function.Consumer; |
| 98 | import java.util.stream.Collectors; |
| 99 | |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 100 | import static org.onlab.util.Tools.groupedThreads; |
| 101 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 102 | @Component(immediate = true, service = XconnectService.class) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 103 | public class XconnectManager implements XconnectService { |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 105 | private CoreService coreService; |
| 106 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 108 | private CodecService codecService; |
| 109 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 111 | private StorageService storageService; |
| 112 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 114 | public NetworkConfigService netCfgService; |
| 115 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 117 | public DeviceService deviceService; |
| 118 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 120 | public FlowObjectiveService flowObjectiveService; |
| 121 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 123 | private LeadershipService leadershipService; |
| 124 | |
| 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 126 | private ClusterService clusterService; |
| 127 | |
| 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 129 | public MastershipService mastershipService; |
| 130 | |
Ray Milkey | 2bd24a9 | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 131 | @Reference(cardinality = ReferenceCardinality.OPTIONAL) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 132 | public SegmentRoutingService srService; |
| 133 | |
Ray Milkey | 3cad4db | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 135 | public InterfaceService interfaceService; |
| 136 | |
Ray Milkey | 3cad4db | 2018-10-04 15:13:33 -0700 | [diff] [blame] | 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 138 | HostService hostService; |
| 139 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 141 | L2LbService l2LbService; |
| 142 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 143 | private static final String APP_NAME = "org.onosproject.xconnect"; |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 144 | private static final String ERROR_NOT_LEADER = "Not leader controller"; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 145 | private static final String ERROR_NEXT_OBJ_BUILDER = "Unable to construct next objective builder"; |
| 146 | private static final String ERROR_NEXT_ID = "Unable to get next id"; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 147 | |
| 148 | private static Logger log = LoggerFactory.getLogger(XconnectManager.class); |
| 149 | |
| 150 | private ApplicationId appId; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 151 | private ConsistentMap<XconnectKey, Set<String>> xconnectStore; |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 152 | private ConsistentMap<XconnectKey, Integer> xconnectNextObjStore; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 153 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 154 | private ConsistentMap<VlanNextObjectiveStoreKey, Integer> xconnectMulticastNextStore; |
| 155 | private ConsistentMap<VlanNextObjectiveStoreKey, List<PortNumber>> xconnectMulticastPortsStore; |
| 156 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 157 | private final MapEventListener<XconnectKey, Set<String>> xconnectListener = new XconnectMapListener(); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 158 | private ExecutorService xConnectExecutor; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 159 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 160 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 161 | private ExecutorService deviceEventExecutor; |
| 162 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 163 | private final HostListener hostListener = new InternalHostListener(); |
| 164 | private ExecutorService hostEventExecutor; |
| 165 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 166 | @Activate |
| 167 | void activate() { |
| 168 | appId = coreService.registerApplication(APP_NAME); |
| 169 | codecService.registerCodec(XconnectDesc.class, new XconnectCodec()); |
| 170 | |
| 171 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 172 | .register(KryoNamespaces.API) |
Charles Chan | fbaad96 | 2018-07-23 12:53:16 -0700 | [diff] [blame] | 173 | .register(XconnectManager.class) |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 174 | .register(XconnectKey.class) |
| 175 | .register(VlanNextObjectiveStoreKey.class); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 176 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 177 | xconnectStore = storageService.<XconnectKey, Set<String>>consistentMapBuilder() |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 178 | .withName("onos-sr-xconnect") |
| 179 | .withRelaxedReadConsistency() |
| 180 | .withSerializer(Serializer.using(serializer.build())) |
| 181 | .build(); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 182 | xConnectExecutor = Executors.newSingleThreadScheduledExecutor( |
| 183 | groupedThreads("sr-xconnect-event", "%d", log)); |
| 184 | xconnectStore.addListener(xconnectListener, xConnectExecutor); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 185 | |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 186 | xconnectNextObjStore = storageService.<XconnectKey, Integer>consistentMapBuilder() |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 187 | .withName("onos-sr-xconnect-next") |
| 188 | .withRelaxedReadConsistency() |
| 189 | .withSerializer(Serializer.using(serializer.build())) |
| 190 | .build(); |
| 191 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 192 | xconnectMulticastNextStore = storageService.<VlanNextObjectiveStoreKey, Integer>consistentMapBuilder() |
| 193 | .withName("onos-sr-xconnect-l2multicast-next") |
| 194 | .withSerializer(Serializer.using(serializer.build())) |
| 195 | .build(); |
| 196 | xconnectMulticastPortsStore = storageService.<VlanNextObjectiveStoreKey, List<PortNumber>>consistentMapBuilder() |
| 197 | .withName("onos-sr-xconnect-l2multicast-ports") |
| 198 | .withSerializer(Serializer.using(serializer.build())) |
| 199 | .build(); |
| 200 | |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 201 | deviceEventExecutor = Executors.newSingleThreadScheduledExecutor( |
| 202 | groupedThreads("sr-xconnect-device-event", "%d", log)); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 203 | deviceService.addListener(deviceListener); |
| 204 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 205 | hostEventExecutor = Executors.newSingleThreadExecutor( |
| 206 | groupedThreads("sr-xconnect-host-event", "%d", log)); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 207 | hostService.addListener(hostListener); |
| 208 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 209 | log.info("Started"); |
| 210 | } |
| 211 | |
| 212 | @Deactivate |
| 213 | void deactivate() { |
| 214 | xconnectStore.removeListener(xconnectListener); |
| 215 | deviceService.removeListener(deviceListener); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 216 | hostService.removeListener(hostListener); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 217 | codecService.unregisterCodec(XconnectDesc.class); |
| 218 | |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 219 | deviceEventExecutor.shutdown(); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 220 | hostEventExecutor.shutdown(); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 221 | xConnectExecutor.shutdown(); |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 222 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 223 | log.info("Stopped"); |
| 224 | } |
| 225 | |
| 226 | @Override |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 227 | public void addOrUpdateXconnect(DeviceId deviceId, VlanId vlanId, Set<String> ports) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 228 | log.info("Adding or updating xconnect. deviceId={}, vlanId={}, ports={}", |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 229 | deviceId, vlanId, ports); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 230 | final XconnectKey key = new XconnectKey(deviceId, vlanId); |
| 231 | xconnectStore.put(key, ports); |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void removeXonnect(DeviceId deviceId, VlanId vlanId) { |
| 236 | log.info("Removing xconnect. deviceId={}, vlanId={}", |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 237 | deviceId, vlanId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 238 | final XconnectKey key = new XconnectKey(deviceId, vlanId); |
| 239 | xconnectStore.remove(key); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 240 | |
| 241 | // Cleanup multicasting support, if any. |
| 242 | srService.getPairDeviceId(deviceId).ifPresent(pairDeviceId -> { |
| 243 | cleanupL2MulticastRule(pairDeviceId, srService.getPairLocalPort(pairDeviceId).get(), vlanId, true); |
| 244 | }); |
| 245 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public Set<XconnectDesc> getXconnects() { |
| 250 | return xconnectStore.asJavaMap().entrySet().stream() |
| 251 | .map(e -> new XconnectDesc(e.getKey(), e.getValue())) |
| 252 | .collect(Collectors.toSet()); |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public boolean hasXconnect(ConnectPoint cp) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 257 | return getXconnects().stream().anyMatch(desc -> desc.key().deviceId().equals(cp.deviceId()) |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 258 | && desc.ports().contains(cp.port().toString()) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 259 | ); |
| 260 | } |
| 261 | |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 262 | @Override |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 263 | public List<VlanId> getXconnectVlans(DeviceId deviceId, PortNumber port) { |
| 264 | return getXconnects().stream() |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 265 | .filter(desc -> desc.key().deviceId().equals(deviceId) && desc.ports().contains(port.toString())) |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 266 | .map(desc -> desc.key().vlanId()) |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 267 | .collect(Collectors.toList()); |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public boolean isXconnectVlan(DeviceId deviceId, VlanId vlanId) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 272 | XconnectKey key = new XconnectKey(deviceId, vlanId); |
| 273 | return Versioned.valueOrNull(xconnectStore.get(key)) != null; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | @Override |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 277 | public ImmutableMap<XconnectKey, Integer> getNext() { |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 278 | if (xconnectNextObjStore != null) { |
| 279 | return ImmutableMap.copyOf(xconnectNextObjStore.asJavaMap()); |
| 280 | } else { |
| 281 | return ImmutableMap.of(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | @Override |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 286 | public int getNextId(DeviceId deviceId, VlanId vlanId) { |
| 287 | return Versioned.valueOrElse(xconnectNextObjStore.get(new XconnectKey(deviceId, vlanId)), -1); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 291 | public void removeNextId(int nextId) { |
| 292 | xconnectNextObjStore.entrySet().forEach(e -> { |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 293 | if (e.getValue().value() == nextId) { |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 294 | xconnectNextObjStore.remove(e.getKey()); |
| 295 | } |
| 296 | }); |
| 297 | } |
| 298 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 299 | private class XconnectMapListener implements MapEventListener<XconnectKey, Set<String>> { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 300 | @Override |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 301 | public void event(MapEvent<XconnectKey, Set<String>> event) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 302 | XconnectKey key = event.key(); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 303 | Set<String> ports = Versioned.valueOrNull(event.newValue()); |
| 304 | Set<String> oldPorts = Versioned.valueOrNull(event.oldValue()); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 305 | |
| 306 | switch (event.type()) { |
| 307 | case INSERT: |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 308 | populateXConnect(key, ports); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 309 | break; |
| 310 | case UPDATE: |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 311 | updateXConnect(key, oldPorts, ports); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 312 | break; |
| 313 | case REMOVE: |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 314 | revokeXConnect(key, oldPorts); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 315 | break; |
| 316 | default: |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | private class InternalDeviceListener implements DeviceListener { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 323 | // Offload the execution to an executor and then process the event |
| 324 | // if this instance is the leader of the device |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 325 | @Override |
| 326 | public void event(DeviceEvent event) { |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 327 | deviceEventExecutor.execute(() -> { |
| 328 | DeviceId deviceId = event.subject().id(); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 329 | // Just skip if we are not the leader |
| 330 | if (!isLocalLeader(deviceId)) { |
| 331 | log.debug("Not the leader of {}. Skip event {}", deviceId, event); |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 332 | return; |
| 333 | } |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 334 | // Populate or revoke according to the device availability |
| 335 | if (deviceService.isAvailable(deviceId)) { |
| 336 | init(deviceId); |
| 337 | } else { |
| 338 | cleanup(deviceId); |
Charles Chan | 56542b6 | 2018-08-07 12:48:36 -0700 | [diff] [blame] | 339 | } |
| 340 | }); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 341 | } |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 342 | // We want to manage only a subset of events and if we are the leader |
| 343 | @Override |
| 344 | public boolean isRelevant(DeviceEvent event) { |
| 345 | return event.type() == DeviceEvent.Type.DEVICE_ADDED || |
| 346 | event.type() == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 347 | event.type() == DeviceEvent.Type.DEVICE_UPDATED; |
| 348 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 349 | } |
| 350 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 351 | private class InternalHostListener implements HostListener { |
| 352 | @Override |
| 353 | public void event(HostEvent event) { |
| 354 | hostEventExecutor.execute(() -> { |
| 355 | |
| 356 | switch (event.type()) { |
| 357 | case HOST_MOVED: |
| 358 | log.trace("Processing host event {}", event); |
| 359 | |
| 360 | Host host = event.subject(); |
| 361 | Set<HostLocation> prevLocations = event.prevSubject().locations(); |
| 362 | Set<HostLocation> newLocations = host.locations(); |
| 363 | |
| 364 | // Dual-home host port failure |
| 365 | // For each old location, in failed and paired devices update L2 vlan groups |
| 366 | Sets.difference(prevLocations, newLocations).forEach(prevLocation -> { |
| 367 | |
| 368 | Optional<DeviceId> pairDeviceId = srService.getPairDeviceId(prevLocation.deviceId()); |
| 369 | Optional<PortNumber> pairLocalPort = srService.getPairLocalPort(prevLocation.deviceId()); |
| 370 | |
| 371 | if (pairDeviceId.isPresent() && pairLocalPort.isPresent() && newLocations.stream() |
| 372 | .anyMatch(location -> location.deviceId().equals(pairDeviceId.get())) && |
| 373 | hasXconnect(new ConnectPoint(prevLocation.deviceId(), prevLocation.port()))) { |
| 374 | |
| 375 | List<VlanId> xconnectVlans = getXconnectVlans(prevLocation.deviceId(), |
| 376 | prevLocation.port()); |
| 377 | xconnectVlans.forEach(xconnectVlan -> { |
| 378 | // Add single-home host into L2 multicast group at paired device side. |
| 379 | // Also append ACL rule to forward traffic from paired port to L2 multicast group. |
| 380 | newLocations.stream() |
| 381 | .filter(location -> location.deviceId().equals(pairDeviceId.get())) |
| 382 | .forEach(location -> populateL2Multicast(location.deviceId(), |
| 383 | srService.getPairLocalPort( |
| 384 | location.deviceId()).get(), |
| 385 | xconnectVlan, |
| 386 | Collections.singletonList( |
| 387 | location.port()))); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 388 | // Ensure pair-port attached to xconnect vlan flooding group |
| 389 | // at dual home failed device. |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 390 | updateL2Flooding(prevLocation.deviceId(), pairLocalPort.get(), xconnectVlan, true); |
| 391 | }); |
| 392 | } |
| 393 | }); |
| 394 | |
| 395 | // Dual-home host port restoration |
| 396 | // For each new location, reverse xconnect loop prevention groups. |
| 397 | Sets.difference(newLocations, prevLocations).forEach(newLocation -> { |
| 398 | final Optional<DeviceId> pairDeviceId = srService.getPairDeviceId(newLocation.deviceId()); |
| 399 | Optional<PortNumber> pairLocalPort = srService.getPairLocalPort(newLocation.deviceId()); |
| 400 | if (pairDeviceId.isPresent() && pairLocalPort.isPresent() && |
| 401 | hasXconnect((new ConnectPoint(newLocation.deviceId(), newLocation.port())))) { |
| 402 | |
| 403 | List<VlanId> xconnectVlans = getXconnectVlans(newLocation.deviceId(), |
| 404 | newLocation.port()); |
| 405 | xconnectVlans.forEach(xconnectVlan -> { |
| 406 | // Remove recovered dual homed port from vlan L2 multicast group |
| 407 | prevLocations.stream() |
| 408 | .filter(prevLocation -> prevLocation.deviceId().equals(pairDeviceId.get())) |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 409 | .forEach(prevLocation -> revokeL2Multicast( |
| 410 | prevLocation.deviceId(), |
| 411 | xconnectVlan, |
| 412 | Collections.singletonList(newLocation.port())) |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 413 | ); |
| 414 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 415 | // Remove pair-port from vlan's flooding group at dual home |
| 416 | // restored device, if needed. |
| 417 | if (!hasAccessPortInMulticastGroup(new VlanNextObjectiveStoreKey( |
| 418 | newLocation.deviceId(), xconnectVlan), pairLocalPort.get())) { |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 419 | updateL2Flooding(newLocation.deviceId(), |
| 420 | pairLocalPort.get(), |
| 421 | xconnectVlan, |
| 422 | false); |
| 423 | |
| 424 | // Clean L2 multicast group at pair-device; also update store. |
| 425 | cleanupL2MulticastRule(pairDeviceId.get(), |
| 426 | srService.getPairLocalPort(pairDeviceId.get()).get(), |
| 427 | xconnectVlan, |
| 428 | false); |
| 429 | } |
| 430 | }); |
| 431 | } |
| 432 | }); |
| 433 | break; |
| 434 | |
| 435 | default: |
| 436 | log.warn("Unsupported host event type: {} received. Ignoring.", event.type()); |
| 437 | break; |
| 438 | } |
| 439 | }); |
| 440 | } |
| 441 | } |
| 442 | |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 443 | private void init(DeviceId deviceId) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 444 | getXconnects().stream() |
| 445 | .filter(desc -> desc.key().deviceId().equals(deviceId)) |
| 446 | .forEach(desc -> populateXConnect(desc.key(), desc.ports())); |
| 447 | } |
| 448 | |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 449 | private void cleanup(DeviceId deviceId) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 450 | xconnectNextObjStore.entrySet().stream() |
| 451 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
| 452 | .forEach(entry -> xconnectNextObjStore.remove(entry.getKey())); |
| 453 | log.debug("{} is removed from xConnectNextObjStore", deviceId); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Populates XConnect groups and flows for given key. |
| 458 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 459 | * @param key XConnect key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 460 | * @param ports a set of ports to be cross-connected |
| 461 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 462 | private void populateXConnect(XconnectKey key, Set<String> ports) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 463 | if (!isLocalLeader(key.deviceId())) { |
| 464 | log.debug("Abort populating XConnect {}: {}", key, ERROR_NOT_LEADER); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 468 | int nextId = populateNext(key, ports); |
| 469 | if (nextId == -1) { |
| 470 | log.warn("Fail to populateXConnect {}: {}", key, ERROR_NEXT_ID); |
| 471 | return; |
| 472 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 473 | populateFilter(key, ports); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 474 | populateFwd(key, nextId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 475 | populateAcl(key); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Populates filtering objectives for given XConnect. |
| 480 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 481 | * @param key XConnect store key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 482 | * @param ports XConnect ports |
| 483 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 484 | private void populateFilter(XconnectKey key, Set<String> ports) { |
| 485 | // FIXME Improve the logic |
| 486 | // If L2 load balancer is not involved, use filtered port. Otherwise, use unfiltered port. |
| 487 | // The purpose is to make sure existing XConnect logic can still work on a configured port. |
| 488 | boolean filtered = ports.stream() |
| 489 | .map(p -> getNextTreatment(key.deviceId(), p)) |
| 490 | .allMatch(t -> t.type().equals(NextTreatment.Type.TREATMENT)); |
| 491 | |
| 492 | ports.stream() |
| 493 | .map(p -> getPhysicalPorts(key.deviceId(), p)) |
| 494 | .flatMap(Set::stream).forEach(port -> { |
| 495 | FilteringObjective.Builder filtObjBuilder = filterObjBuilder(key, port, filtered); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 496 | ObjectiveContext context = new DefaultObjectiveContext( |
| 497 | (objective) -> log.debug("XConnect FilterObj for {} on port {} populated", |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 498 | key, port), |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 499 | (objective, error) -> |
| 500 | log.warn("Failed to populate XConnect FilterObj for {} on port {}: {}", |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 501 | key, port, error)); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 502 | flowObjectiveService.filter(key.deviceId(), filtObjBuilder.add(context)); |
| 503 | }); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Populates next objectives for given XConnect. |
| 508 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 509 | * @param key XConnect store key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 510 | * @param ports XConnect ports |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 511 | * @return next id |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 512 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 513 | private int populateNext(XconnectKey key, Set<String> ports) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 514 | int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1); |
| 515 | if (nextId != -1) { |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 516 | log.debug("NextObj for {} found, id={}", key, nextId); |
| 517 | return nextId; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 518 | } else { |
| 519 | NextObjective.Builder nextObjBuilder = nextObjBuilder(key, ports); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 520 | if (nextObjBuilder == null) { |
| 521 | log.warn("Fail to populate {}: {}", key, ERROR_NEXT_OBJ_BUILDER); |
| 522 | return -1; |
| 523 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 524 | ObjectiveContext nextContext = new DefaultObjectiveContext( |
| 525 | // To serialize this with kryo |
| 526 | (Serializable & Consumer<Objective>) (objective) -> |
| 527 | log.debug("XConnect NextObj for {} added", key), |
Charles Chan | facfbef | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 528 | (Serializable & BiConsumer<Objective, ObjectiveError>) (objective, error) -> { |
| 529 | log.warn("Failed to add XConnect NextObj for {}: {}", key, error); |
| 530 | srService.invalidateNextObj(objective.id()); |
| 531 | }); |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 532 | NextObjective nextObj = nextObjBuilder.add(nextContext); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 533 | flowObjectiveService.next(key.deviceId(), nextObj); |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 534 | xconnectNextObjStore.put(key, nextObj.id()); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 535 | log.debug("NextObj for {} not found. Creating new NextObj with id={}", key, nextObj.id()); |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 536 | return nextObj.id(); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 537 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Populates bridging forwarding objectives for given XConnect. |
| 542 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 543 | * @param key XConnect store key |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 544 | * @param nextId next objective id |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 545 | */ |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 546 | private void populateFwd(XconnectKey key, int nextId) { |
| 547 | ForwardingObjective.Builder fwdObjBuilder = fwdObjBuilder(key, nextId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 548 | ObjectiveContext fwdContext = new DefaultObjectiveContext( |
| 549 | (objective) -> log.debug("XConnect FwdObj for {} populated", key), |
| 550 | (objective, error) -> |
| 551 | log.warn("Failed to populate XConnect FwdObj for {}: {}", key, error)); |
| 552 | flowObjectiveService.forward(key.deviceId(), fwdObjBuilder.add(fwdContext)); |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Populates ACL forwarding objectives for given XConnect. |
| 557 | * |
| 558 | * @param key XConnect store key |
| 559 | */ |
| 560 | private void populateAcl(XconnectKey key) { |
| 561 | ForwardingObjective.Builder aclObjBuilder = aclObjBuilder(key.vlanId()); |
| 562 | ObjectiveContext aclContext = new DefaultObjectiveContext( |
| 563 | (objective) -> log.debug("XConnect AclObj for {} populated", key), |
| 564 | (objective, error) -> |
| 565 | log.warn("Failed to populate XConnect AclObj for {}: {}", key, error)); |
| 566 | flowObjectiveService.forward(key.deviceId(), aclObjBuilder.add(aclContext)); |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Revokes XConnect groups and flows for given key. |
| 571 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 572 | * @param key XConnect key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 573 | * @param ports XConnect ports |
| 574 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 575 | private void revokeXConnect(XconnectKey key, Set<String> ports) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 576 | if (!isLocalLeader(key.deviceId())) { |
| 577 | log.debug("Abort revoking XConnect {}: {}", key, ERROR_NOT_LEADER); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 578 | return; |
| 579 | } |
| 580 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 581 | revokeFilter(key, ports); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 582 | int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1); |
| 583 | if (nextId != -1) { |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 584 | revokeFwd(key, nextId, null); |
| 585 | revokeNext(key, ports, nextId, null); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 586 | } else { |
| 587 | log.warn("NextObj for {} does not exist in the store.", key); |
| 588 | } |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 589 | revokeFilter(key, ports); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 590 | revokeAcl(key); |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Revokes filtering objectives for given XConnect. |
| 595 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 596 | * @param key XConnect store key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 597 | * @param ports XConnect ports |
| 598 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 599 | private void revokeFilter(XconnectKey key, Set<String> ports) { |
| 600 | // FIXME Improve the logic |
| 601 | // If L2 load balancer is not involved, use filtered port. Otherwise, use unfiltered port. |
| 602 | // The purpose is to make sure existing XConnect logic can still work on a configured port. |
| 603 | Set<Set<PortNumber>> portsSet = ports.stream() |
| 604 | .map(p -> getPhysicalPorts(key.deviceId(), p)).collect(Collectors.toSet()); |
| 605 | boolean filtered = portsSet.stream().allMatch(s -> s.size() == 1); |
| 606 | portsSet.stream().flatMap(Set::stream).forEach(port -> { |
| 607 | FilteringObjective.Builder filtObjBuilder = filterObjBuilder(key, port, filtered); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 608 | ObjectiveContext context = new DefaultObjectiveContext( |
| 609 | (objective) -> log.debug("XConnect FilterObj for {} on port {} revoked", |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 610 | key, port), |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 611 | (objective, error) -> |
| 612 | log.warn("Failed to revoke XConnect FilterObj for {} on port {}: {}", |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 613 | key, port, error)); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 614 | flowObjectiveService.filter(key.deviceId(), filtObjBuilder.remove(context)); |
| 615 | }); |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * Revokes next objectives for given XConnect. |
| 620 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 621 | * @param key XConnect store key |
| 622 | * @param ports ports in the XConnect |
| 623 | * @param nextId next objective id |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 624 | * @param nextFuture completable future for this next objective operation |
| 625 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 626 | private void revokeNext(XconnectKey key, Set<String> ports, int nextId, |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 627 | CompletableFuture<ObjectiveError> nextFuture) { |
| 628 | ObjectiveContext context = new ObjectiveContext() { |
| 629 | @Override |
| 630 | public void onSuccess(Objective objective) { |
| 631 | log.debug("Previous NextObj for {} removed", key); |
| 632 | if (nextFuture != null) { |
| 633 | nextFuture.complete(null); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public void onError(Objective objective, ObjectiveError error) { |
| 639 | log.warn("Failed to remove previous NextObj for {}: {}", key, error); |
| 640 | if (nextFuture != null) { |
| 641 | nextFuture.complete(error); |
| 642 | } |
Charles Chan | facfbef | 2018-08-23 14:30:33 -0700 | [diff] [blame] | 643 | srService.invalidateNextObj(objective.id()); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 644 | } |
| 645 | }; |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 646 | |
| 647 | NextObjective.Builder nextObjBuilder = nextObjBuilder(key, ports, nextId); |
| 648 | if (nextObjBuilder == null) { |
| 649 | log.warn("Fail to revokeNext {}: {}", key, ERROR_NEXT_OBJ_BUILDER); |
| 650 | return; |
| 651 | } |
| 652 | flowObjectiveService.next(key.deviceId(), nextObjBuilder.remove(context)); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 653 | xconnectNextObjStore.remove(key); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * Revokes bridging forwarding objectives for given XConnect. |
| 658 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 659 | * @param key XConnect store key |
| 660 | * @param nextId next objective id |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 661 | * @param fwdFuture completable future for this forwarding objective operation |
| 662 | */ |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 663 | private void revokeFwd(XconnectKey key, int nextId, CompletableFuture<ObjectiveError> fwdFuture) { |
| 664 | ForwardingObjective.Builder fwdObjBuilder = fwdObjBuilder(key, nextId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 665 | ObjectiveContext context = new ObjectiveContext() { |
| 666 | @Override |
| 667 | public void onSuccess(Objective objective) { |
| 668 | log.debug("Previous FwdObj for {} removed", key); |
| 669 | if (fwdFuture != null) { |
| 670 | fwdFuture.complete(null); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | @Override |
| 675 | public void onError(Objective objective, ObjectiveError error) { |
| 676 | log.warn("Failed to remove previous FwdObj for {}: {}", key, error); |
| 677 | if (fwdFuture != null) { |
| 678 | fwdFuture.complete(error); |
| 679 | } |
| 680 | } |
| 681 | }; |
| 682 | flowObjectiveService.forward(key.deviceId(), fwdObjBuilder.remove(context)); |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Revokes ACL forwarding objectives for given XConnect. |
| 687 | * |
| 688 | * @param key XConnect store key |
| 689 | */ |
| 690 | private void revokeAcl(XconnectKey key) { |
| 691 | ForwardingObjective.Builder aclObjBuilder = aclObjBuilder(key.vlanId()); |
| 692 | ObjectiveContext aclContext = new DefaultObjectiveContext( |
| 693 | (objective) -> log.debug("XConnect AclObj for {} populated", key), |
| 694 | (objective, error) -> |
| 695 | log.warn("Failed to populate XConnect AclObj for {}: {}", key, error)); |
| 696 | flowObjectiveService.forward(key.deviceId(), aclObjBuilder.remove(aclContext)); |
| 697 | } |
| 698 | |
| 699 | /** |
| 700 | * Updates XConnect groups and flows for given key. |
| 701 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 702 | * @param key XConnect key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 703 | * @param prevPorts previous XConnect ports |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 704 | * @param ports new XConnect ports |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 705 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 706 | private void updateXConnect(XconnectKey key, Set<String> prevPorts, |
| 707 | Set<String> ports) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 708 | if (!isLocalLeader(key.deviceId())) { |
| 709 | log.debug("Abort updating XConnect {}: {}", key, ERROR_NOT_LEADER); |
| 710 | return; |
| 711 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 712 | // NOTE: ACL flow doesn't include port information. No need to update it. |
| 713 | // Pair port is built-in and thus not going to change. No need to update it. |
| 714 | |
| 715 | // remove old filter |
| 716 | prevPorts.stream().filter(port -> !ports.contains(port)).forEach(port -> |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 717 | revokeFilter(key, ImmutableSet.of(port))); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 718 | // install new filter |
| 719 | ports.stream().filter(port -> !prevPorts.contains(port)).forEach(port -> |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 720 | populateFilter(key, ImmutableSet.of(port))); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 721 | |
| 722 | CompletableFuture<ObjectiveError> fwdFuture = new CompletableFuture<>(); |
| 723 | CompletableFuture<ObjectiveError> nextFuture = new CompletableFuture<>(); |
| 724 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 725 | int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1); |
| 726 | if (nextId != -1) { |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 727 | revokeFwd(key, nextId, fwdFuture); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 728 | |
| 729 | fwdFuture.thenAcceptAsync(fwdStatus -> { |
| 730 | if (fwdStatus == null) { |
| 731 | log.debug("Fwd removed. Now remove group {}", key); |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 732 | revokeNext(key, prevPorts, nextId, nextFuture); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 733 | } |
| 734 | }); |
| 735 | |
| 736 | nextFuture.thenAcceptAsync(nextStatus -> { |
| 737 | if (nextStatus == null) { |
| 738 | log.debug("Installing new group and flow for {}", key); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 739 | int newNextId = populateNext(key, ports); |
| 740 | if (newNextId == -1) { |
| 741 | log.warn("Fail to updateXConnect {}: {}", key, ERROR_NEXT_ID); |
| 742 | return; |
| 743 | } |
| 744 | populateFwd(key, newNextId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 745 | } |
| 746 | }); |
| 747 | } else { |
| 748 | log.warn("NextObj for {} does not exist in the store.", key); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 753 | * Creates a next objective builder for XConnect with given nextId. |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 754 | * |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 755 | * @param key XConnect key |
| 756 | * @param ports ports or L2 load balancer key |
| 757 | * @param nextId next objective id |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 758 | * @return next objective builder |
| 759 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 760 | private NextObjective.Builder nextObjBuilder(XconnectKey key, Set<String> ports, int nextId) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 761 | TrafficSelector metadata = |
| 762 | DefaultTrafficSelector.builder().matchVlanId(key.vlanId()).build(); |
| 763 | NextObjective.Builder nextObjBuilder = DefaultNextObjective |
| 764 | .builder().withId(nextId) |
| 765 | .withType(NextObjective.Type.BROADCAST).fromApp(appId) |
| 766 | .withMeta(metadata); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 767 | |
| 768 | for (String port : ports) { |
| 769 | NextTreatment nextTreatment = getNextTreatment(key.deviceId(), port); |
| 770 | if (nextTreatment == null) { |
| 771 | log.warn("Unable to create nextObj. Null NextTreatment"); |
| 772 | return null; |
| 773 | } |
| 774 | nextObjBuilder.addTreatment(nextTreatment); |
| 775 | } |
| 776 | |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 777 | return nextObjBuilder; |
| 778 | } |
| 779 | |
| 780 | /** |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 781 | * Creates a next objective builder for XConnect. |
| 782 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 783 | * @param key XConnect key |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 784 | * @param ports set of XConnect ports |
| 785 | * @return next objective builder |
| 786 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 787 | private NextObjective.Builder nextObjBuilder(XconnectKey key, Set<String> ports) { |
Charles Chan | 1fb6513 | 2018-09-21 11:29:12 -0700 | [diff] [blame] | 788 | int nextId = flowObjectiveService.allocateNextId(); |
| 789 | return nextObjBuilder(key, ports, nextId); |
| 790 | } |
| 791 | |
| 792 | |
| 793 | /** |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 794 | * Creates a bridging forwarding objective builder for XConnect. |
| 795 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 796 | * @param key XConnect key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 797 | * @param nextId next ID of the broadcast group for this XConnect key |
| 798 | * @return forwarding objective builder |
| 799 | */ |
| 800 | private ForwardingObjective.Builder fwdObjBuilder(XconnectKey key, int nextId) { |
| 801 | /* |
| 802 | * Driver should treat objectives with MacAddress.NONE and !VlanId.NONE |
| 803 | * as the VLAN cross-connect broadcast rules |
| 804 | */ |
| 805 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 806 | sbuilder.matchVlanId(key.vlanId()); |
| 807 | sbuilder.matchEthDst(MacAddress.NONE); |
| 808 | |
| 809 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 810 | fob.withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 811 | .withSelector(sbuilder.build()) |
| 812 | .nextStep(nextId) |
| 813 | .withPriority(XCONNECT_PRIORITY) |
| 814 | .fromApp(appId) |
| 815 | .makePermanent(); |
| 816 | return fob; |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * Creates an ACL forwarding objective builder for XConnect. |
| 821 | * |
| 822 | * @param vlanId cross connect VLAN id |
| 823 | * @return forwarding objective builder |
| 824 | */ |
| 825 | private ForwardingObjective.Builder aclObjBuilder(VlanId vlanId) { |
| 826 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 827 | sbuilder.matchVlanId(vlanId); |
| 828 | |
| 829 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 830 | |
| 831 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 832 | fob.withFlag(ForwardingObjective.Flag.VERSATILE) |
| 833 | .withSelector(sbuilder.build()) |
| 834 | .withTreatment(tbuilder.build()) |
| 835 | .withPriority(XCONNECT_ACL_PRIORITY) |
| 836 | .fromApp(appId) |
| 837 | .makePermanent(); |
| 838 | return fob; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Creates a filtering objective builder for XConnect. |
| 843 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 844 | * @param key XConnect key |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 845 | * @param port XConnect ports |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 846 | * @param filtered true if this is a filtered port |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 847 | * @return next objective builder |
| 848 | */ |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 849 | private FilteringObjective.Builder filterObjBuilder(XconnectKey key, PortNumber port, boolean filtered) { |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 850 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 851 | fob.withKey(Criteria.matchInPort(port)) |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 852 | .addCondition(Criteria.matchEthDst(MacAddress.NONE)) |
| 853 | .withPriority(XCONNECT_PRIORITY); |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 854 | if (filtered) { |
| 855 | fob.addCondition(Criteria.matchVlanId(key.vlanId())); |
| 856 | } else { |
| 857 | fob.addCondition(Criteria.matchVlanId(VlanId.ANY)); |
| 858 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 859 | return fob.permit().fromApp(appId); |
| 860 | } |
| 861 | |
| 862 | /** |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 863 | * Updates L2 flooding groups; add pair link into L2 flooding group of given xconnect vlan. |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 864 | * |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 865 | * @param deviceId Device ID |
| 866 | * @param port Port details |
| 867 | * @param vlanId VLAN ID |
| 868 | * @param install Whether to add or revoke pair link addition to flooding group |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 869 | */ |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 870 | private void updateL2Flooding(DeviceId deviceId, PortNumber port, VlanId vlanId, boolean install) { |
| 871 | XconnectKey key = new XconnectKey(deviceId, vlanId); |
| 872 | // Ensure leadership on device |
| 873 | if (!isLocalLeader(deviceId)) { |
| 874 | log.debug("Abort updating L2Flood {}: {}", key, ERROR_NOT_LEADER); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 875 | return; |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 876 | } |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 877 | |
| 878 | // Locate L2 flooding group details for given xconnect vlan |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 879 | int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 880 | if (nextId == -1) { |
| 881 | log.debug("XConnect vlan {} broadcast group for device {} doesn't exists. " + |
| 882 | "Aborting pair group linking.", vlanId, deviceId); |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | // Add pairing-port group to flooding group |
| 887 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 888 | // treatment.popVlan(); |
| 889 | treatment.setOutput(port); |
| 890 | ObjectiveContext context = new DefaultObjectiveContext( |
| 891 | (objective) -> |
| 892 | log.debug("Pair port added/removed to vlan {} next objective {} on {}", |
| 893 | vlanId, nextId, deviceId), |
| 894 | (objective, error) -> |
| 895 | log.warn("Failed adding/removing pair port to vlan {} next objective {} on {}." + |
| 896 | "Error : {}", vlanId, nextId, deviceId, error) |
| 897 | ); |
| 898 | NextObjective.Builder vlanNextObjectiveBuilder = DefaultNextObjective.builder() |
| 899 | .withId(nextId) |
| 900 | .withType(NextObjective.Type.BROADCAST) |
| 901 | .fromApp(srService.appId()) |
| 902 | .withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).build()) |
| 903 | .addTreatment(treatment.build()); |
| 904 | if (install) { |
| 905 | flowObjectiveService.next(deviceId, vlanNextObjectiveBuilder.addToExisting(context)); |
| 906 | } else { |
| 907 | flowObjectiveService.next(deviceId, vlanNextObjectiveBuilder.removeFromExisting(context)); |
| 908 | } |
| 909 | log.debug("Submitted next objective {} for vlan: {} in device {}", |
| 910 | nextId, vlanId, deviceId); |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 911 | } |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 912 | |
| 913 | /** |
| 914 | * Populate L2 multicast rule on given deviceId that matches given mac, given vlan and |
| 915 | * output to given port's L2 mulitcast group. |
| 916 | * |
| 917 | * @param deviceId Device ID |
| 918 | * @param pairPort Pair port number |
| 919 | * @param vlanId VLAN ID |
| 920 | * @param accessPorts List of access ports to be added into L2 multicast group |
| 921 | */ |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 922 | private void populateL2Multicast(DeviceId deviceId, PortNumber pairPort, |
| 923 | VlanId vlanId, List<PortNumber> accessPorts) { |
| 924 | // Ensure enough rights to program pair device |
| 925 | if (!srService.shouldProgram(deviceId)) { |
| 926 | log.debug("Abort populate L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER); |
| 927 | return; |
| 928 | } |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 929 | |
| 930 | boolean multicastGroupExists = true; |
| 931 | int vlanMulticastNextId; |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 932 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 933 | |
| 934 | // Step 1 : Populate single homed access ports into vlan's L2 multicast group |
| 935 | NextObjective.Builder vlanMulticastNextObjBuilder = DefaultNextObjective |
| 936 | .builder() |
| 937 | .withType(NextObjective.Type.BROADCAST) |
| 938 | .fromApp(srService.appId()) |
| 939 | .withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId) |
| 940 | .matchEthDst(MacAddress.IPV4_MULTICAST).build()); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 941 | vlanMulticastNextId = getMulticastGroupNextObjectiveId(key); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 942 | if (vlanMulticastNextId == -1) { |
| 943 | // Vlan's L2 multicast group doesn't exist; create it, update store and add pair port as sub-group |
| 944 | multicastGroupExists = false; |
| 945 | vlanMulticastNextId = flowObjectiveService.allocateNextId(); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 946 | addMulticastGroupNextObjectiveId(key, vlanMulticastNextId); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 947 | vlanMulticastNextObjBuilder.addTreatment( |
| 948 | DefaultTrafficTreatment.builder().popVlan().setOutput(pairPort).build() |
| 949 | ); |
| 950 | } |
| 951 | vlanMulticastNextObjBuilder.withId(vlanMulticastNextId); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 952 | int nextId = vlanMulticastNextId; |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 953 | accessPorts.forEach(p -> { |
| 954 | TrafficTreatment.Builder egressAction = DefaultTrafficTreatment.builder(); |
| 955 | // Do vlan popup action based on interface configuration |
| 956 | if (interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, p)) |
| 957 | .stream().noneMatch(i -> i.vlanTagged().contains(vlanId))) { |
| 958 | egressAction.popVlan(); |
| 959 | } |
| 960 | egressAction.setOutput(p); |
| 961 | vlanMulticastNextObjBuilder.addTreatment(egressAction.build()); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 962 | addMulticastGroupPort(key, p); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 963 | }); |
| 964 | ObjectiveContext context = new DefaultObjectiveContext( |
| 965 | (objective) -> |
| 966 | log.debug("L2 multicast group installed/updated. " |
| 967 | + "NextObject Id {} on {} for subnet {} ", |
| 968 | nextId, deviceId, vlanId), |
| 969 | (objective, error) -> |
| 970 | log.warn("L2 multicast group failed to install/update. " |
| 971 | + " NextObject Id {} on {} for subnet {} : {}", |
| 972 | nextId, deviceId, vlanId, error) |
| 973 | ); |
| 974 | if (!multicastGroupExists) { |
| 975 | flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.add(context)); |
| 976 | |
| 977 | // Step 2 : Populate ACL rule; selector = vlan + pair-port, output = vlan L2 multicast group |
| 978 | TrafficSelector.Builder multicastSelector = DefaultTrafficSelector.builder(); |
| 979 | multicastSelector.matchEthType(Ethernet.TYPE_VLAN); |
| 980 | multicastSelector.matchInPort(pairPort); |
| 981 | multicastSelector.matchVlanId(vlanId); |
| 982 | ForwardingObjective.Builder vlanMulticastForwardingObj = DefaultForwardingObjective.builder() |
| 983 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 984 | .nextStep(vlanMulticastNextId) |
| 985 | .withSelector(multicastSelector.build()) |
| 986 | .withPriority(100) |
| 987 | .fromApp(srService.appId()) |
| 988 | .makePermanent(); |
| 989 | context = new DefaultObjectiveContext( |
| 990 | (objective) -> log.debug("L2 multicasting versatile rule for device {}, port/vlan {}/{} populated", |
| 991 | deviceId, |
| 992 | pairPort, |
| 993 | vlanId), |
| 994 | (objective, error) -> log.warn("Failed to populate L2 multicasting versatile rule for device {}, " + |
| 995 | "ports/vlan {}/{}: {}", deviceId, pairPort, vlanId, error)); |
| 996 | flowObjectiveService.forward(deviceId, vlanMulticastForwardingObj.add(context)); |
| 997 | } else { |
| 998 | // L2_MULTICAST & BROADCAST are similar structure in subgroups; so going with BROADCAST type. |
| 999 | vlanMulticastNextObjBuilder.withType(NextObjective.Type.BROADCAST); |
| 1000 | flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.addToExisting(context)); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Removes access ports from VLAN L2 multicast group on given deviceId. |
| 1006 | * |
| 1007 | * @param deviceId Device ID |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1008 | * @param vlanId VLAN ID |
| 1009 | * @param accessPorts List of access ports to be added into L2 multicast group |
| 1010 | */ |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1011 | private void revokeL2Multicast(DeviceId deviceId, VlanId vlanId, List<PortNumber> accessPorts) { |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1012 | // Ensure enough rights to program pair device |
| 1013 | if (!srService.shouldProgram(deviceId)) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1014 | log.debug("Abort revoke L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1015 | return; |
| 1016 | } |
| 1017 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1018 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
| 1019 | |
| 1020 | int vlanMulticastNextId = getMulticastGroupNextObjectiveId(key); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1021 | if (vlanMulticastNextId == -1) { |
| 1022 | return; |
| 1023 | } |
| 1024 | NextObjective.Builder vlanMulticastNextObjBuilder = DefaultNextObjective |
| 1025 | .builder() |
| 1026 | .withType(NextObjective.Type.BROADCAST) |
| 1027 | .fromApp(srService.appId()) |
| 1028 | .withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).build()) |
| 1029 | .withId(vlanMulticastNextId); |
| 1030 | accessPorts.forEach(p -> { |
| 1031 | TrafficTreatment.Builder egressAction = DefaultTrafficTreatment.builder(); |
| 1032 | // Do vlan popup action based on interface configuration |
| 1033 | if (interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, p)) |
| 1034 | .stream().noneMatch(i -> i.vlanTagged().contains(vlanId))) { |
| 1035 | egressAction.popVlan(); |
| 1036 | } |
| 1037 | egressAction.setOutput(p); |
| 1038 | vlanMulticastNextObjBuilder.addTreatment(egressAction.build()); |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1039 | removeMulticastGroupPort(key, p); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1040 | }); |
| 1041 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1042 | (objective) -> |
| 1043 | log.debug("L2 multicast group installed/updated. " |
| 1044 | + "NextObject Id {} on {} for subnet {} ", |
| 1045 | vlanMulticastNextId, deviceId, vlanId), |
| 1046 | (objective, error) -> |
| 1047 | log.warn("L2 multicast group failed to install/update. " |
| 1048 | + " NextObject Id {} on {} for subnet {} : {}", |
| 1049 | vlanMulticastNextId, deviceId, vlanId, error) |
| 1050 | ); |
| 1051 | flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.removeFromExisting(context)); |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Cleans up VLAN L2 multicast group on given deviceId. ACL rules for the group will also be deleted. |
| 1056 | * Normally multicast group is not removed if it contains access ports; which can be forced |
| 1057 | * by "force" flag |
| 1058 | * |
| 1059 | * @param deviceId Device ID |
| 1060 | * @param pairPort Pair port number |
| 1061 | * @param vlanId VLAN ID |
| 1062 | * @param force Forceful removal |
| 1063 | */ |
| 1064 | private void cleanupL2MulticastRule(DeviceId deviceId, PortNumber pairPort, VlanId vlanId, boolean force) { |
| 1065 | |
| 1066 | // Ensure enough rights to program pair device |
| 1067 | if (!srService.shouldProgram(deviceId)) { |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1068 | log.debug("Abort cleanup L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1072 | VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId); |
| 1073 | |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1074 | // Ensure L2 multicast group doesn't contain access ports |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1075 | if (hasAccessPortInMulticastGroup(key, pairPort) && !force) { |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1076 | return; |
| 1077 | } |
| 1078 | |
| 1079 | // Load L2 multicast group details |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1080 | int vlanMulticastNextId = getMulticastGroupNextObjectiveId(key); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1081 | if (vlanMulticastNextId == -1) { |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | // Step 1 : Clear ACL rule; selector = vlan + pair-port, output = vlan L2 multicast group |
| 1086 | TrafficSelector.Builder l2MulticastSelector = DefaultTrafficSelector.builder(); |
| 1087 | l2MulticastSelector.matchEthType(Ethernet.TYPE_VLAN); |
| 1088 | l2MulticastSelector.matchInPort(pairPort); |
| 1089 | l2MulticastSelector.matchVlanId(vlanId); |
| 1090 | ForwardingObjective.Builder vlanMulticastForwardingObj = DefaultForwardingObjective.builder() |
| 1091 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 1092 | .nextStep(vlanMulticastNextId) |
| 1093 | .withSelector(l2MulticastSelector.build()) |
| 1094 | .withPriority(100) |
| 1095 | .fromApp(srService.appId()) |
| 1096 | .makePermanent(); |
| 1097 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1098 | (objective) -> log.debug("L2 multicasting rule for device {}, port/vlan {}/{} deleted", deviceId, |
| 1099 | pairPort, vlanId), |
| 1100 | (objective, error) -> log.warn("Failed to delete L2 multicasting rule for device {}, " + |
| 1101 | "ports/vlan {}/{}: {}", deviceId, pairPort, vlanId, error)); |
| 1102 | flowObjectiveService.forward(deviceId, vlanMulticastForwardingObj.remove(context)); |
| 1103 | |
| 1104 | // Step 2 : Clear L2 multicast group associated with vlan |
| 1105 | NextObjective.Builder l2MulticastGroupBuilder = DefaultNextObjective |
| 1106 | .builder() |
| 1107 | .withId(vlanMulticastNextId) |
| 1108 | .withType(NextObjective.Type.BROADCAST) |
| 1109 | .fromApp(srService.appId()) |
| 1110 | .withMeta(DefaultTrafficSelector.builder() |
| 1111 | .matchVlanId(vlanId) |
| 1112 | .matchEthDst(MacAddress.IPV4_MULTICAST).build()) |
| 1113 | .addTreatment(DefaultTrafficTreatment.builder().popVlan().setOutput(pairPort).build()); |
| 1114 | context = new DefaultObjectiveContext( |
| 1115 | (objective) -> |
| 1116 | log.debug("L2 multicast group with NextObject Id {} deleted on {} for subnet {} ", |
| 1117 | vlanMulticastNextId, deviceId, vlanId), |
| 1118 | (objective, error) -> |
| 1119 | log.warn("L2 multicast group with NextObject Id {} failed to delete on {} for subnet {} : {}", |
| 1120 | vlanMulticastNextId, deviceId, vlanId, error) |
| 1121 | ); |
| 1122 | flowObjectiveService.next(deviceId, l2MulticastGroupBuilder.remove(context)); |
| 1123 | |
| 1124 | // Finally clear store. |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1125 | removeMulticastGroup(key); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1126 | } |
| 1127 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1128 | private int getMulticastGroupNextObjectiveId(VlanNextObjectiveStoreKey key) { |
| 1129 | return Versioned.valueOrElse(xconnectMulticastNextStore.get(key), -1); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1130 | } |
| 1131 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1132 | private void addMulticastGroupNextObjectiveId(VlanNextObjectiveStoreKey key, int nextId) { |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1133 | if (nextId == -1) { |
| 1134 | return; |
| 1135 | } |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1136 | xconnectMulticastNextStore.put(key, nextId); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1137 | } |
| 1138 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1139 | private void addMulticastGroupPort(VlanNextObjectiveStoreKey groupKey, PortNumber port) { |
| 1140 | xconnectMulticastPortsStore.compute(groupKey, (key, ports) -> { |
| 1141 | if (ports == null) { |
| 1142 | ports = Lists.newArrayList(); |
| 1143 | } |
| 1144 | ports.add(port); |
| 1145 | return ports; |
| 1146 | }); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1147 | } |
| 1148 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1149 | private void removeMulticastGroupPort(VlanNextObjectiveStoreKey groupKey, PortNumber port) { |
| 1150 | xconnectMulticastPortsStore.compute(groupKey, (key, ports) -> { |
| 1151 | if (ports != null && !ports.isEmpty()) { |
| 1152 | ports.remove(port); |
| 1153 | } |
| 1154 | return ports; |
| 1155 | }); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1156 | } |
| 1157 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1158 | private void removeMulticastGroup(VlanNextObjectiveStoreKey groupKey) { |
| 1159 | xconnectMulticastPortsStore.remove(groupKey); |
| 1160 | xconnectMulticastNextStore.remove(groupKey); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1161 | } |
| 1162 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1163 | private boolean hasAccessPortInMulticastGroup(VlanNextObjectiveStoreKey groupKey, PortNumber pairPort) { |
| 1164 | List<PortNumber> ports = Versioned.valueOrElse(xconnectMulticastPortsStore.get(groupKey), ImmutableList.of()); |
jayakumarthazhath | 66c9ec1 | 2018-10-01 00:51:54 +0530 | [diff] [blame] | 1165 | return ports.stream().anyMatch(p -> !p.equals(pairPort)); |
| 1166 | } |
| 1167 | |
pier | 6fd24fd | 2018-11-27 11:23:50 -0800 | [diff] [blame] | 1168 | // Custom-built function, when the device is not available we need a fallback mechanism |
| 1169 | private boolean isLocalLeader(DeviceId deviceId) { |
| 1170 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 1171 | // When the device is available we just check the mastership |
| 1172 | if (deviceService.isAvailable(deviceId)) { |
| 1173 | return false; |
| 1174 | } |
| 1175 | // Fallback with Leadership service - device id is used as topic |
| 1176 | NodeId leader = leadershipService.runForLeadership( |
| 1177 | deviceId.toString()).leaderNodeId(); |
| 1178 | // Verify if this node is the leader |
| 1179 | return clusterService.getLocalNode().id().equals(leader); |
| 1180 | } |
| 1181 | return true; |
| 1182 | } |
| 1183 | |
Charles Chan | 48df9ad | 2018-10-30 18:08:59 -0700 | [diff] [blame^] | 1184 | private Set<PortNumber> getPhysicalPorts(DeviceId deviceId, String port) { |
| 1185 | // If port is numeric, treat it as regular port. |
| 1186 | // Otherwise try to parse it as load balancer key and get the physical port the LB maps to. |
| 1187 | try { |
| 1188 | return Sets.newHashSet(PortNumber.portNumber(Integer.parseInt(port))); |
| 1189 | } catch (NumberFormatException e) { |
| 1190 | log.debug("Port {} is not numeric. Try to parse it as load balancer key", port); |
| 1191 | } |
| 1192 | |
| 1193 | String l2LbKey = port.substring("L2LB(".length(), port.length() - 1); |
| 1194 | try { |
| 1195 | return Sets.newHashSet(l2LbService.getL2Lb(deviceId, Integer.parseInt(l2LbKey)).ports()); |
| 1196 | } catch (NumberFormatException e) { |
| 1197 | log.debug("Port {} is not load balancer key either. Ignore", port); |
| 1198 | } catch (NullPointerException e) { |
| 1199 | log.debug("L2 load balancer {} not found. Ignore", l2LbKey); |
| 1200 | } |
| 1201 | |
| 1202 | return Sets.newHashSet(); |
| 1203 | } |
| 1204 | |
| 1205 | private NextTreatment getNextTreatment(DeviceId deviceId, String port) { |
| 1206 | // If port is numeric, treat it as regular port. |
| 1207 | // Otherwise try to parse it as load balancer key and get the physical port the LB maps to. |
| 1208 | try { |
| 1209 | PortNumber portNumber = PortNumber.portNumber(Integer.parseInt(port)); |
| 1210 | return DefaultNextTreatment.of(DefaultTrafficTreatment.builder().setOutput(portNumber).build()); |
| 1211 | } catch (NumberFormatException e) { |
| 1212 | log.debug("Port {} is not numeric. Try to parse it as load balancer key", port); |
| 1213 | } |
| 1214 | |
| 1215 | String l2LbKey = port.substring("L2LB(".length(), port.length() - 1); |
| 1216 | try { |
| 1217 | return IdNextTreatment.of(l2LbService.getL2LbNexts(deviceId, Integer.parseInt(l2LbKey))); |
| 1218 | } catch (NumberFormatException e) { |
| 1219 | log.debug("Port {} is not load balancer key either. Ignore", port); |
| 1220 | } catch (NullPointerException e) { |
| 1221 | log.debug("L2 load balancer {} not found. Ignore", l2LbKey); |
| 1222 | } |
| 1223 | |
| 1224 | return null; |
| 1225 | } |
Charles Chan | 8d31633 | 2018-06-19 20:31:57 -0700 | [diff] [blame] | 1226 | } |