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 | |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 20 | import org.onlab.packet.EthType; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 21 | import org.onlab.packet.Ethernet; |
Charles Chan | ef8d12e | 2017-12-05 21:07:38 -0800 | [diff] [blame] | 22 | import org.onlab.packet.IPv6; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 23 | import org.onlab.packet.Ip4Address; |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 24 | import org.onlab.packet.Ip6Address; |
| 25 | import org.onlab.packet.IpAddress; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IpPrefix; |
| 27 | import org.onlab.packet.MacAddress; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 28 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 31 | import org.onosproject.net.Device; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 32 | import org.onosproject.net.flowobjective.DefaultObjectiveContext; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flowobjective.Objective; |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 34 | import org.onosproject.net.flowobjective.ObjectiveContext; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 35 | import org.onosproject.net.flowobjective.ObjectiveError; |
Jonghwan Hyun | 671a7ab | 2018-04-30 09:27:21 -0700 | [diff] [blame] | 36 | import org.onosproject.net.intf.Interface; |
Charles Chan | 2d0bbcd | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 37 | import org.onosproject.net.packet.PacketPriority; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 38 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 39 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 40 | import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 41 | import org.onosproject.segmentrouting.grouphandler.DestinationSet; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 42 | import org.onosproject.net.DeviceId; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 43 | import org.onosproject.net.Port; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 44 | import org.onosproject.net.PortNumber; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 46 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flow.TrafficSelector; |
| 48 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flow.criteria.Criteria; |
| 50 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 51 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 52 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 53 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 54 | import org.onosproject.net.flowobjective.ForwardingObjective.Builder; |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 55 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 56 | import org.onosproject.segmentrouting.storekey.DummyVlanIdStoreKey; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | import org.slf4j.LoggerFactory; |
| 59 | |
| 60 | import java.util.ArrayList; |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 61 | import java.util.Collection; |
| 62 | import java.util.Collections; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 63 | import java.util.HashMap; |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 64 | import java.util.HashSet; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 65 | import java.util.List; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 66 | import java.util.Map; |
Charles Chan | 2d0bbcd | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 67 | import java.util.Optional; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 68 | import java.util.Set; |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 69 | import java.util.concurrent.atomic.AtomicLong; |
Charles Chan | f17f66b | 2018-02-26 21:33:25 -0800 | [diff] [blame] | 70 | import java.util.stream.Collectors; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 71 | |
| 72 | import static com.google.common.base.Preconditions.checkNotNull; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 73 | import static org.onlab.packet.Ethernet.TYPE_ARP; |
| 74 | import static org.onlab.packet.Ethernet.TYPE_IPV6; |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 75 | import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 76 | import static org.onlab.packet.ICMP6.NEIGHBOR_SOLICITATION; |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 77 | import static org.onlab.packet.ICMP6.ROUTER_ADVERTISEMENT; |
| 78 | import static org.onlab.packet.ICMP6.ROUTER_SOLICITATION; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 79 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 80 | import static org.onosproject.segmentrouting.SegmentRoutingService.DEFAULT_PRIORITY; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 81 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 82 | /** |
| 83 | * Populator of segment routing flow rules. |
| 84 | */ |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 85 | public class RoutingRulePopulator { |
Charles Chan | ef8d12e | 2017-12-05 21:07:38 -0800 | [diff] [blame] | 86 | private static final Logger log = LoggerFactory.getLogger(RoutingRulePopulator.class); |
| 87 | |
| 88 | private static final int ARP_NDP_PRIORITY = 30000; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 89 | |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 90 | private AtomicLong rulePopulationCounter; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 91 | private SegmentRoutingManager srManager; |
| 92 | private DeviceConfiguration config; |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 93 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Creates a RoutingRulePopulator object. |
| 96 | * |
Thomas Vachuska | 8a07509 | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 97 | * @param srManager segment routing manager reference |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 98 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 99 | RoutingRulePopulator(SegmentRoutingManager srManager) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 100 | this.srManager = srManager; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 101 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 102 | this.rulePopulationCounter = new AtomicLong(0); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Resets the population counter. |
| 107 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 108 | void resetCounter() { |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 109 | rulePopulationCounter.set(0); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns the number of rules populated. |
Thomas Vachuska | 7cfc620 | 2015-04-30 18:13:25 -0700 | [diff] [blame] | 114 | * |
| 115 | * @return number of rules |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 116 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 117 | long getCounter() { |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 118 | return rulePopulationCounter.get(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 122 | * Populate a bridging rule on given deviceId that matches given mac, given vlan and |
| 123 | * output to given port. |
| 124 | * |
| 125 | * @param deviceId device ID |
| 126 | * @param port port |
| 127 | * @param mac mac address |
| 128 | * @param vlanId VLAN ID |
| 129 | */ |
| 130 | void populateBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) { |
| 131 | ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, false); |
| 132 | if (fob == null) { |
| 133 | log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 5ff8a3c | 2018-04-07 16:51:09 -0700 | [diff] [blame] | 138 | (objective) -> log.debug("Brigding rule for {}/{} populated", mac, vlanId), |
| 139 | (objective, error) -> log.warn("Failed to populate bridging rule for {}/{}: {}", mac, vlanId, error)); |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 140 | srManager.flowObjectiveService.forward(deviceId, fob.add(context)); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Revoke a bridging rule on given deviceId that matches given mac, given vlan and |
| 145 | * output to given port. |
| 146 | * |
| 147 | * @param deviceId device ID |
| 148 | * @param port port |
| 149 | * @param mac mac address |
| 150 | * @param vlanId VLAN ID |
| 151 | */ |
| 152 | void revokeBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) { |
| 153 | ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, true); |
| 154 | if (fob == null) { |
| 155 | log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | 5ff8a3c | 2018-04-07 16:51:09 -0700 | [diff] [blame] | 160 | (objective) -> log.debug("Brigding rule for {}/{} revoked", mac, vlanId), |
| 161 | (objective, error) -> log.warn("Failed to revoke bridging rule for {}/{}: {}", mac, vlanId, error)); |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 162 | srManager.flowObjectiveService.forward(deviceId, fob.remove(context)); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Generates a forwarding objective builder for bridging rules. |
| 167 | * <p> |
| 168 | * The forwarding objective bridges packets destined to a given MAC to |
| 169 | * given port on given device. |
| 170 | * |
| 171 | * @param deviceId Device that host attaches to |
| 172 | * @param mac MAC address of the host |
| 173 | * @param hostVlanId VLAN ID of the host |
| 174 | * @param outport Port that host attaches to |
| 175 | * @param revoke true if forwarding objective is meant to revoke forwarding rule |
| 176 | * @return Forwarding objective builder |
| 177 | */ |
| 178 | private ForwardingObjective.Builder bridgingFwdObjBuilder( |
| 179 | DeviceId deviceId, MacAddress mac, VlanId hostVlanId, PortNumber outport, boolean revoke) { |
| 180 | ConnectPoint connectPoint = new ConnectPoint(deviceId, outport); |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 181 | VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint); |
| 182 | Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint); |
| 183 | VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint); |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 184 | |
| 185 | // Create host selector |
| 186 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 187 | sbuilder.matchEthDst(mac); |
| 188 | |
| 189 | // Create host treatment |
| 190 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 191 | tbuilder.immediate().setOutput(outport); |
| 192 | |
| 193 | // Create host meta |
| 194 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
| 195 | |
| 196 | // Adjust the selector, treatment and meta according to VLAN configuration |
| 197 | if (taggedVlans.contains(hostVlanId)) { |
| 198 | sbuilder.matchVlanId(hostVlanId); |
| 199 | mbuilder.matchVlanId(hostVlanId); |
| 200 | } else if (hostVlanId.equals(VlanId.NONE)) { |
| 201 | if (untaggedVlan != null) { |
| 202 | sbuilder.matchVlanId(untaggedVlan); |
| 203 | mbuilder.matchVlanId(untaggedVlan); |
| 204 | tbuilder.immediate().popVlan(); |
| 205 | } else if (nativeVlan != null) { |
| 206 | sbuilder.matchVlanId(nativeVlan); |
| 207 | mbuilder.matchVlanId(nativeVlan); |
| 208 | tbuilder.immediate().popVlan(); |
| 209 | } else { |
| 210 | log.warn("Untagged host {}/{} is not allowed on {} without untagged or native" + |
| 211 | "vlan config", mac, hostVlanId, connectPoint); |
| 212 | return null; |
| 213 | } |
| 214 | } else { |
| 215 | log.warn("Tagged host {}/{} is not allowed on {} without VLAN listed in tagged vlan", |
| 216 | mac, hostVlanId, connectPoint); |
| 217 | return null; |
| 218 | } |
| 219 | |
| 220 | // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed. |
| 221 | // If the objective is to revoke an existing rule, and for some reason |
| 222 | // the next-objective does not exist, then a new one should not be created |
| 223 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport, |
| 224 | tbuilder.build(), mbuilder.build(), !revoke); |
| 225 | if (portNextObjId == -1) { |
| 226 | // Warning log will come from getPortNextObjective method |
| 227 | return null; |
| 228 | } |
| 229 | |
| 230 | return DefaultForwardingObjective.builder() |
| 231 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 232 | .withSelector(sbuilder.build()) |
| 233 | .nextStep(portNextObjId) |
| 234 | .withPriority(100) |
| 235 | .fromApp(srManager.appId) |
| 236 | .makePermanent(); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Populate or revoke a bridging rule on given deviceId that matches given vlanId, |
| 241 | * and hostMAC connected to given port, and output to given port only when |
| 242 | * vlan information is valid. |
| 243 | * |
| 244 | * @param deviceId device ID that host attaches to |
| 245 | * @param portNum port number that host attaches to |
| 246 | * @param hostMac mac address of the host connected to the switch port |
| 247 | * @param vlanId Vlan ID configured on the switch port |
| 248 | * @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise |
| 249 | * @param install true to populate the objective, false to revoke |
| 250 | */ |
| 251 | // TODO Refactor. There are a lot of duplications between this method, populateBridging, |
| 252 | // revokeBridging and bridgingFwdObjBuilder. |
| 253 | void updateBridging(DeviceId deviceId, PortNumber portNum, MacAddress hostMac, |
| 254 | VlanId vlanId, boolean popVlan, boolean install) { |
| 255 | // Create host selector |
| 256 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 257 | sbuilder.matchEthDst(hostMac); |
| 258 | |
| 259 | // Create host meta |
| 260 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
| 261 | |
| 262 | sbuilder.matchVlanId(vlanId); |
| 263 | mbuilder.matchVlanId(vlanId); |
| 264 | |
| 265 | // Create host treatment |
| 266 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 267 | tbuilder.immediate().setOutput(portNum); |
| 268 | |
| 269 | if (popVlan) { |
| 270 | tbuilder.immediate().popVlan(); |
| 271 | } |
| 272 | |
| 273 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum, |
| 274 | tbuilder.build(), mbuilder.build(), install); |
| 275 | if (portNextObjId != -1) { |
| 276 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder() |
| 277 | .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 278 | .withSelector(sbuilder.build()) |
| 279 | .nextStep(portNextObjId) |
| 280 | .withPriority(100) |
| 281 | .fromApp(srManager.appId) |
| 282 | .makePermanent(); |
| 283 | |
| 284 | ObjectiveContext context = new DefaultObjectiveContext( |
| 285 | (objective) -> log.debug("Brigding rule for {}/{} {}", hostMac, vlanId, |
| 286 | install ? "populated" : "revoked"), |
| 287 | (objective, error) -> log.warn("Failed to {} bridging rule for {}/{}: {}", |
| 288 | install ? "populate" : "revoke", hostMac, vlanId, error)); |
| 289 | srManager.flowObjectiveService.forward(deviceId, install ? fob.add(context) : fob.remove(context)); |
| 290 | } else { |
| 291 | log.warn("Failed to retrieve next objective for {}/{}", hostMac, vlanId); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Populates IP rules for a route that has direct connection to the switch. |
| 297 | * This method should not be invoked directly without going through DefaultRoutingHandler. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 298 | * |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 299 | * @param deviceId device ID of the device that next hop attaches to |
| 300 | * @param prefix IP prefix of the route |
| 301 | * @param hostMac MAC address of the next hop |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 302 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 303 | * @param outPort port where the next hop attaches to |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 304 | */ |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 305 | void populateRoute(DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 306 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 307 | log.debug("Populate direct routing entry for route {} at {}:{}", |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 308 | prefix, deviceId, outPort); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 309 | ForwardingObjective.Builder fwdBuilder; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 310 | try { |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 311 | fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, |
| 312 | hostVlanId, outPort, false); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 313 | } catch (DeviceConfigNotFoundException e) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 314 | log.warn(e.getMessage() + " Aborting direct populateRoute"); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 317 | if (fwdBuilder == null) { |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 318 | log.warn("Aborting host routing table entry due " |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 319 | + "to error for dev:{} route:{}", deviceId, prefix); |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 320 | return; |
| 321 | } |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 322 | |
| 323 | int nextId = fwdBuilder.add().nextId(); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 324 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 325 | (objective) -> log.debug("Direct routing rule for route {} populated. nextId={}", |
| 326 | prefix, nextId), |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 327 | (objective, error) -> |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 328 | log.warn("Failed to populate direct routing rule for route {}: {}", |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 329 | prefix, error)); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 330 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context)); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 331 | rulePopulationCounter.incrementAndGet(); |
| 332 | } |
| 333 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 334 | /** |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 335 | * Removes IP rules for a route when the next hop is gone. |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 336 | * This method should not be invoked directly without going through DefaultRoutingHandler. |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 337 | * |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 338 | * @param deviceId device ID of the device that next hop attaches to |
| 339 | * @param prefix IP prefix of the route |
| 340 | * @param hostMac MAC address of the next hop |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 341 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 342 | * @param outPort port that next hop attaches to |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 343 | */ |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 344 | void revokeRoute(DeviceId deviceId, IpPrefix prefix, |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 345 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort) { |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 346 | log.debug("Revoke IP table entry for route {} at {}:{}", |
| 347 | prefix, deviceId, outPort); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 348 | ForwardingObjective.Builder fwdBuilder; |
| 349 | try { |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 350 | fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, |
| 351 | hostVlanId, outPort, true); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 352 | } catch (DeviceConfigNotFoundException e) { |
| 353 | log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); |
| 354 | return; |
| 355 | } |
Charles Chan | ea702b1 | 2016-11-30 11:55:05 -0800 | [diff] [blame] | 356 | if (fwdBuilder == null) { |
| 357 | log.warn("Aborting host routing table entries due " |
| 358 | + "to error for dev:{} route:{}", deviceId, prefix); |
| 359 | return; |
| 360 | } |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 361 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 362 | (objective) -> log.debug("IP rule for route {} revoked", prefix), |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 363 | (objective, error) -> |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 364 | log.warn("Failed to revoke IP rule for route {}: {}", prefix, error)); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 365 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context)); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 368 | /** |
Charles Chan | 18fa425 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 369 | * Returns a forwarding objective builder for routing rules. |
| 370 | * <p> |
| 371 | * The forwarding objective routes packets destined to a given prefix to |
| 372 | * given port on given device with given destination MAC. |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 373 | * |
| 374 | * @param deviceId device ID |
| 375 | * @param prefix prefix that need to be routed |
| 376 | * @param hostMac MAC address of the nexthop |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 377 | * @param hostVlanId Vlan ID of the nexthop |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 378 | * @param outPort port where the nexthop attaches to |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 379 | * @param revoke true if forwarding objective is meant to revoke forwarding rule |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 380 | * @return forwarding objective builder |
| 381 | * @throws DeviceConfigNotFoundException if given device is not configured |
| 382 | */ |
Charles Chan | 18fa425 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 383 | private ForwardingObjective.Builder routingFwdObjBuilder( |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 384 | DeviceId deviceId, IpPrefix prefix, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 385 | MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, |
| 386 | boolean revoke) |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 387 | throws DeviceConfigNotFoundException { |
| 388 | MacAddress deviceMac; |
| 389 | deviceMac = config.getDeviceMac(deviceId); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 390 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 391 | ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort); |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 392 | VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint); |
| 393 | Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint); |
| 394 | VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 395 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 396 | // Create route selector |
| 397 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix); |
| 398 | |
| 399 | // Create route treatment |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 400 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 401 | tbuilder.deferred() |
| 402 | .setEthDst(hostMac) |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 403 | .setEthSrc(deviceMac) |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 404 | .setOutput(outPort); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 405 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 406 | // Create route meta |
| 407 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
Charles Chan | 10b0fb7 | 2017-02-02 16:20:42 -0800 | [diff] [blame] | 408 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 409 | // Adjust the meta according to VLAN configuration |
| 410 | if (taggedVlans.contains(hostVlanId)) { |
| 411 | tbuilder.setVlanId(hostVlanId); |
| 412 | } else if (hostVlanId.equals(VlanId.NONE)) { |
| 413 | if (untaggedVlan != null) { |
| 414 | mbuilder.matchVlanId(untaggedVlan); |
| 415 | } else if (nativeVlan != null) { |
| 416 | mbuilder.matchVlanId(nativeVlan); |
| 417 | } else { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 418 | log.warn("Untagged nexthop {}/{} is not allowed on {} without untagged or native vlan", |
| 419 | hostMac, hostVlanId, connectPoint); |
| 420 | return null; |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 421 | } |
| 422 | } else { |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 423 | // Internally-assigned dummy VLAN id will be given as hostVlanId |
| 424 | // when destination is double-tagged. |
| 425 | VlanId vlanId = srManager.dummyVlanIdStore().get( |
| 426 | new DummyVlanIdStoreKey(connectPoint, prefix.address())); |
| 427 | if (vlanId != null && vlanId.equals(hostVlanId)) { |
| 428 | tbuilder.setVlanId(hostVlanId); |
| 429 | mbuilder.matchVlanId(VlanId.ANY); |
| 430 | } else { |
| 431 | log.warn("Tagged nexthop {}/{} is not allowed on {} without VLAN listed" |
| 432 | + " in tagged vlan", hostMac, hostVlanId, connectPoint); |
| 433 | return null; |
| 434 | } |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 435 | } |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 436 | // if the objective is to revoke an existing rule, and for some reason |
| 437 | // the next-objective does not exist, then a new one should not be created |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 438 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outPort, |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 439 | tbuilder.build(), mbuilder.build(), !revoke); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 440 | if (portNextObjId == -1) { |
| 441 | // Warning log will come from getPortNextObjective method |
| 442 | return null; |
| 443 | } |
| 444 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 445 | return DefaultForwardingObjective.builder() |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 446 | .withSelector(sbuilder.build()) |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 447 | .nextStep(portNextObjId) |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 448 | .fromApp(srManager.appId).makePermanent() |
Charles Chan | ddac7fd | 2016-10-27 14:19:48 -0700 | [diff] [blame] | 449 | .withPriority(getPriorityFromPrefix(prefix)) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 450 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 454 | * Populates IP flow rules for all the given prefixes reachable from the |
| 455 | * destination switch(es). |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 456 | * |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 457 | * @param targetSw switch where rules are to be programmed |
| 458 | * @param subnets subnets/prefixes being added |
| 459 | * @param destSw1 destination switch where the prefixes are reachable |
| 460 | * @param destSw2 paired destination switch if one exists for the subnets/prefixes. |
| 461 | * Should be null if there is no paired destination switch (by config) |
| 462 | * or if the given prefixes are reachable only via destSw1 |
| 463 | * @param nextHops a map containing a set of next-hops for each destination switch. |
| 464 | * If destSw2 is not null, then this map must contain an |
| 465 | * entry for destSw2 with its next-hops from the targetSw |
| 466 | * (although the next-hop set may be empty in certain scenarios). |
| 467 | * If destSw2 is null, there should not be an entry in this |
| 468 | * map for destSw2. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 469 | * @return true if all rules are set successfully, false otherwise |
| 470 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 471 | boolean populateIpRuleForSubnet(DeviceId targetSw, Set<IpPrefix> subnets, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 472 | DeviceId destSw1, DeviceId destSw2, Map<DeviceId, Set<DeviceId>> nextHops) { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 473 | for (IpPrefix subnet : subnets) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 474 | if (!populateIpRuleForRouter(targetSw, subnet, destSw1, destSw2, nextHops)) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | } |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 478 | return true; |
| 479 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 480 | |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 481 | /** |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 482 | * Revokes IP flow rules for the subnets from given device. |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 483 | * |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 484 | * @param targetSw target switch from which the subnets need to be removed |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 485 | * @param subnets subnet being removed |
| 486 | * @return true if all rules are removed successfully, false otherwise |
| 487 | */ |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 488 | boolean revokeIpRuleForSubnet(DeviceId targetSw, Set<IpPrefix> subnets) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 489 | for (IpPrefix subnet : subnets) { |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 490 | if (!revokeIpRuleForRouter(targetSw, subnet)) { |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 491 | return false; |
| 492 | } |
| 493 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
| 497 | /** |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 498 | * Populates IP flow rules for an IP prefix in the target device. The prefix |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 499 | * is reachable via destination device(s). |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 500 | * |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 501 | * @param targetSw target device ID to set the rules |
| 502 | * @param ipPrefix the IP prefix |
| 503 | * @param destSw1 destination switch where the prefixes are reachable |
| 504 | * @param destSw2 paired destination switch if one exists for the subnets/prefixes. |
| 505 | * Should be null if there is no paired destination switch (by config) |
| 506 | * or if the given prefixes are reachable only via destSw1 |
| 507 | * @param nextHops map of destination switches and their next-hops. |
| 508 | * Should only contain destination switches that are |
| 509 | * actually meant to be routed to. If destSw2 is null, there |
| 510 | * should not be an entry for destSw2 in this map. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 511 | * @return true if all rules are set successfully, false otherwise |
| 512 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 513 | private boolean populateIpRuleForRouter(DeviceId targetSw, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 514 | IpPrefix ipPrefix, DeviceId destSw1, |
| 515 | DeviceId destSw2, |
| 516 | Map<DeviceId, Set<DeviceId>> nextHops) { |
| 517 | int segmentId1, segmentId2 = -1; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 518 | try { |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 519 | if (ipPrefix.isIp4()) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 520 | segmentId1 = config.getIPv4SegmentId(destSw1); |
| 521 | if (destSw2 != null) { |
| 522 | segmentId2 = config.getIPv4SegmentId(destSw2); |
| 523 | } |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 524 | } else { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 525 | segmentId1 = config.getIPv6SegmentId(destSw1); |
| 526 | if (destSw2 != null) { |
| 527 | segmentId2 = config.getIPv6SegmentId(destSw2); |
| 528 | } |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 529 | } |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 530 | } catch (DeviceConfigNotFoundException e) { |
| 531 | log.warn(e.getMessage() + " Aborting populateIpRuleForRouter."); |
| 532 | return false; |
| 533 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 534 | |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 535 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 536 | TrafficSelector selector = sbuilder.build(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 537 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 538 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 539 | DestinationSet ds; |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 540 | TrafficTreatment treatment; |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 541 | DestinationSet.DestinationSetType dsType; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 542 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 543 | if (destSw2 == null) { |
| 544 | // single dst - create destination set based on next-hop |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 545 | // If the next hop is the same as the final destination, then MPLS |
| 546 | // label is not set. |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 547 | Set<DeviceId> nhd1 = nextHops.get(destSw1); |
| 548 | if (nhd1.size() == 1 && nhd1.iterator().next().equals(destSw1)) { |
| 549 | tbuilder.immediate().decNwTtl(); |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 550 | ds = DestinationSet.createTypePushNone(destSw1); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 551 | treatment = tbuilder.build(); |
| 552 | } else { |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 553 | ds = DestinationSet.createTypePushBos(segmentId1, destSw1); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 554 | treatment = null; |
| 555 | } |
| 556 | } else { |
| 557 | // dst pair - IP rules for dst-pairs are always from other edge nodes |
| 558 | // the destination set needs to have both destinations, even if there |
| 559 | // are no next hops to one of them |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 560 | ds = DestinationSet.createTypePushBos(segmentId1, destSw1, segmentId2, destSw2); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 561 | treatment = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 564 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 565 | // if needed by the switch pipeline. Since neighbor sets are always to |
| 566 | // other neighboring routers, there is no subnet assigned on those ports. |
| 567 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 568 | metabuilder.matchVlanId(srManager.getDefaultInternalVlan()); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 569 | DefaultGroupHandler grpHandler = srManager.getGroupHandler(targetSw); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 570 | if (grpHandler == null) { |
| 571 | log.warn("populateIPRuleForRouter: groupHandler for device {} " |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 572 | + "not found", targetSw); |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 573 | return false; |
| 574 | } |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 575 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 576 | int nextId = grpHandler.getNextObjectiveId(ds, nextHops, |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 577 | metabuilder.build(), false); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 578 | if (nextId <= 0) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 579 | log.warn("No next objective in {} for ds: {}", targetSw, ds); |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 580 | return false; |
| 581 | } |
| 582 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 583 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 584 | .builder() |
| 585 | .fromApp(srManager.appId) |
| 586 | .makePermanent() |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 587 | .nextStep(nextId) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 588 | .withSelector(selector) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 589 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 590 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 591 | if (treatment != null) { |
| 592 | fwdBuilder.withTreatment(treatment); |
| 593 | } |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 594 | log.debug("Installing IPv4 forwarding objective for router IP/subnet {} " |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 595 | + "in switch {} with nextId: {}", ipPrefix, targetSw, nextId); |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 596 | ObjectiveContext context = new DefaultObjectiveContext( |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 597 | (objective) -> log.debug("IP rule for router {} populated in dev:{}", |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 598 | ipPrefix, targetSw), |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 599 | (objective, error) -> |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 600 | log.warn("Failed to populate IP rule for router {}: {} in dev:{}", |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 601 | ipPrefix, error, targetSw)); |
| 602 | srManager.flowObjectiveService.forward(targetSw, fwdBuilder.add(context)); |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 603 | rulePopulationCounter.incrementAndGet(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 604 | |
| 605 | return true; |
| 606 | } |
| 607 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 608 | /** |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 609 | * Revokes IP flow rules for the router IP address from given device. |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 610 | * |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 611 | * @param targetSw target switch from which the ipPrefix need to be removed |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 612 | * @param ipPrefix the IP address of the destination router |
| 613 | * @return true if all rules are removed successfully, false otherwise |
| 614 | */ |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 615 | private boolean revokeIpRuleForRouter(DeviceId targetSw, IpPrefix ipPrefix) { |
Pier Ventre | 6b2c1b3 | 2016-12-09 17:26:04 -0800 | [diff] [blame] | 616 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 617 | TrafficSelector selector = sbuilder.build(); |
| 618 | TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build(); |
| 619 | |
| 620 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 621 | .builder() |
| 622 | .fromApp(srManager.appId) |
| 623 | .makePermanent() |
| 624 | .withSelector(selector) |
| 625 | .withTreatment(dummyTreatment) |
| 626 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
| 627 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 628 | |
Charles Chan | d66d671 | 2018-03-29 16:03:41 -0700 | [diff] [blame] | 629 | ObjectiveContext context = new DefaultObjectiveContext( |
| 630 | (objective) -> log.debug("IP rule for router {} revoked from {}", ipPrefix, targetSw), |
| 631 | (objective, error) -> log.warn("Failed to revoke IP rule for router {} from {}: {}", |
| 632 | ipPrefix, targetSw, error)); |
| 633 | srManager.flowObjectiveService.forward(targetSw, fwdBuilder.remove(context)); |
Charles Chan | c22cef3 | 2016-04-29 14:38:22 -0700 | [diff] [blame] | 634 | |
| 635 | return true; |
| 636 | } |
| 637 | |
| 638 | /** |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 639 | * Populates MPLS flow rules in the target device to point towards the |
| 640 | * destination device. |
| 641 | * |
| 642 | * @param targetSwId target device ID of the switch to set the rules |
| 643 | * @param destSwId destination switch device ID |
| 644 | * @param nextHops next hops switch ID list |
| 645 | * @param routerIp the router ip of the destination switch |
| 646 | * @return true if all rules are set successfully, false otherwise |
| 647 | */ |
| 648 | boolean populateMplsRule(DeviceId targetSwId, DeviceId destSwId, |
| 649 | Set<DeviceId> nextHops, IpAddress routerIp) { |
| 650 | int segmentId; |
| 651 | try { |
| 652 | if (routerIp.isIp4()) { |
| 653 | segmentId = config.getIPv4SegmentId(destSwId); |
| 654 | } else { |
| 655 | segmentId = config.getIPv6SegmentId(destSwId); |
| 656 | } |
| 657 | } catch (DeviceConfigNotFoundException e) { |
| 658 | log.warn(e.getMessage() + " Aborting populateMplsRule."); |
| 659 | return false; |
| 660 | } |
| 661 | |
| 662 | List<ForwardingObjective> fwdObjs = new ArrayList<>(); |
| 663 | Collection<ForwardingObjective> fwdObjsMpls; |
| 664 | // Generates the transit rules used by the standard "routing". |
| 665 | fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, segmentId, |
| 666 | routerIp, true); |
| 667 | if (fwdObjsMpls.isEmpty()) { |
| 668 | return false; |
| 669 | } |
| 670 | fwdObjs.addAll(fwdObjsMpls); |
| 671 | |
| 672 | // Generates the transit rules used by the MPLS Pwaas. |
| 673 | int pwSrLabel; |
| 674 | try { |
| 675 | pwSrLabel = config.getPWRoutingLabel(destSwId); |
| 676 | } catch (DeviceConfigNotFoundException e) { |
| 677 | log.warn(e.getMessage() |
| 678 | + " Aborting populateMplsRule. No label for PseudoWire traffic."); |
| 679 | return false; |
| 680 | } |
| 681 | fwdObjsMpls = handleMpls(targetSwId, destSwId, nextHops, pwSrLabel, |
| 682 | routerIp, false); |
| 683 | if (fwdObjsMpls.isEmpty()) { |
| 684 | return false; |
| 685 | } |
| 686 | fwdObjs.addAll(fwdObjsMpls); |
| 687 | |
| 688 | for (ForwardingObjective fwdObj : fwdObjs) { |
| 689 | log.debug("Sending MPLS fwd obj {} for SID {}-> next {} in sw: {}", |
| 690 | fwdObj.id(), segmentId, fwdObj.nextId(), targetSwId); |
| 691 | srManager.flowObjectiveService.forward(targetSwId, fwdObj); |
| 692 | rulePopulationCounter.incrementAndGet(); |
| 693 | } |
| 694 | |
| 695 | return true; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Differentiates between popping and swapping labels when building an MPLS |
| 700 | * forwarding objective. |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 701 | * |
| 702 | * @param targetSwId the target sw |
| 703 | * @param destSwId the destination sw |
| 704 | * @param nextHops the set of next hops |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 705 | * @param segmentId the segmentId to match representing the destination |
| 706 | * switch |
| 707 | * @param routerIp the router ip representing the destination switch |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 708 | * @return a collection of fwdobjective |
| 709 | */ |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 710 | private Collection<ForwardingObjective> handleMpls( |
| 711 | DeviceId targetSwId, |
| 712 | DeviceId destSwId, |
| 713 | Set<DeviceId> nextHops, |
| 714 | int segmentId, |
| 715 | IpAddress routerIp, |
| 716 | boolean isMplsBos) { |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 717 | |
| 718 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 719 | List<ForwardingObjective.Builder> fwdObjBuilders = Lists.newArrayList(); |
Pier Luigi | 0be3f0f | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 720 | // For the transport of Pwaas we can use two or three MPLS label |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 721 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
| 722 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId)); |
| 723 | sbuilder.matchMplsBos(isMplsBos); |
| 724 | TrafficSelector selector = sbuilder.build(); |
| 725 | |
| 726 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 727 | // if needed by the switch pipeline. Since mpls next-hops are always to |
| 728 | // other neighboring routers, there is no subnet assigned on those ports. |
| 729 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 730 | metabuilder.matchVlanId(srManager.getDefaultInternalVlan()); |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 731 | |
| 732 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
| 733 | // If the next hop is the destination router for the segment, do pop |
| 734 | log.debug("populateMplsRule: Installing MPLS forwarding objective for " |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 735 | + "label {} in switch {} with pop to next-hops {}", |
| 736 | segmentId, targetSwId, nextHops); |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 737 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 738 | getMplsForwardingObjective(targetSwId, |
| 739 | nextHops, |
| 740 | true, |
| 741 | isMplsBos, |
| 742 | metabuilder.build(), |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 743 | routerIp, |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 744 | segmentId, |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 745 | destSwId); |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 746 | // Error case, we cannot handle, exit. |
| 747 | if (fwdObjNoBosBuilder == null) { |
| 748 | return Collections.emptyList(); |
| 749 | } |
| 750 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 751 | |
| 752 | } else { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 753 | // next hop is not destination, irrespective of the number of next |
| 754 | // hops (1 or more) -- SR CONTINUE case (swap with self) |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 755 | log.debug("Installing MPLS forwarding objective for " |
| 756 | + "label {} in switch {} without pop to next-hops {}", |
| 757 | segmentId, targetSwId, nextHops); |
Saurav Das | 2cb3829 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 758 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 759 | getMplsForwardingObjective(targetSwId, |
| 760 | nextHops, |
| 761 | false, |
| 762 | isMplsBos, |
| 763 | metabuilder.build(), |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 764 | routerIp, |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 765 | segmentId, |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 766 | destSwId); |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 767 | // Error case, we cannot handle, exit. |
| 768 | if (fwdObjNoBosBuilder == null) { |
| 769 | return Collections.emptyList(); |
| 770 | } |
| 771 | fwdObjBuilders.add(fwdObjNoBosBuilder); |
| 772 | |
| 773 | } |
| 774 | |
| 775 | List<ForwardingObjective> fwdObjs = Lists.newArrayList(); |
| 776 | // We add the final property to the fwdObjs. |
| 777 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 778 | ((Builder) ((Builder) fwdObjBuilder |
| 779 | .fromApp(srManager.appId) |
| 780 | .makePermanent()) |
| 781 | .withSelector(selector) |
| 782 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)) |
| 783 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 784 | |
| 785 | ObjectiveContext context = new DefaultObjectiveContext( |
| 786 | (objective) -> |
| 787 | log.debug("MPLS rule {} for SID {} populated in dev:{} ", |
| 788 | objective.id(), segmentId, targetSwId), |
| 789 | (objective, error) -> |
| 790 | log.warn("Failed to populate MPLS rule {} for SID {}: {} in dev:{}", |
| 791 | objective.id(), segmentId, error, targetSwId)); |
| 792 | |
| 793 | ForwardingObjective fob = fwdObjBuilder.add(context); |
| 794 | fwdObjs.add(fob); |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | return fwdObjs; |
| 798 | } |
| 799 | |
| 800 | /** |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 801 | * Returns a Forwarding Objective builder for the MPLS rule that references |
| 802 | * the desired Next Objective. Creates a DestinationSet that allows the |
| 803 | * groupHandler to create or find the required next objective. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 804 | * |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 805 | * @param targetSw the target sw |
| 806 | * @param nextHops the set of next hops |
| 807 | * @param phpRequired true if penultimate-hop-popping is required |
| 808 | * @param isBos true if matched label is bottom-of-stack |
| 809 | * @param meta metadata for creating next objective |
| 810 | * @param routerIp the router ip representing the destination switch |
| 811 | * @param destSw the destination sw |
| 812 | * @return the mpls forwarding objective builder |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 813 | */ |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 814 | private ForwardingObjective.Builder getMplsForwardingObjective( |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 815 | DeviceId targetSw, |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 816 | Set<DeviceId> nextHops, |
| 817 | boolean phpRequired, |
| 818 | boolean isBos, |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 819 | TrafficSelector meta, |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 820 | IpAddress routerIp, |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 821 | int segmentId, |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 822 | DeviceId destSw) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 823 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 824 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 825 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 826 | |
| 827 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 828 | DestinationSet ds = null; |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 829 | DestinationSet.DestinationSetType dstType = null; |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 830 | boolean simple = false; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 831 | if (phpRequired) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 832 | // php case - pop should always be flow-action |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 833 | log.debug("getMplsForwardingObjective: php required"); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 834 | tbuilder.deferred().copyTtlIn(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 835 | if (isBos) { |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 836 | if (routerIp.isIp4()) { |
| 837 | tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType()); |
| 838 | } else { |
| 839 | tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType()); |
| 840 | } |
| 841 | tbuilder.decNwTtl(); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 842 | // standard case -> BoS == True; pop results in IP packet and forwarding |
| 843 | // is via an ECMP group |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 844 | ds = DestinationSet.createTypePopBos(destSw); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 845 | } else { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 846 | tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()) |
| 847 | .decMplsTtl(); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 848 | // double-label case -> BoS == False, pop results in MPLS packet |
| 849 | // depending on configuration we can ECMP this packet or choose one output |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 850 | ds = DestinationSet.createTypePopNotBos(destSw); |
| 851 | if (!srManager.getMplsEcmp()) { |
| 852 | simple = true; |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 853 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 854 | } |
| 855 | } else { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 856 | // swap with self case - SR CONTINUE |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 857 | log.debug("getMplsForwardingObjective: swap with self"); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 858 | tbuilder.deferred().decMplsTtl(); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 859 | // swap results in MPLS packet with same BoS bit regardless of bit value |
| 860 | // depending on configuration we can ECMP this packet or choose one output |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 861 | // differentiate here between swap with not bos or swap with bos |
| 862 | ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) : |
| 863 | DestinationSet.createTypeSwapNotBos(segmentId, destSw); |
| 864 | if (!srManager.getMplsEcmp()) { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 865 | simple = true; |
| 866 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 869 | fwdBuilder.withTreatment(tbuilder.build()); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 870 | log.debug("Trying to get a nextObjId for mpls rule on device:{} to ds:{}", |
| 871 | targetSw, ds); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 872 | DefaultGroupHandler gh = srManager.getGroupHandler(targetSw); |
| 873 | if (gh == null) { |
| 874 | log.warn("getNextObjectiveId query - groupHandler for device {} " |
| 875 | + "not found", targetSw); |
| 876 | return null; |
| 877 | } |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 878 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 879 | Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>(); |
| 880 | dstNextHops.put(destSw, nextHops); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 881 | int nextId = gh.getNextObjectiveId(ds, dstNextHops, meta, simple); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 882 | if (nextId <= 0) { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 883 | log.warn("No next objective in {} for ds: {}", targetSw, ds); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 884 | return null; |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 885 | } else { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 886 | log.debug("nextObjId found:{} for mpls rule on device:{} to ds:{}", |
| 887 | nextId, targetSw, ds); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 890 | fwdBuilder.nextStep(nextId); |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 891 | return fwdBuilder; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /** |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 895 | * Creates a filtering objective to permit all untagged packets with a |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 896 | * dstMac corresponding to the router's MAC address. For those pipelines |
| 897 | * that need to internally assign vlans to untagged packets, this method |
| 898 | * provides per-subnet vlan-ids as metadata. |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 899 | * <p> |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 900 | * Note that the vlan assignment and filter programming should only be done by |
| 901 | * the master for a switch. This method is typically called at deviceAdd and |
| 902 | * programs filters only for the enabled ports of the device. For port-updates, |
| 903 | * that enable/disable ports after device add, singlePortFilter methods should |
| 904 | * be called. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 905 | * |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 906 | * @param deviceId the switch dpid for the router |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 907 | * @return PortFilterInfo information about the processed ports |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 908 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 909 | PortFilterInfo populateVlanMacFilters(DeviceId deviceId) { |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 910 | log.debug("Installing per-port filtering objective for untagged " |
| 911 | + "packets in device {}", deviceId); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 912 | |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 913 | List<Port> devPorts = srManager.deviceService.getPorts(deviceId); |
Jon Hall | 31d8478 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 914 | if (devPorts == null || devPorts.isEmpty()) { |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 915 | log.warn("Device {} ports not available. Unable to add MacVlan filters", |
| 916 | deviceId); |
Saurav Das | d1872b0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 917 | return null; |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 918 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 919 | int disabledPorts = 0, errorPorts = 0, filteredPorts = 0; |
Saurav Das | 07c7460 | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 920 | for (Port port : devPorts) { |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 921 | if (!port.isEnabled()) { |
| 922 | disabledPorts++; |
| 923 | continue; |
| 924 | } |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 925 | if (processSinglePortFilters(deviceId, port.number(), true)) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 926 | filteredPorts++; |
| 927 | } else { |
| 928 | errorPorts++; |
Saurav Das | e0237a3 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 929 | } |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 930 | } |
Charles Chan | 077314e | 2017-06-22 14:27:17 -0700 | [diff] [blame] | 931 | log.debug("Filtering on dev:{}, disabledPorts:{}, errorPorts:{}, filteredPorts:{}", |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 932 | deviceId, disabledPorts, errorPorts, filteredPorts); |
Charles Chan | 9d2dd55 | 2018-06-19 20:56:33 -0700 | [diff] [blame] | 933 | return new PortFilterInfo(disabledPorts, errorPorts, filteredPorts); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /** |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 937 | * Creates or removes filtering objectives for a single port. Should only be |
| 938 | * called by the master for a switch. |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 939 | * |
| 940 | * @param deviceId device identifier |
| 941 | * @param portnum port identifier for port to be filtered |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 942 | * @param install true to install the filtering objective, false to remove |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 943 | * @return true if no errors occurred during the build of the filtering objective |
| 944 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 945 | boolean processSinglePortFilters(DeviceId deviceId, PortNumber portnum, boolean install) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 946 | ConnectPoint connectPoint = new ConnectPoint(deviceId, portnum); |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 947 | VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint); |
| 948 | Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint); |
| 949 | VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 950 | |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 951 | // Do not configure filter for edge ports where double-tagged hosts are connected. |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 952 | if (taggedVlans.size() != 0) { |
| 953 | // Filter for tagged vlans |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 954 | if (!srManager.interfaceService.getTaggedVlanId(connectPoint).stream().allMatch(taggedVlanId -> |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 955 | processSinglePortFiltersInternal(deviceId, portnum, false, taggedVlanId, install))) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 956 | return false; |
| 957 | } |
| 958 | if (nativeVlan != null) { |
| 959 | // Filter for native vlan |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 960 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, nativeVlan, install)) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 961 | return false; |
| 962 | } |
| 963 | } |
| 964 | } else if (untaggedVlan != null) { |
| 965 | // Filter for untagged vlan |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 966 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, untaggedVlan, install)) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 967 | return false; |
| 968 | } |
Jonghwan Hyun | 671a7ab | 2018-04-30 09:27:21 -0700 | [diff] [blame] | 969 | } else if (!hasIPConfiguration(connectPoint)) { |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 970 | // Filter for unconfigured upstream port, using INTERNAL_VLAN |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 971 | if (!processSinglePortFiltersInternal(deviceId, portnum, true, |
| 972 | srManager.getDefaultInternalVlan(), |
| 973 | install)) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 974 | return false; |
| 975 | } |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 976 | // Filter for receiveing pseudowire traffic |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 977 | if (!processSinglePortFiltersInternal(deviceId, portnum, false, |
| 978 | srManager.getPwTransportVlan(), |
| 979 | install)) { |
Andreas Pantelopoulos | b281ae2 | 2018-05-01 14:56:05 -0700 | [diff] [blame] | 980 | return false; |
| 981 | } |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 982 | } |
| 983 | return true; |
| 984 | } |
| 985 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 986 | /** |
| 987 | * Updates filtering objectives for a single port. Should only be called by |
| 988 | * the master for a switch |
| 989 | * @param deviceId device identifier |
| 990 | * @param portNum port identifier for port to be filtered |
| 991 | * @param pushVlan true to push vlan, false otherwise |
| 992 | * @param vlanId vlan identifier |
| 993 | * @param install true to install the filtering objective, false to remove |
| 994 | */ |
| 995 | void updateSinglePortFilters(DeviceId deviceId, PortNumber portNum, |
| 996 | boolean pushVlan, VlanId vlanId, boolean install) { |
| 997 | if (!processSinglePortFiltersInternal(deviceId, portNum, pushVlan, vlanId, install)) { |
| 998 | log.warn("Failed to update FilteringObjective for {}/{} with vlan {}", |
| 999 | deviceId, portNum, vlanId); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1003 | private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum, |
| 1004 | boolean pushVlan, VlanId vlanId, boolean install) { |
Daniel Ginsburg | 776789f | 2018-04-30 19:27:19 -0400 | [diff] [blame] | 1005 | boolean doTMAC = true; |
| 1006 | |
| 1007 | if (!pushVlan) { |
| 1008 | // Skip the tagged vlans belonging to an interface without an IP address |
| 1009 | Set<Interface> ifaces = srManager.interfaceService |
| 1010 | .getInterfacesByPort(new ConnectPoint(deviceId, portnum)) |
| 1011 | .stream() |
| 1012 | .filter(intf -> intf.vlanTagged().contains(vlanId) && intf.ipAddressesList().isEmpty()) |
| 1013 | .collect(Collectors.toSet()); |
| 1014 | if (!ifaces.isEmpty()) { |
| 1015 | log.debug("processSinglePortFiltersInternal: skipping TMAC for vlan {} at {}/{} - no IP", |
| 1016 | vlanId, deviceId, portnum); |
| 1017 | doTMAC = false; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId, doTMAC); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1022 | if (fob == null) { |
| 1023 | // error encountered during build |
| 1024 | return false; |
| 1025 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1026 | log.debug("{} filtering objectives for dev/port: {}/{}", |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1027 | install ? "Installing" : "Removing", deviceId, portnum); |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1028 | ObjectiveContext context = new DefaultObjectiveContext( |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1029 | (objective) -> log.debug("Filter for {}/{} {}", deviceId, portnum, |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1030 | install ? "installed" : "removed"), |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1031 | (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}", |
Saurav Das | 62ae679 | 2017-05-15 15:34:25 -0700 | [diff] [blame] | 1032 | install ? "install" : "remove", deviceId, portnum, error)); |
Charles Chan | 43be46b | 2017-02-26 22:59:35 -0800 | [diff] [blame] | 1033 | if (install) { |
| 1034 | srManager.flowObjectiveService.filter(deviceId, fob.add(context)); |
| 1035 | } else { |
| 1036 | srManager.flowObjectiveService.filter(deviceId, fob.remove(context)); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1037 | } |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1038 | return true; |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1041 | private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, PortNumber portnum, |
Daniel Ginsburg | 776789f | 2018-04-30 19:27:19 -0400 | [diff] [blame] | 1042 | boolean pushVlan, VlanId vlanId, boolean doTMAC) { |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1043 | MacAddress deviceMac; |
| 1044 | try { |
| 1045 | deviceMac = config.getDeviceMac(deviceId); |
| 1046 | } catch (DeviceConfigNotFoundException e) { |
| 1047 | log.warn(e.getMessage() + " Processing SinglePortFilters aborted"); |
| 1048 | return null; |
| 1049 | } |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1050 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
Daniel Ginsburg | 776789f | 2018-04-30 19:27:19 -0400 | [diff] [blame] | 1051 | |
| 1052 | if (doTMAC) { |
| 1053 | fob.withKey(Criteria.matchInPort(portnum)) |
| 1054 | .addCondition(Criteria.matchEthDst(deviceMac)) |
| 1055 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
| 1056 | } else { |
| 1057 | fob.withKey(Criteria.matchInPort(portnum)) |
| 1058 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
| 1059 | } |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1060 | |
Charles Chan | 17ca220 | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 1061 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1062 | |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1063 | if (pushVlan) { |
| 1064 | fob.addCondition(Criteria.matchVlanId(VlanId.NONE)); |
Charles Chan | 17ca220 | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 1065 | tBuilder.pushVlan().setVlanId(vlanId); |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1066 | } else { |
| 1067 | fob.addCondition(Criteria.matchVlanId(vlanId)); |
| 1068 | } |
| 1069 | |
Charles Chan | 17ca220 | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 1070 | // NOTE: Some switch hardware share the same filtering flow among different ports. |
| 1071 | // We use this metadata to let the driver know that there is no more enabled port |
| 1072 | // within the same VLAN on this device. |
Charles Chan | f17f66b | 2018-02-26 21:33:25 -0800 | [diff] [blame] | 1073 | if (noMoreEnabledPort(deviceId, vlanId)) { |
Charles Chan | 17ca220 | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 1074 | tBuilder.wipeDeferred(); |
| 1075 | } |
| 1076 | |
| 1077 | fob.withMeta(tBuilder.build()); |
| 1078 | |
Saurav Das | f933219 | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1079 | fob.permit().fromApp(srManager.appId); |
| 1080 | return fob; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | /** |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1084 | * Creates or removes filtering objectives for a double-tagged host on a port. |
| 1085 | * |
| 1086 | * @param deviceId device identifier |
| 1087 | * @param portNum port identifier for port to be filtered |
| 1088 | * @param outerVlan outer VLAN ID |
| 1089 | * @param innerVlan inner VLAN ID |
| 1090 | * @param install true to install the filtering objective, false to remove |
| 1091 | */ |
| 1092 | void processDoubleTaggedFilter(DeviceId deviceId, PortNumber portNum, VlanId outerVlan, |
| 1093 | VlanId innerVlan, boolean install) { |
| 1094 | FilteringObjective.Builder fob = buildDoubleTaggedFilteringObj(deviceId, portNum, outerVlan, innerVlan); |
| 1095 | if (fob == null) { |
| 1096 | // error encountered during build |
| 1097 | return; |
| 1098 | } |
| 1099 | log.debug("{} double-tagged filtering objectives for dev/port: {}/{}", |
| 1100 | install ? "Installing" : "Removing", deviceId, portNum); |
| 1101 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1102 | (objective) -> log.debug("Filter for {}/{} {}", deviceId, portNum, |
| 1103 | install ? "installed" : "removed"), |
| 1104 | (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}", |
| 1105 | install ? "install" : "remove", deviceId, portNum, error)); |
| 1106 | if (install) { |
| 1107 | srManager.flowObjectiveService.filter(deviceId, fob.add(context)); |
| 1108 | } else { |
| 1109 | srManager.flowObjectiveService.filter(deviceId, fob.remove(context)); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | private FilteringObjective.Builder buildDoubleTaggedFilteringObj(DeviceId deviceId, PortNumber portNum, |
| 1114 | VlanId outerVlan, VlanId innerVlan) { |
| 1115 | MacAddress deviceMac; |
| 1116 | try { |
| 1117 | deviceMac = config.getDeviceMac(deviceId); |
| 1118 | } catch (DeviceConfigNotFoundException e) { |
| 1119 | log.warn(e.getMessage() + " Processing DoubleTaggedFilters aborted"); |
| 1120 | return null; |
| 1121 | } |
| 1122 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 1123 | // Outer vlan id match should be appeared before inner vlan id match. |
| 1124 | fob.withKey(Criteria.matchInPort(portNum)) |
| 1125 | .addCondition(Criteria.matchEthDst(deviceMac)) |
| 1126 | .addCondition(Criteria.matchVlanId(outerVlan)) |
| 1127 | .addCondition(Criteria.matchVlanId(innerVlan)) |
| 1128 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
| 1129 | |
| 1130 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1131 | // Pop outer vlan |
| 1132 | tBuilder.popVlan(); |
| 1133 | |
| 1134 | // NOTE: Some switch hardware share the same filtering flow among different ports. |
| 1135 | // We use this metadata to let the driver know that there is no more enabled port |
| 1136 | // within the same VLAN on this device. |
| 1137 | if (noMoreEnabledPort(deviceId, outerVlan)) { |
| 1138 | tBuilder.wipeDeferred(); |
| 1139 | } |
| 1140 | |
| 1141 | fob.withMeta(tBuilder.build()); |
| 1142 | |
| 1143 | fob.permit().fromApp(srManager.appId); |
| 1144 | return fob; |
| 1145 | } |
| 1146 | |
| 1147 | /** |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1148 | * Creates a forwarding objective to punt all IP packets, destined to the |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1149 | * router's port IP addresses, to the controller. Note that the input |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1150 | * port should not be matched on, as these packets can come from any input. |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1151 | * Furthermore, these are applied only by the master instance. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1152 | * |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1153 | * @param deviceId the switch dpid for the router |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1154 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1155 | void populateIpPunts(DeviceId deviceId) { |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1156 | Ip4Address routerIpv4, pairRouterIpv4 = null; |
Charles Chan | ef8d12e | 2017-12-05 21:07:38 -0800 | [diff] [blame] | 1157 | Ip6Address routerIpv6, routerLinkLocalIpv6, pairRouterIpv6 = null; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1158 | try { |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1159 | routerIpv4 = config.getRouterIpv4(deviceId); |
| 1160 | routerIpv6 = config.getRouterIpv6(deviceId); |
Charles Chan | ef8d12e | 2017-12-05 21:07:38 -0800 | [diff] [blame] | 1161 | routerLinkLocalIpv6 = Ip6Address.valueOf( |
| 1162 | IPv6.getLinkLocalAddress(config.getDeviceMac(deviceId).toBytes())); |
| 1163 | |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1164 | if (config.isPairedEdge(deviceId)) { |
| 1165 | pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId)); |
| 1166 | pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId)); |
| 1167 | } |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1168 | } catch (DeviceConfigNotFoundException e) { |
Charles Chan | 18fa425 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1169 | log.warn(e.getMessage() + " Aborting populateIpPunts."); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 1170 | return; |
| 1171 | } |
| 1172 | |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 1173 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 1174 | log.debug("Not installing port-IP punts - not the master for dev:{} ", |
| 1175 | deviceId); |
| 1176 | return; |
| 1177 | } |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1178 | Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId)); |
| 1179 | allIps.add(routerIpv4); |
| 1180 | if (routerIpv6 != null) { |
| 1181 | allIps.add(routerIpv6); |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1182 | allIps.add(routerLinkLocalIpv6); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1183 | } |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1184 | if (pairRouterIpv4 != null) { |
| 1185 | allIps.add(pairRouterIpv4); |
| 1186 | } |
| 1187 | if (pairRouterIpv6 != null) { |
| 1188 | allIps.add(pairRouterIpv6); |
| 1189 | } |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1190 | for (IpAddress ipaddr : allIps) { |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1191 | populateSingleIpPunts(deviceId, ipaddr); |
| 1192 | } |
| 1193 | } |
Charles Chan | 2d0bbcd | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 1194 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1195 | /** |
| 1196 | * Creates a forwarding objective to punt all IP packets, destined to the |
| 1197 | * specified IP address, which should be router's port IP address. |
| 1198 | * |
| 1199 | * @param deviceId the switch dpid for the router |
| 1200 | * @param ipAddress the IP address of the router's port |
| 1201 | */ |
| 1202 | void populateSingleIpPunts(DeviceId deviceId, IpAddress ipAddress) { |
| 1203 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipAddress); |
| 1204 | Optional<DeviceId> optDeviceId = Optional.of(deviceId); |
| 1205 | |
| 1206 | srManager.packetService.requestPackets(sbuilder.build(), |
| 1207 | PacketPriority.CONTROL, srManager.appId, optDeviceId); |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Removes a forwarding objective to punt all IP packets, destined to the |
| 1212 | * specified IP address, which should be router's port IP address. |
| 1213 | * |
| 1214 | * @param deviceId the switch dpid for the router |
| 1215 | * @param ipAddress the IP address of the router's port |
| 1216 | */ |
| 1217 | void revokeSingleIpPunts(DeviceId deviceId, IpAddress ipAddress) { |
| 1218 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpAddress(ipAddress); |
| 1219 | Optional<DeviceId> optDeviceId = Optional.of(deviceId); |
| 1220 | |
| 1221 | try { |
| 1222 | if (!ipAddress.equals(config.getRouterIpv4(deviceId)) && |
| 1223 | !ipAddress.equals(config.getRouterIpv6(deviceId))) { |
| 1224 | srManager.packetService.cancelPackets(sbuilder.build(), |
| 1225 | PacketPriority.CONTROL, srManager.appId, optDeviceId); |
| 1226 | } |
| 1227 | } catch (DeviceConfigNotFoundException e) { |
| 1228 | log.warn(e.getMessage() + " Aborting revokeSingleIpPunts"); |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1229 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1232 | /** |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1233 | * Method to build IPv4 or IPv6 selector. |
| 1234 | * |
| 1235 | * @param addressToMatch the address to match |
| 1236 | */ |
| 1237 | private TrafficSelector.Builder buildIpSelectorFromIpAddress(IpAddress addressToMatch) { |
| 1238 | return buildIpSelectorFromIpPrefix(addressToMatch.toIpPrefix()); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Method to build IPv4 or IPv6 selector. |
| 1243 | * |
| 1244 | * @param prefixToMatch the prefix to match |
| 1245 | */ |
| 1246 | private TrafficSelector.Builder buildIpSelectorFromIpPrefix(IpPrefix prefixToMatch) { |
| 1247 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1248 | // If the prefix is IPv4 |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1249 | if (prefixToMatch.isIp4()) { |
| 1250 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 1251 | selectorBuilder.matchIPDst(prefixToMatch.getIp4Prefix()); |
| 1252 | return selectorBuilder; |
| 1253 | } |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1254 | // If the prefix is IPv6 |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1255 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); |
| 1256 | selectorBuilder.matchIPv6Dst(prefixToMatch.getIp6Prefix()); |
| 1257 | return selectorBuilder; |
| 1258 | } |
| 1259 | |
| 1260 | /** |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1261 | * Creates forwarding objectives to punt ARP and NDP packets, to the controller. |
| 1262 | * Furthermore, these are applied only by the master instance. Deferred actions |
| 1263 | * are not cleared such that packets can be flooded in the cross connect use case |
| 1264 | * |
| 1265 | * @param deviceId the switch dpid for the router |
| 1266 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1267 | void populateArpNdpPunts(DeviceId deviceId) { |
Pier Ventre | 229fd0b | 2016-10-31 16:49:19 -0700 | [diff] [blame] | 1268 | // We are not the master just skip. |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1269 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 1270 | log.debug("Not installing ARP/NDP punts - not the master for dev:{} ", |
| 1271 | deviceId); |
| 1272 | return; |
| 1273 | } |
| 1274 | |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1275 | ForwardingObjective fwdObj; |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1276 | // We punt all ARP packets towards the controller. |
Charles Chan | ef8d12e | 2017-12-05 21:07:38 -0800 | [diff] [blame] | 1277 | fwdObj = arpFwdObjective(null, true, ARP_NDP_PRIORITY) |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1278 | .add(new ObjectiveContext() { |
| 1279 | @Override |
| 1280 | public void onError(Objective objective, ObjectiveError error) { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1281 | log.warn("Failed to install forwarding objective to punt ARP to {}: {}", |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1282 | deviceId, error); |
| 1283 | } |
| 1284 | }); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1285 | srManager.flowObjectiveService.forward(deviceId, fwdObj); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1286 | |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1287 | if (isIpv6Configured(deviceId)) { |
| 1288 | // We punt all NDP packets towards the controller. |
| 1289 | ndpFwdObjective(null, true, ARP_NDP_PRIORITY).forEach(builder -> { |
| 1290 | ForwardingObjective obj = builder.add(new ObjectiveContext() { |
| 1291 | @Override |
| 1292 | public void onError(Objective objective, ObjectiveError error) { |
| 1293 | log.warn("Failed to install forwarding objective to punt NDP to {}: {}", |
| 1294 | deviceId, error); |
| 1295 | } |
| 1296 | }); |
| 1297 | srManager.flowObjectiveService.forward(deviceId, obj); |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1298 | }); |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1299 | } |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1300 | |
Saurav Das | ec683dc | 2018-04-27 18:42:30 -0700 | [diff] [blame] | 1301 | srManager.getPairLocalPort(deviceId).ifPresent(port -> { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1302 | ForwardingObjective pairFwdObj; |
| 1303 | // Do not punt ARP packets from pair port |
| 1304 | pairFwdObj = arpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1) |
| 1305 | .add(new ObjectiveContext() { |
| 1306 | @Override |
| 1307 | public void onError(Objective objective, ObjectiveError error) { |
| 1308 | log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", |
| 1309 | deviceId, error); |
| 1310 | } |
| 1311 | }); |
| 1312 | srManager.flowObjectiveService.forward(deviceId, pairFwdObj); |
| 1313 | |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1314 | if (isIpv6Configured(deviceId)) { |
| 1315 | // Do not punt NDP packets from pair port |
| 1316 | ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).forEach(builder -> { |
| 1317 | ForwardingObjective obj = builder.add(new ObjectiveContext() { |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1318 | @Override |
| 1319 | public void onError(Objective objective, ObjectiveError error) { |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1320 | log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1321 | deviceId, error); |
| 1322 | } |
| 1323 | }); |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1324 | srManager.flowObjectiveService.forward(deviceId, obj); |
| 1325 | }); |
| 1326 | |
| 1327 | // Do not forward DAD packets from pair port |
| 1328 | pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2) |
| 1329 | .add(new ObjectiveContext() { |
| 1330 | @Override |
| 1331 | public void onError(Objective objective, ObjectiveError error) { |
| 1332 | log.warn("Failed to install forwarding objective to drop DAD to {}: {}", |
| 1333 | deviceId, error); |
| 1334 | } |
| 1335 | }); |
| 1336 | srManager.flowObjectiveService.forward(deviceId, pairFwdObj); |
| 1337 | } |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1338 | }); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1341 | private ForwardingObjective.Builder fwdObjBuilder(TrafficSelector selector, |
| 1342 | TrafficTreatment treatment, int priority) { |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1343 | return DefaultForwardingObjective.builder() |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1344 | .withPriority(priority) |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1345 | .withSelector(selector) |
| 1346 | .fromApp(srManager.appId) |
| 1347 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1348 | .withTreatment(treatment) |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1349 | .makePermanent(); |
| 1350 | } |
| 1351 | |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1352 | private ForwardingObjective.Builder arpFwdObjective(PortNumber port, boolean punt, int priority) { |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1353 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 1354 | sBuilder.matchEthType(TYPE_ARP); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1355 | if (port != null) { |
| 1356 | sBuilder.matchInPort(port); |
| 1357 | } |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1358 | |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1359 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1360 | if (punt) { |
| 1361 | tBuilder.punt(); |
| 1362 | } |
| 1363 | return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1366 | private Set<ForwardingObjective.Builder> ndpFwdObjective(PortNumber port, boolean punt, int priority) { |
| 1367 | Set<ForwardingObjective.Builder> result = Sets.newHashSet(); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1368 | |
Charles Chan | 051490d | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1369 | Lists.newArrayList(NEIGHBOR_SOLICITATION, NEIGHBOR_ADVERTISEMENT, ROUTER_SOLICITATION, ROUTER_ADVERTISEMENT) |
| 1370 | .forEach(type -> { |
| 1371 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 1372 | sBuilder.matchEthType(TYPE_IPV6) |
| 1373 | .matchIPProtocol(PROTOCOL_ICMP6) |
| 1374 | .matchIcmpv6Type(type); |
| 1375 | if (port != null) { |
| 1376 | sBuilder.matchInPort(port); |
| 1377 | } |
| 1378 | |
| 1379 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1380 | if (punt) { |
| 1381 | tBuilder.punt(); |
| 1382 | } |
| 1383 | |
| 1384 | result.add(fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority)); |
| 1385 | }); |
| 1386 | |
| 1387 | return result; |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | private ForwardingObjective.Builder dad6FwdObjective(PortNumber port, int priority) { |
| 1391 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 1392 | sBuilder.matchEthType(TYPE_IPV6) |
Charles Chan | e6bda75 | 2017-08-07 12:39:03 -0700 | [diff] [blame] | 1393 | .matchIPv6Src(Ip6Address.ZERO.toIpPrefix()); |
| 1394 | // TODO CORD-1672 Fix this when OFDPA can distinguish ::/0 and ::/128 correctly |
| 1395 | // .matchIPProtocol(PROTOCOL_ICMP6) |
| 1396 | // .matchIcmpv6Type(NEIGHBOR_SOLICITATION); |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1397 | if (port != null) { |
| 1398 | sBuilder.matchInPort(port); |
| 1399 | } |
| 1400 | |
| 1401 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1402 | tBuilder.wipeDeferred(); |
| 1403 | return fwdObjBuilder(sBuilder.build(), tBuilder.build(), priority); |
Pier Luigi | b9632ba | 2017-01-12 18:14:58 -0800 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** |
Charles Chan | 155ec44 | 2018-09-16 14:30:19 -0700 | [diff] [blame] | 1407 | * Block given prefix in routing table. |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1408 | * |
Andrea Campanella | 60ce222 | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 1409 | * @param address the address to block |
| 1410 | * @param deviceId switch ID to set the rules |
| 1411 | */ |
| 1412 | void populateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address) { |
| 1413 | updateDefaultRouteBlackhole(deviceId, address, true); |
| 1414 | } |
| 1415 | |
| 1416 | /** |
Charles Chan | 155ec44 | 2018-09-16 14:30:19 -0700 | [diff] [blame] | 1417 | * Unblock given prefix in routing table. |
Andrea Campanella | 60ce222 | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 1418 | * |
| 1419 | * @param address the address to block |
| 1420 | * @param deviceId switch ID to set the rules |
| 1421 | */ |
| 1422 | void removeDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address) { |
| 1423 | updateDefaultRouteBlackhole(deviceId, address, false); |
| 1424 | } |
| 1425 | |
| 1426 | private void updateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address, boolean install) { |
| 1427 | try { |
| 1428 | if (srManager.deviceConfiguration.isEdgeDevice(deviceId)) { |
| 1429 | |
| 1430 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1431 | if (address.isIp4()) { |
| 1432 | sbuilder.matchIPDst(address); |
| 1433 | sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort()); |
| 1434 | } else { |
| 1435 | sbuilder.matchIPv6Dst(address); |
| 1436 | sbuilder.matchEthType(EthType.EtherType.IPV6.ethType().toShort()); |
| 1437 | } |
| 1438 | |
| 1439 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
Andrea Campanella | 60ce222 | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 1440 | tBuilder.wipeDeferred(); |
| 1441 | |
| 1442 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 1443 | fob.withFlag(Flag.SPECIFIC) |
| 1444 | .withSelector(sbuilder.build()) |
| 1445 | .withTreatment(tBuilder.build()) |
| 1446 | .withPriority(getPriorityFromPrefix(address)) |
| 1447 | .fromApp(srManager.appId) |
| 1448 | .makePermanent(); |
| 1449 | |
| 1450 | log.debug("{} blackhole forwarding objectives for dev: {}", |
| 1451 | install ? "Installing" : "Removing", deviceId); |
| 1452 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1453 | (objective) -> log.debug("Forward for {} {}", deviceId, |
| 1454 | install ? "installed" : "removed"), |
| 1455 | (objective, error) -> log.warn("Failed to {} forward for {}: {}", |
| 1456 | install ? "install" : "remove", deviceId, error)); |
| 1457 | if (install) { |
| 1458 | srManager.flowObjectiveService.forward(deviceId, fob.add(context)); |
| 1459 | } else { |
| 1460 | srManager.flowObjectiveService.forward(deviceId, fob.remove(context)); |
| 1461 | } |
| 1462 | } |
| 1463 | } catch (DeviceConfigNotFoundException e) { |
| 1464 | log.info("Not populating blackhole for un-configured device {}", deviceId); |
| 1465 | } |
| 1466 | |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * Populates a forwarding objective to send packets that miss other high |
| 1471 | * priority Bridging Table entries to a group that contains all ports of |
| 1472 | * its subnet. |
| 1473 | * |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1474 | * @param deviceId switch ID to set the rules |
| 1475 | */ |
Charles Chan | 3ed34d8 | 2017-06-22 18:03:14 -0700 | [diff] [blame] | 1476 | void populateSubnetBroadcastRule(DeviceId deviceId) { |
Charles Chan | 90772a7 | 2017-02-08 15:52:08 -0800 | [diff] [blame] | 1477 | srManager.getVlanPortMap(deviceId).asMap().forEach((vlanId, ports) -> { |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1478 | updateSubnetBroadcastRule(deviceId, vlanId, true); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 1479 | }); |
| 1480 | } |
| 1481 | |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1482 | /** |
| 1483 | * Creates or removes a forwarding objective to broadcast packets to its subnet. |
| 1484 | * @param deviceId switch ID to set the rule |
| 1485 | * @param vlanId vlan ID to specify the subnet |
| 1486 | * @param install true to install the rule, false to revoke the rule |
| 1487 | */ |
| 1488 | void updateSubnetBroadcastRule(DeviceId deviceId, VlanId vlanId, boolean install) { |
| 1489 | int nextId = srManager.getVlanNextObjectiveId(deviceId, vlanId); |
| 1490 | |
| 1491 | if (nextId < 0) { |
| 1492 | log.error("Cannot install vlan {} broadcast rule in dev:{} due" |
| 1493 | + " to vlanId:{} or nextId:{}", vlanId, deviceId, vlanId, nextId); |
| 1494 | return; |
| 1495 | } |
| 1496 | |
| 1497 | // Driver should treat objective with MacAddress.NONE as the |
| 1498 | // subnet broadcast rule |
| 1499 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1500 | sbuilder.matchVlanId(vlanId); |
| 1501 | sbuilder.matchEthDst(MacAddress.NONE); |
| 1502 | |
| 1503 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 1504 | fob.withFlag(Flag.SPECIFIC) |
| 1505 | .withSelector(sbuilder.build()) |
| 1506 | .nextStep(nextId) |
| 1507 | .withPriority(SegmentRoutingService.FLOOD_PRIORITY) |
| 1508 | .fromApp(srManager.appId) |
| 1509 | .makePermanent(); |
| 1510 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1511 | (objective) -> log.debug("Vlan broadcast rule for {} populated", vlanId), |
| 1512 | (objective, error) -> |
| 1513 | log.warn("Failed to populate vlan broadcast rule for {}: {}", vlanId, error)); |
| 1514 | |
| 1515 | if (install) { |
| 1516 | srManager.flowObjectiveService.forward(deviceId, fob.add(context)); |
| 1517 | } else { |
| 1518 | srManager.flowObjectiveService.forward(deviceId, fob.remove(context)); |
| 1519 | } |
| 1520 | } |
| 1521 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1522 | private int getPriorityFromPrefix(IpPrefix prefix) { |
| 1523 | return (prefix.isIp4()) ? |
| 1524 | 2000 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY : |
| 1525 | 500 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY; |
Srikanth Vavilapalli | 8c83f1d | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 1526 | } |
Jonghwan Hyun | e5ef762 | 2017-08-25 17:48:36 -0700 | [diff] [blame] | 1527 | |
| 1528 | /** |
| 1529 | * Update Forwarding objective for each host and IP address connected to given port. |
| 1530 | * And create corresponding Simple Next objective if it does not exist. |
| 1531 | * Applied only when populating Forwarding objective |
| 1532 | * @param deviceId switch ID to set the rule |
| 1533 | * @param portNumber port number |
| 1534 | * @param prefix IP prefix of the route |
| 1535 | * @param hostMac MAC address of the next hop |
| 1536 | * @param vlanId Vlan ID of the port |
| 1537 | * @param popVlan true to pop vlan tag in TrafficTreatment |
| 1538 | * @param install true to populate the forwarding objective, false to revoke |
| 1539 | */ |
| 1540 | void updateFwdObj(DeviceId deviceId, PortNumber portNumber, IpPrefix prefix, MacAddress hostMac, |
| 1541 | VlanId vlanId, boolean popVlan, boolean install) { |
| 1542 | ForwardingObjective.Builder fob; |
| 1543 | TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix); |
| 1544 | MacAddress deviceMac; |
| 1545 | try { |
| 1546 | deviceMac = config.getDeviceMac(deviceId); |
| 1547 | } catch (DeviceConfigNotFoundException e) { |
| 1548 | log.warn(e.getMessage() + " Aborting updateFwdObj."); |
| 1549 | return; |
| 1550 | } |
| 1551 | |
| 1552 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 1553 | tbuilder.deferred() |
| 1554 | .setEthDst(hostMac) |
| 1555 | .setEthSrc(deviceMac) |
| 1556 | .setOutput(portNumber); |
| 1557 | |
| 1558 | TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder(); |
| 1559 | |
| 1560 | if (!popVlan) { |
| 1561 | tbuilder.setVlanId(vlanId); |
| 1562 | } else { |
| 1563 | mbuilder.matchVlanId(vlanId); |
| 1564 | } |
| 1565 | |
| 1566 | // if the objective is to revoke an existing rule, and for some reason |
| 1567 | // the next-objective does not exist, then a new one should not be created |
| 1568 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNumber, |
| 1569 | tbuilder.build(), mbuilder.build(), install); |
| 1570 | if (portNextObjId == -1) { |
| 1571 | // Warning log will come from getPortNextObjective method |
| 1572 | return; |
| 1573 | } |
| 1574 | |
| 1575 | fob = DefaultForwardingObjective.builder().withSelector(sbuilder.build()) |
| 1576 | .nextStep(portNextObjId).fromApp(srManager.appId).makePermanent() |
| 1577 | .withPriority(getPriorityFromPrefix(prefix)).withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 1578 | |
| 1579 | ObjectiveContext context = new DefaultObjectiveContext( |
| 1580 | (objective) -> log.debug("IP rule for route {} {}", prefix, install ? "installed" : "revoked"), |
| 1581 | (objective, error) -> |
| 1582 | log.warn("Failed to {} IP rule for route {}: {}", |
| 1583 | install ? "install" : "revoke", prefix, error)); |
| 1584 | srManager.flowObjectiveService.forward(deviceId, install ? fob.add(context) : fob.remove(context)); |
| 1585 | |
| 1586 | if (!install) { |
| 1587 | DefaultGroupHandler grpHandler = srManager.getGroupHandler(deviceId); |
| 1588 | if (grpHandler == null) { |
| 1589 | log.warn("updateFwdObj: groupHandler for device {} not found", deviceId); |
| 1590 | } else { |
| 1591 | // Remove L3UG for the given port and host |
| 1592 | grpHandler.removeGroupFromPort(portNumber, tbuilder.build(), mbuilder.build()); |
| 1593 | } |
| 1594 | } |
| 1595 | } |
Charles Chan | f17f66b | 2018-02-26 21:33:25 -0800 | [diff] [blame] | 1596 | |
| 1597 | /** |
| 1598 | * Checks if there is other enabled port within the given VLAN on the given device. |
| 1599 | * |
| 1600 | * @param deviceId device ID |
| 1601 | * @param vlanId VLAN ID |
| 1602 | * @return true if there is no more port enabled within the given VLAN on the given device |
| 1603 | */ |
| 1604 | boolean noMoreEnabledPort(DeviceId deviceId, VlanId vlanId) { |
| 1605 | Set<ConnectPoint> enabledPorts = srManager.deviceService.getPorts(deviceId).stream() |
| 1606 | .filter(Port::isEnabled) |
| 1607 | .map(port -> new ConnectPoint(port.element().id(), port.number())) |
| 1608 | .collect(Collectors.toSet()); |
| 1609 | |
| 1610 | return enabledPorts.stream().noneMatch(cp -> |
| 1611 | // Given vlanId is included in the vlan-tagged configuration |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1612 | srManager.interfaceService.getTaggedVlanId(cp).contains(vlanId) || |
Charles Chan | f17f66b | 2018-02-26 21:33:25 -0800 | [diff] [blame] | 1613 | // Given vlanId is INTERNAL_VLAN and the interface is not configured |
Charles Chan | 098ca20 | 2018-05-01 11:50:20 -0700 | [diff] [blame] | 1614 | (srManager.interfaceService.getTaggedVlanId(cp).isEmpty() && srManager.getInternalVlanId(cp) == null && |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 1615 | vlanId.equals(srManager.getDefaultInternalVlan())) || |
Charles Chan | f17f66b | 2018-02-26 21:33:25 -0800 | [diff] [blame] | 1616 | // interface is configured and either vlan-untagged or vlan-native matches given vlanId |
| 1617 | (srManager.getInternalVlanId(cp) != null && srManager.getInternalVlanId(cp).equals(vlanId)) |
| 1618 | ); |
| 1619 | } |
Jonghwan Hyun | 9aaa34f | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 1620 | |
| 1621 | /** |
| 1622 | * Returns a forwarding objective builder for egress forwarding rules. |
| 1623 | * <p> |
| 1624 | * The forwarding objective installs flow rules to egress pipeline to push |
| 1625 | * two vlan headers with given inner, outer vlan ids and outer tpid. |
| 1626 | * |
| 1627 | * @param portNumber port where the next hop attaches to |
| 1628 | * @param dummyVlanId vlan ID of the packet to match |
| 1629 | * @param innerVlan inner vlan ID of the next hop |
| 1630 | * @param outerVlan outer vlan ID of the next hop |
| 1631 | * @param outerTpid outer TPID of the next hop |
| 1632 | * @return forwarding objective builder |
| 1633 | */ |
| 1634 | private ForwardingObjective.Builder egressFwdObjBuilder(PortNumber portNumber, VlanId dummyVlanId, |
| 1635 | VlanId innerVlan, VlanId outerVlan, EthType outerTpid) { |
| 1636 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1637 | sbuilder.matchVlanId(dummyVlanId); |
| 1638 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 1639 | tbuilder.setOutput(portNumber).setVlanId(innerVlan); |
| 1640 | |
| 1641 | if (outerTpid.equals(EthType.EtherType.QINQ.ethType())) { |
| 1642 | tbuilder.pushVlan(outerTpid); |
| 1643 | } else { |
| 1644 | tbuilder.pushVlan(); |
| 1645 | } |
| 1646 | |
| 1647 | tbuilder.setVlanId(outerVlan); |
| 1648 | return DefaultForwardingObjective.builder() |
| 1649 | .withSelector(sbuilder.build()) |
| 1650 | .withTreatment(tbuilder.build()) |
| 1651 | .fromApp(srManager.appId) |
| 1652 | .makePermanent() |
| 1653 | .withPriority(DEFAULT_PRIORITY) |
| 1654 | .withFlag(ForwardingObjective.Flag.EGRESS); |
| 1655 | } |
| 1656 | |
| 1657 | /** |
| 1658 | * Populates IP rules for a route that has double-tagged next hop. |
| 1659 | * |
| 1660 | * @param deviceId device ID of the device that next hop attaches to |
| 1661 | * @param prefix IP prefix of the route |
| 1662 | * @param hostMac MAC address of the next hop |
| 1663 | * @param dummyVlan Dummy Vlan ID allocated for this route |
| 1664 | * @param innerVlan inner Vlan ID of the next hop |
| 1665 | * @param outerVlan outer Vlan ID of the next hop |
| 1666 | * @param outerTpid outer TPID of the next hop |
| 1667 | * @param outPort port where the next hop attaches to |
| 1668 | */ |
| 1669 | void populateDoubleTaggedRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId dummyVlan, |
| 1670 | VlanId innerVlan, VlanId outerVlan, EthType outerTpid, PortNumber outPort) { |
| 1671 | ForwardingObjective.Builder fwdBuilder; |
| 1672 | log.debug("Populate direct routing entry for double-tagged host route {} at {}:{}", |
| 1673 | prefix, deviceId, outPort); |
| 1674 | |
| 1675 | ForwardingObjective.Builder egressFwdBuilder = egressFwdObjBuilder( |
| 1676 | outPort, dummyVlan, innerVlan, outerVlan, outerTpid); |
| 1677 | DefaultObjectiveContext egressFwdContext = new DefaultObjectiveContext( |
| 1678 | objective -> log.debug("Egress rule for IP {} is populated", prefix.address()), |
| 1679 | (objective, error) -> { |
| 1680 | log.warn("Failed to populate egress rule for IP {}: {}", prefix.address(), error); |
| 1681 | srManager.dummyVlanIdStore().remove(new DummyVlanIdStoreKey( |
| 1682 | new ConnectPoint(deviceId, outPort), prefix.address() |
| 1683 | )); |
| 1684 | }); |
| 1685 | try { |
| 1686 | fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, dummyVlan, outPort, false); |
| 1687 | } catch (DeviceConfigNotFoundException e) { |
| 1688 | log.error(e.getMessage() + " Aborting populateDoubleTaggedRoute"); |
| 1689 | return; |
| 1690 | } |
| 1691 | if (fwdBuilder == null) { |
| 1692 | log.error("Aborting double-tagged host routing table entry due to error for dev:{} route:{}", |
| 1693 | deviceId, prefix); |
| 1694 | return; |
| 1695 | } |
| 1696 | |
| 1697 | // Egress forwarding objective should be installed after the nextObjective for the output port is installed. |
| 1698 | // Installation of routingFwdObj will ensure the installation of the nextObjective. |
| 1699 | int nextId = fwdBuilder.add().nextId(); |
| 1700 | DefaultObjectiveContext context = new DefaultObjectiveContext(objective -> { |
| 1701 | log.debug("Direct routing rule for double-tagged host route {} populated. nextId={}", prefix, nextId); |
| 1702 | srManager.flowObjectiveService.forward(deviceId, egressFwdBuilder.add(egressFwdContext)); |
| 1703 | }, (objective, error) -> |
| 1704 | log.warn("Failed to populate direct routing rule for double-tagged host route {}: {}", prefix, error) |
| 1705 | ); |
| 1706 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context)); |
| 1707 | rulePopulationCounter.incrementAndGet(); |
| 1708 | } |
| 1709 | |
| 1710 | /** |
| 1711 | * Revokes IP rules for a route that has double-tagged next hop. |
| 1712 | * |
| 1713 | * @param deviceId device ID of the device that next hop attaches to |
| 1714 | * @param prefix IP prefix of the route |
| 1715 | * @param hostMac MAC address of the next hop |
| 1716 | * @param hostVlan Vlan ID of the next hop |
| 1717 | * @param innerVlan inner Vlan ID of the next hop |
| 1718 | * @param outerVlan outer Vlan ID of the next hop |
| 1719 | * @param outerTpid outer TPID of the next hop |
| 1720 | * @param outPort port where the next hop attaches to |
| 1721 | */ |
| 1722 | void revokeDoubleTaggedRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, |
| 1723 | VlanId hostVlan, VlanId innerVlan, VlanId outerVlan, |
| 1724 | EthType outerTpid, PortNumber outPort) { |
| 1725 | revokeRoute(deviceId, prefix, hostMac, hostVlan, outPort); |
| 1726 | |
| 1727 | DummyVlanIdStoreKey key = new DummyVlanIdStoreKey( |
| 1728 | new ConnectPoint(deviceId, outPort), prefix.address()); |
| 1729 | VlanId dummyVlanId = srManager.dummyVlanIdStore().get(key); |
| 1730 | if (dummyVlanId == null) { |
| 1731 | log.warn("Failed to retrieve dummy VLAN ID for {}/{} and {}", |
| 1732 | deviceId, outPort, prefix.address()); |
| 1733 | return; |
| 1734 | } |
| 1735 | ForwardingObjective.Builder fob = egressFwdObjBuilder( |
| 1736 | outPort, dummyVlanId, innerVlan, outerVlan, outerTpid); |
| 1737 | DefaultObjectiveContext context = new DefaultObjectiveContext(objective -> { |
| 1738 | log.debug("Egress rule for IP {} revoked", prefix.address()); |
| 1739 | srManager.dummyVlanIdStore().remove(key); |
| 1740 | }, (objective, error) -> { |
| 1741 | log.warn("Failed to revoke egress rule for IP {}: {}", prefix.address(), error); |
| 1742 | }); |
| 1743 | srManager.flowObjectiveService.forward(deviceId, fob.remove(context)); |
| 1744 | } |
| 1745 | |
Jonghwan Hyun | 671a7ab | 2018-04-30 09:27:21 -0700 | [diff] [blame] | 1746 | /** |
| 1747 | * Checks whether the specified port has IP configuration or not. |
| 1748 | * |
| 1749 | * @param cp ConnectPoint to check the existance of IP configuration |
| 1750 | * @return true if the port has IP configuration; false otherwise. |
| 1751 | */ |
| 1752 | private boolean hasIPConfiguration(ConnectPoint cp) { |
| 1753 | Set<Interface> interfaces = srManager.interfaceService.getInterfacesByPort(cp); |
| 1754 | return interfaces.stream().anyMatch(intf -> intf.ipAddressesList().size() > 0); |
| 1755 | } |
Saurav Das | 9bf4958 | 2018-08-13 15:34:26 -0700 | [diff] [blame] | 1756 | |
| 1757 | /** |
| 1758 | * Updates filtering rules for unconfigured ports on all devices for which |
| 1759 | * this controller instance is master. |
| 1760 | * |
| 1761 | * @param pushVlan true if the filtering rule requires a push vlan action |
| 1762 | * @param oldVlanId the vlanId to be removed |
| 1763 | * @param newVlanId the vlanId to be added |
| 1764 | */ |
| 1765 | void updateSpecialVlanFilteringRules(boolean pushVlan, VlanId oldVlanId, |
| 1766 | VlanId newVlanId) { |
| 1767 | for (Device dev : srManager.deviceService.getAvailableDevices()) { |
| 1768 | if (srManager.mastershipService.isLocalMaster(dev.id())) { |
| 1769 | for (Port p : srManager.deviceService.getPorts(dev.id())) { |
| 1770 | if (!hasIPConfiguration(new ConnectPoint(dev.id(), p.number())) |
| 1771 | && p.isEnabled()) { |
| 1772 | updateSinglePortFilters(dev.id(), p.number(), pushVlan, |
| 1773 | oldVlanId, false); |
| 1774 | updateSinglePortFilters(dev.id(), p.number(), pushVlan, |
| 1775 | newVlanId, true); |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | } |
| 1781 | |
Charles Chan | f0f7b5c | 2018-08-29 14:55:53 -0700 | [diff] [blame] | 1782 | private boolean isIpv6Configured(DeviceId deviceId) { |
| 1783 | boolean isIpv6Configured; |
| 1784 | try { |
| 1785 | isIpv6Configured = (config.getRouterIpv6(deviceId) != null); |
| 1786 | } catch (DeviceConfigNotFoundException e) { |
| 1787 | isIpv6Configured = false; |
| 1788 | } |
| 1789 | return isIpv6Configured; |
| 1790 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1791 | } |