sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 19 | import org.onlab.packet.Ethernet; |
| 20 | import org.onlab.packet.Ip4Address; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 21 | import org.onlab.packet.Ip4Prefix; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 26 | import org.onosproject.net.ConnectPoint; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 27 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 28 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 29 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 30 | import org.onosproject.net.DeviceId; |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 31 | import org.onosproject.net.Port; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 32 | import org.onosproject.net.PortNumber; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 33 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 34 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 35 | import org.onosproject.net.flow.TrafficSelector; |
| 36 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 37 | import org.onosproject.net.flow.criteria.Criteria; |
| 38 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 39 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 40 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 41 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 42 | import org.onosproject.net.flowobjective.ForwardingObjective.Builder; |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 43 | import org.onosproject.net.flowobjective.ForwardingObjective.Flag; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
| 46 | |
| 47 | import java.util.ArrayList; |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 48 | import java.util.HashSet; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 49 | import java.util.List; |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 50 | import java.util.Map; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 51 | import java.util.Set; |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 52 | import java.util.concurrent.atomic.AtomicLong; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 53 | |
| 54 | import static com.google.common.base.Preconditions.checkNotNull; |
| 55 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Populator of segment routing flow rules. |
| 58 | */ |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 59 | public class RoutingRulePopulator { |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 60 | private static final Logger log = LoggerFactory |
| 61 | .getLogger(RoutingRulePopulator.class); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 62 | |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 63 | private AtomicLong rulePopulationCounter; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 64 | private SegmentRoutingManager srManager; |
| 65 | private DeviceConfiguration config; |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 66 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Creates a RoutingRulePopulator object. |
| 69 | * |
Thomas Vachuska | 8a07509 | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 70 | * @param srManager segment routing manager reference |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 71 | */ |
| 72 | public RoutingRulePopulator(SegmentRoutingManager srManager) { |
| 73 | this.srManager = srManager; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 74 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 75 | this.rulePopulationCounter = new AtomicLong(0); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Resets the population counter. |
| 80 | */ |
| 81 | public void resetCounter() { |
| 82 | rulePopulationCounter.set(0); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the number of rules populated. |
Thomas Vachuska | 7cfc620 | 2015-04-30 18:13:25 -0700 | [diff] [blame] | 87 | * |
| 88 | * @return number of rules |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 89 | */ |
| 90 | public long getCounter() { |
| 91 | return rulePopulationCounter.get(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 95 | * Populates IP flow rules for specific hosts directly connected to the |
| 96 | * switch. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 97 | * |
| 98 | * @param deviceId switch ID to set the rules |
| 99 | * @param hostIp host IP address |
| 100 | * @param hostMac host MAC address |
| 101 | * @param outPort port where the host is connected |
| 102 | */ |
| 103 | public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, |
| 104 | MacAddress hostMac, PortNumber outPort) { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 105 | log.debug("Populate IP table entry for host {} at {}:{}", |
| 106 | hostIp, deviceId, outPort); |
| 107 | ForwardingObjective.Builder fwdBuilder; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 108 | try { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 109 | fwdBuilder = getForwardingObjectiveBuilder( |
| 110 | deviceId, hostIp, hostMac, outPort); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 111 | } catch (DeviceConfigNotFoundException e) { |
| 112 | log.warn(e.getMessage() + " Aborting populateIpRuleForHost."); |
| 113 | return; |
| 114 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 115 | srManager.flowObjectiveService. |
| 116 | forward(deviceId, fwdBuilder.add(new SRObjectiveContext(deviceId, |
| 117 | SRObjectiveContext.ObjectiveType.FORWARDING))); |
| 118 | rulePopulationCounter.incrementAndGet(); |
| 119 | } |
| 120 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Removes IP rules for host when the host is gone. |
| 123 | * |
| 124 | * @param deviceId device ID of the device that host attaches to |
| 125 | * @param hostIp IP address of the host |
| 126 | * @param hostMac MAC address of the host |
| 127 | * @param outPort port that host attaches to |
| 128 | */ |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 129 | public void revokeIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, |
| 130 | MacAddress hostMac, PortNumber outPort) { |
| 131 | log.debug("Revoke IP table entry for host {} at {}:{}", |
| 132 | hostIp, deviceId, outPort); |
| 133 | ForwardingObjective.Builder fwdBuilder; |
| 134 | try { |
| 135 | fwdBuilder = getForwardingObjectiveBuilder( |
| 136 | deviceId, hostIp, hostMac, outPort); |
| 137 | } catch (DeviceConfigNotFoundException e) { |
| 138 | log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); |
| 139 | return; |
| 140 | } |
| 141 | srManager.flowObjectiveService. |
| 142 | forward(deviceId, fwdBuilder.remove(new SRObjectiveContext(deviceId, |
| 143 | SRObjectiveContext.ObjectiveType.FORWARDING))); |
| 144 | } |
| 145 | |
| 146 | private ForwardingObjective.Builder getForwardingObjectiveBuilder( |
| 147 | DeviceId deviceId, Ip4Address hostIp, |
| 148 | MacAddress hostMac, PortNumber outPort) |
| 149 | throws DeviceConfigNotFoundException { |
| 150 | MacAddress deviceMac; |
| 151 | deviceMac = config.getDeviceMac(deviceId); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 152 | int priority; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 153 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 154 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 155 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 156 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 157 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 158 | // Special case for default route |
| 159 | if (hostIp.isZero()) { |
| 160 | sbuilder.matchIPDst(IpPrefix.valueOf(hostIp, 0)); |
| 161 | priority = SegmentRoutingService.MIN_IP_PRIORITY; |
| 162 | } else { |
| 163 | Ip4Prefix hostIpPrefix = Ip4Prefix.valueOf(hostIp, IpPrefix.MAX_INET_MASK_LENGTH); |
| 164 | sbuilder.matchIPDst(hostIpPrefix); |
| 165 | priority = getPriorityFromPrefix(hostIpPrefix); |
| 166 | } |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 167 | TrafficSelector selector = sbuilder.build(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 168 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 169 | tbuilder.deferred() |
| 170 | .setEthDst(hostMac) |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 171 | .setEthSrc(deviceMac) |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 172 | .setOutput(outPort); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 173 | TrafficTreatment treatment = tbuilder.build(); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 174 | |
| 175 | // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed. |
| 176 | // for switch pipelines that need it, provide outgoing vlan as metadata |
| 177 | VlanId outvlan = null; |
| 178 | Ip4Prefix subnet = srManager.deviceConfiguration.getPortSubnet(deviceId, outPort); |
| 179 | if (subnet == null) { |
| 180 | outvlan = VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET); |
| 181 | } else { |
| 182 | outvlan = srManager.getSubnetAssignedVlanId(deviceId, subnet); |
| 183 | } |
| 184 | TrafficSelector meta = DefaultTrafficSelector.builder() |
| 185 | .matchVlanId(outvlan).build(); |
| 186 | int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outPort, |
| 187 | treatment, meta); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 188 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 189 | return DefaultForwardingObjective.builder() |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 190 | .withSelector(selector) |
| 191 | .nextStep(portNextObjId) |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 192 | .fromApp(srManager.appId).makePermanent() |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 193 | .withPriority(priority) |
| 194 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Populates IP flow rules for the subnets of the destination router. |
| 199 | * |
| 200 | * @param deviceId switch ID to set the rules |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 201 | * @param subnets subnet information |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 202 | * @param destSw destination switch ID |
| 203 | * @param nextHops next hop switch ID list |
| 204 | * @return true if all rules are set successfully, false otherwise |
| 205 | */ |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 206 | public boolean populateIpRuleForSubnet(DeviceId deviceId, |
Charles Chan | c6ad775 | 2015-10-29 14:58:10 -0700 | [diff] [blame] | 207 | Set<Ip4Prefix> subnets, |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 208 | DeviceId destSw, |
| 209 | Set<DeviceId> nextHops) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 210 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 211 | for (IpPrefix subnet : subnets) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 212 | if (!populateIpRuleForRouter(deviceId, subnet, destSw, nextHops)) { |
| 213 | return false; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Populates IP flow rules for the router IP address. |
| 222 | * |
Saurav Das | 8897918 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 223 | * @param deviceId target device ID to set the rules |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 224 | * @param ipPrefix the IP address of the destination router |
| 225 | * @param destSw device ID of the destination router |
| 226 | * @param nextHops next hop switch ID list |
| 227 | * @return true if all rules are set successfully, false otherwise |
| 228 | */ |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 229 | public boolean populateIpRuleForRouter(DeviceId deviceId, |
| 230 | IpPrefix ipPrefix, DeviceId destSw, |
| 231 | Set<DeviceId> nextHops) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 232 | int segmentId; |
| 233 | try { |
| 234 | segmentId = config.getSegmentId(destSw); |
| 235 | } catch (DeviceConfigNotFoundException e) { |
| 236 | log.warn(e.getMessage() + " Aborting populateIpRuleForRouter."); |
| 237 | return false; |
| 238 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 239 | |
| 240 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
Charles Chan | 3ef31e7 | 2016-02-05 13:33:54 -0800 | [diff] [blame] | 241 | sbuilder.matchIPDst(ipPrefix); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 242 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 243 | TrafficSelector selector = sbuilder.build(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 244 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 245 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 246 | NeighborSet ns; |
| 247 | TrafficTreatment treatment; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 248 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 249 | // If the next hop is the same as the final destination, then MPLS label |
| 250 | // is not set. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 251 | if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 252 | tbuilder.immediate().decNwTtl(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 253 | ns = new NeighborSet(nextHops); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 254 | treatment = tbuilder.build(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 255 | } else { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 256 | ns = new NeighborSet(nextHops, segmentId); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 257 | treatment = null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 260 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 261 | // if needed by the switch pipeline. Since neighbor sets are always to |
| 262 | // other neighboring routers, there is no subnet assigned on those ports. |
| 263 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
| 264 | metabuilder.matchVlanId( |
| 265 | VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET)); |
| 266 | |
| 267 | int nextId = srManager.getNextObjectiveId(deviceId, ns, metabuilder.build()); |
| 268 | if (nextId <= 0) { |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 269 | log.warn("No next objective in {} for ns: {}", deviceId, ns); |
| 270 | return false; |
| 271 | } |
| 272 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 273 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 274 | .builder() |
| 275 | .fromApp(srManager.appId) |
| 276 | .makePermanent() |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 277 | .nextStep(nextId) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 278 | .withSelector(selector) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 279 | .withPriority(getPriorityFromPrefix(ipPrefix)) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 280 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 281 | if (treatment != null) { |
| 282 | fwdBuilder.withTreatment(treatment); |
| 283 | } |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 284 | log.debug("Installing IPv4 forwarding objective " |
sangho | 2165d22 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 285 | + "for router IP/subnet {} in switch {}", |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 286 | ipPrefix, |
| 287 | deviceId); |
Srikanth Vavilapalli | 8c83f1d | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 288 | srManager.flowObjectiveService. |
| 289 | forward(deviceId, |
| 290 | fwdBuilder. |
| 291 | add(new SRObjectiveContext(deviceId, |
| 292 | SRObjectiveContext.ObjectiveType.FORWARDING))); |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 293 | rulePopulationCounter.incrementAndGet(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 294 | |
| 295 | return true; |
| 296 | } |
| 297 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 298 | /** |
Saurav Das | 8897918 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 299 | * Populates MPLS flow rules to all routers. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 300 | * |
Saurav Das | 8897918 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 301 | * @param deviceId target device ID of the switch to set the rules |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 302 | * @param destSwId destination switch device ID |
| 303 | * @param nextHops next hops switch ID list |
| 304 | * @return true if all rules are set successfully, false otherwise |
| 305 | */ |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 306 | public boolean populateMplsRule(DeviceId deviceId, DeviceId destSwId, |
| 307 | Set<DeviceId> nextHops) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 308 | int segmentId; |
| 309 | try { |
| 310 | segmentId = config.getSegmentId(destSwId); |
| 311 | } catch (DeviceConfigNotFoundException e) { |
| 312 | log.warn(e.getMessage() + " Aborting populateMplsRule."); |
| 313 | return false; |
| 314 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 315 | |
| 316 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
Sho SHIMIZU | 47b8aa2 | 2015-09-11 11:19:11 -0700 | [diff] [blame] | 317 | List<ForwardingObjective.Builder> fwdObjBuilders = new ArrayList<>(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 318 | |
| 319 | // TODO Handle the case of Bos == false |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 320 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 321 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId)); |
Charles Chan | de6655c | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 322 | sbuilder.matchMplsBos(true); |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 323 | TrafficSelector selector = sbuilder.build(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 324 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 325 | // setup metadata to pass to nextObjective - indicate the vlan on egress |
| 326 | // if needed by the switch pipeline. Since mpls next-hops are always to |
| 327 | // other neighboring routers, there is no subnet assigned on those ports. |
| 328 | TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector); |
| 329 | metabuilder.matchVlanId( |
| 330 | VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET)); |
| 331 | |
| 332 | // If the next hop is the destination router for the segment, do pop |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 333 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 334 | log.debug("populateMplsRule: Installing MPLS forwarding objective for " |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 335 | + "label {} in switch {} with pop", segmentId, deviceId); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 336 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 337 | // bos pop case (php) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 338 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 339 | getMplsForwardingObjective(deviceId, |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 340 | nextHops, |
| 341 | true, |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 342 | true, |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 343 | metabuilder.build()); |
| 344 | if (fwdObjBosBuilder == null) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 345 | return false; |
| 346 | } |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 347 | fwdObjBuilders.add(fwdObjBosBuilder); |
| 348 | |
| 349 | // XXX not-bos pop case, SR app multi-label not implemented yet |
| 350 | /*ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 351 | getMplsForwardingObjective(deviceId, |
| 352 | nextHops, |
| 353 | true, |
| 354 | false);*/ |
| 355 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 356 | } else { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 357 | // next hop is not destination, SR CONTINUE case (swap with self) |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 358 | log.debug("Installing MPLS forwarding objective for " |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 359 | + "label {} in switch {} without pop", segmentId, deviceId); |
Srikanth Vavilapalli | 7cd1671 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 360 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 361 | // continue case with bos - this does get triggered in edge routers |
| 362 | // and in core routers - driver can handle depending on availability |
| 363 | // of MPLS ECMP or not |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 364 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 365 | getMplsForwardingObjective(deviceId, |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 366 | nextHops, |
| 367 | false, |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 368 | true, |
| 369 | metabuilder.build()); |
| 370 | if (fwdObjBosBuilder == null) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 371 | return false; |
| 372 | } |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 373 | fwdObjBuilders.add(fwdObjBosBuilder); |
| 374 | |
| 375 | // XXX continue case with not-bos - SR app multi label not implemented yet |
| 376 | // also requires MPLS ECMP |
| 377 | /*ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 378 | getMplsForwardingObjective(deviceId, |
| 379 | nextHops, |
| 380 | false, |
| 381 | false); */ |
| 382 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 385 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
| 386 | ((Builder) ((Builder) fwdObjBuilder.fromApp(srManager.appId) |
| 387 | .makePermanent()).withSelector(selector) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 388 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)) |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 389 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Srikanth Vavilapalli | 8c83f1d | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 390 | srManager.flowObjectiveService. |
| 391 | forward(deviceId, |
| 392 | fwdObjBuilder. |
| 393 | add(new SRObjectiveContext(deviceId, |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 394 | SRObjectiveContext.ObjectiveType.FORWARDING))); |
sangho | fb7c729 | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 395 | rulePopulationCounter.incrementAndGet(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | return true; |
| 399 | } |
| 400 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 401 | private ForwardingObjective.Builder getMplsForwardingObjective( |
| 402 | DeviceId deviceId, |
| 403 | Set<DeviceId> nextHops, |
| 404 | boolean phpRequired, |
| 405 | boolean isBos, |
| 406 | TrafficSelector meta) { |
| 407 | |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 408 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 409 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 410 | |
| 411 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 412 | |
| 413 | if (phpRequired) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 414 | // php case - pop should always be flow-action |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 415 | log.debug("getMplsForwardingObjective: php required"); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 416 | tbuilder.deferred().copyTtlIn(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 417 | if (isBos) { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 418 | tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType()) |
| 419 | .decNwTtl(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 420 | } else { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 421 | tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType()) |
| 422 | .decMplsTtl(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 423 | } |
| 424 | } else { |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 425 | // swap with self case - SR CONTINUE |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 426 | log.debug("getMplsForwardingObjective: php not required"); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 427 | tbuilder.deferred().decMplsTtl(); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 430 | // All forwarding is via ECMP group, the metadata informs the driver |
| 431 | // that the next-Objective will be used by MPLS flows. In other words, |
| 432 | // MPLS ECMP is requested. It is up to the driver to decide if these |
| 433 | // packets will be hashed or not. |
| 434 | fwdBuilder.withTreatment(tbuilder.build()); |
| 435 | NeighborSet ns = new NeighborSet(nextHops); |
| 436 | log.debug("Trying to get a nextObjid for mpls rule on device:{} to ns:{}", |
| 437 | deviceId, ns); |
| 438 | |
| 439 | int nextId = srManager.getNextObjectiveId(deviceId, ns, meta); |
| 440 | if (nextId <= 0) { |
| 441 | log.warn("No next objective in {} for ns: {}", deviceId, ns); |
| 442 | return null; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Saurav Das | 4c35fc4 | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 445 | fwdBuilder.nextStep(nextId); |
Srikanth Vavilapalli | 6450548 | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 446 | return fwdBuilder; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /** |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 450 | * Creates a filtering objective to permit all untagged packets with a |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 451 | * dstMac corresponding to the router's MAC address. For those pipelines |
| 452 | * that need to internally assign vlans to untagged packets, this method |
| 453 | * provides per-subnet vlan-ids as metadata. |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 454 | * <p> |
| 455 | * Note that the vlan assignment is only done by the master-instance for a switch. |
| 456 | * However we send the filtering objective from slave-instances as well, so |
| 457 | * that drivers can obtain other information (like Router MAC and IP). |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 458 | * |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 459 | * @param deviceId the switch dpid for the router |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 460 | */ |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 461 | public void populateRouterMacVlanFilters(DeviceId deviceId) { |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 462 | log.debug("Installing per-port filtering objective for untagged " |
| 463 | + "packets in device {}", deviceId); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 464 | |
| 465 | MacAddress deviceMac; |
| 466 | try { |
| 467 | deviceMac = config.getDeviceMac(deviceId); |
| 468 | } catch (DeviceConfigNotFoundException e) { |
| 469 | log.warn(e.getMessage() + " Aborting populateRouterMacVlanFilters."); |
| 470 | return; |
| 471 | } |
| 472 | |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 473 | for (Port port : srManager.deviceService.getPorts(deviceId)) { |
Charles Chan | 43547ca | 2016-02-10 20:46:58 -0800 | [diff] [blame] | 474 | ConnectPoint cp = new ConnectPoint(deviceId, port.number()); |
| 475 | // TODO: Handles dynamic port events when we are ready for dynamic config |
| 476 | if (!srManager.deviceConfiguration.excludedPorts().contains(cp) && |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 477 | port.isEnabled()) { |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 478 | Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number()); |
| 479 | VlanId assignedVlan = (portSubnet == null) |
| 480 | ? VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET) |
| 481 | : srManager.getSubnetAssignedVlanId(deviceId, portSubnet); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 482 | |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 483 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 484 | fob.withKey(Criteria.matchInPort(port.number())) |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 485 | .addCondition(Criteria.matchEthDst(deviceMac)) |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 486 | .addCondition(Criteria.matchVlanId(VlanId.NONE)) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 487 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY); |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 488 | // vlan assignment is valid only if this instance is master |
| 489 | if (srManager.mastershipService.isLocalMaster(deviceId)) { |
| 490 | TrafficTreatment tt = DefaultTrafficTreatment.builder() |
| 491 | .pushVlan().setVlanId(assignedVlan).build(); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 492 | fob.withMeta(tt); |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 493 | } |
Saurav Das | 7c30537 | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 494 | fob.permit().fromApp(srManager.appId); |
| 495 | srManager.flowObjectiveService. |
| 496 | filter(deviceId, fob.add(new SRObjectiveContext(deviceId, |
| 497 | SRObjectiveContext.ObjectiveType.FILTER))); |
| 498 | } |
| 499 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 503 | * Creates a forwarding objective to punt all IP packets, destined to the |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 504 | * router's port IP addresses, to the controller. Note that the input |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 505 | * 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] | 506 | * Furthermore, these are applied only by the master instance. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 507 | * |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 508 | * @param deviceId the switch dpid for the router |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 509 | */ |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 510 | public void populateRouterIpPunts(DeviceId deviceId) { |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 511 | Ip4Address routerIp; |
| 512 | try { |
| 513 | routerIp = config.getRouterIp(deviceId); |
| 514 | } catch (DeviceConfigNotFoundException e) { |
| 515 | log.warn(e.getMessage() + " Aborting populateRouterIpPunts."); |
| 516 | return; |
| 517 | } |
| 518 | |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 519 | if (!srManager.mastershipService.isLocalMaster(deviceId)) { |
| 520 | log.debug("Not installing port-IP punts - not the master for dev:{} ", |
| 521 | deviceId); |
| 522 | return; |
| 523 | } |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 524 | ForwardingObjective.Builder puntIp = DefaultForwardingObjective.builder(); |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 525 | Set<Ip4Address> allIps = new HashSet<>(config.getPortIPs(deviceId)); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 526 | allIps.add(routerIp); |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 527 | for (Ip4Address ipaddr : allIps) { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 528 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 529 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 530 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 531 | sbuilder.matchIPDst(IpPrefix.valueOf(ipaddr, |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 532 | IpPrefix.MAX_INET_MASK_LENGTH)); |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 533 | tbuilder.setOutput(PortNumber.CONTROLLER); |
| 534 | puntIp.withSelector(sbuilder.build()); |
| 535 | puntIp.withTreatment(tbuilder.build()); |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 536 | puntIp.withFlag(Flag.VERSATILE) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 537 | .withPriority(SegmentRoutingService.HIGHEST_PRIORITY) |
Saurav Das | 9f1c42e | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 538 | .makePermanent() |
| 539 | .fromApp(srManager.appId); |
| 540 | log.debug("Installing forwarding objective to punt port IP addresses"); |
| 541 | srManager.flowObjectiveService. |
| 542 | forward(deviceId, |
| 543 | puntIp.add(new SRObjectiveContext(deviceId, |
| 544 | SRObjectiveContext.ObjectiveType.FORWARDING))); |
| 545 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 548 | /** |
| 549 | * Populates a forwarding objective to send packets that miss other high |
| 550 | * priority Bridging Table entries to a group that contains all ports of |
| 551 | * its subnet. |
| 552 | * |
| 553 | * Note: We assume that packets sending from the edge switches to the hosts |
| 554 | * have untagged VLAN. |
| 555 | * The VLAN tag will be popped later in the flooding group. |
| 556 | * |
| 557 | * @param deviceId switch ID to set the rules |
| 558 | */ |
| 559 | public void populateSubnetBroadcastRule(DeviceId deviceId) { |
| 560 | config.getSubnets(deviceId).forEach(subnet -> { |
| 561 | int nextId = srManager.getSubnetNextObjectiveId(deviceId, subnet); |
| 562 | VlanId vlanId = srManager.getSubnetAssignedVlanId(deviceId, subnet); |
| 563 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 564 | if (nextId < 0 || vlanId == null) { |
| 565 | log.error("Cannot install subnet broadcast rule in dev:{} due" |
| 566 | + "to vlanId:{} or nextId:{}", vlanId, nextId); |
| 567 | return; |
| 568 | } |
| 569 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 570 | /* Driver should treat objective with MacAddress.NONE as the |
| 571 | * subnet broadcast rule |
| 572 | */ |
| 573 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 574 | sbuilder.matchVlanId(vlanId); |
| 575 | sbuilder.matchEthDst(MacAddress.NONE); |
| 576 | |
| 577 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 578 | fob.withFlag(Flag.SPECIFIC) |
| 579 | .withSelector(sbuilder.build()) |
| 580 | .nextStep(nextId) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 581 | .withPriority(SegmentRoutingService.FLOOD_PRIORITY) |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 582 | .fromApp(srManager.appId) |
| 583 | .makePermanent(); |
| 584 | |
| 585 | srManager.flowObjectiveService.forward( |
| 586 | deviceId, |
| 587 | fob.add(new SRObjectiveContext( |
| 588 | deviceId, |
| 589 | SRObjectiveContext.ObjectiveType.FORWARDING) |
| 590 | ) |
| 591 | ); |
| 592 | }); |
| 593 | } |
| 594 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 595 | /** |
| 596 | * Creates a filtering objective to permit VLAN cross-connect traffic. |
| 597 | * |
| 598 | * @param deviceId the DPID of the switch |
| 599 | */ |
| 600 | public void populateXConnectVlanFilters(DeviceId deviceId) { |
| 601 | Map<VlanId, List<ConnectPoint>> xConnectsForDevice = |
| 602 | config.getXConnects(); |
| 603 | xConnectsForDevice.forEach((vlanId, connectPoints) -> { |
| 604 | // Only proceed the xConnect for given device |
| 605 | for (ConnectPoint connectPoint : connectPoints) { |
| 606 | if (!connectPoint.deviceId().equals(deviceId)) { |
| 607 | return; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | connectPoints.forEach(connectPoint -> { |
| 612 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 613 | fob.withKey(Criteria.matchInPort(connectPoint.port())) |
| 614 | .addCondition(Criteria.matchVlanId(vlanId)) |
| 615 | .addCondition(Criteria.matchEthDst(MacAddress.NONE)) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 616 | .withPriority(SegmentRoutingService.XCONNECT_PRIORITY); |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 617 | |
| 618 | fob.permit().fromApp(srManager.appId); |
| 619 | srManager.flowObjectiveService |
| 620 | .filter(deviceId, fob.add(new SRObjectiveContext(deviceId, |
| 621 | SRObjectiveContext.ObjectiveType.FILTER))); |
| 622 | }); |
| 623 | }); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Populates a forwarding objective that points the VLAN cross-connect |
| 628 | * packets to a broadcast group. |
| 629 | * |
| 630 | * @param deviceId switch ID to set the rules |
| 631 | */ |
| 632 | public void populateXConnectBroadcastRule(DeviceId deviceId) { |
| 633 | Map<VlanId, List<ConnectPoint>> xConnects = |
| 634 | config.getXConnects(); |
| 635 | xConnects.forEach((vlanId, connectPoints) -> { |
| 636 | // Only proceed the xConnect for given device |
| 637 | for (ConnectPoint connectPoint : connectPoints) { |
| 638 | if (!connectPoint.deviceId().equals(deviceId)) { |
| 639 | return; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | int nextId = srManager.getXConnectNextObjectiveId(deviceId, vlanId); |
| 644 | if (nextId < 0) { |
| 645 | log.error("Cannot install cross-connect broadcast rule in dev:{} " + |
| 646 | "due to missing nextId:{}", deviceId, nextId); |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | /* |
| 651 | * Driver should treat objectives with MacAddress.NONE and !VlanId.NONE |
| 652 | * as the VLAN cross-connect broadcast rules |
| 653 | */ |
| 654 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 655 | sbuilder.matchVlanId(vlanId); |
| 656 | sbuilder.matchEthDst(MacAddress.NONE); |
| 657 | |
| 658 | ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); |
| 659 | fob.withFlag(Flag.SPECIFIC) |
| 660 | .withSelector(sbuilder.build()) |
| 661 | .nextStep(nextId) |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 662 | .withPriority(SegmentRoutingService.DEFAULT_PRIORITY) |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 663 | .fromApp(srManager.appId) |
| 664 | .makePermanent(); |
| 665 | |
| 666 | srManager.flowObjectiveService.forward( |
| 667 | deviceId, |
| 668 | fob.add(new SRObjectiveContext( |
| 669 | deviceId, |
| 670 | SRObjectiveContext.ObjectiveType.FORWARDING) |
| 671 | ) |
| 672 | ); |
| 673 | }); |
| 674 | } |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 675 | |
Charles Chan | 82ab193 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 676 | private int getPriorityFromPrefix(IpPrefix prefix) { |
| 677 | return (prefix.isIp4()) ? |
| 678 | 2000 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY : |
| 679 | 500 * prefix.prefixLength() + SegmentRoutingService.MIN_IP_PRIORITY; |
Srikanth Vavilapalli | 8c83f1d | 2015-05-22 13:47:31 -0700 | [diff] [blame] | 680 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 681 | } |