sangho | b35a619 | 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 | |
| 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.Ip4Address; |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 20 | import org.onlab.packet.Ip4Prefix; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 24 | import org.onlab.packet.VlanId; |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 25 | import org.onosproject.segmentrouting.grouphandler.NeighborSet; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.Link; |
| 28 | import org.onosproject.net.PortNumber; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 33 | import org.onosproject.net.flow.criteria.Criteria; |
| 34 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 35 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 36 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 37 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 38 | import org.onosproject.net.flowobjective.ForwardingObjective.Builder; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 39 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; |
| 41 | |
| 42 | import java.util.ArrayList; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 43 | import java.util.List; |
| 44 | import java.util.Set; |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 45 | import java.util.concurrent.atomic.AtomicLong; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 46 | |
| 47 | import static com.google.common.base.Preconditions.checkNotNull; |
| 48 | |
| 49 | public class RoutingRulePopulator { |
| 50 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 51 | private static final Logger log = LoggerFactory |
| 52 | .getLogger(RoutingRulePopulator.class); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 53 | |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 54 | private AtomicLong rulePopulationCounter; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 55 | private SegmentRoutingManager srManager; |
| 56 | private DeviceConfiguration config; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Creates a RoutingRulePopulator object. |
| 59 | * |
Thomas Vachuska | e10f56b | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 60 | * @param srManager segment routing manager reference |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 61 | */ |
| 62 | public RoutingRulePopulator(SegmentRoutingManager srManager) { |
| 63 | this.srManager = srManager; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 64 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 65 | this.rulePopulationCounter = new AtomicLong(0); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Resets the population counter. |
| 70 | */ |
| 71 | public void resetCounter() { |
| 72 | rulePopulationCounter.set(0); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the number of rules populated. |
Thomas Vachuska | 266b443 | 2015-04-30 18:13:25 -0700 | [diff] [blame] | 77 | * |
| 78 | * @return number of rules |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 79 | */ |
| 80 | public long getCounter() { |
| 81 | return rulePopulationCounter.get(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 85 | * Populates IP flow rules for specific hosts directly connected to the |
| 86 | * switch. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 87 | * |
| 88 | * @param deviceId switch ID to set the rules |
| 89 | * @param hostIp host IP address |
| 90 | * @param hostMac host MAC address |
| 91 | * @param outPort port where the host is connected |
| 92 | */ |
| 93 | public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, |
| 94 | MacAddress hostMac, PortNumber outPort) { |
| 95 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 96 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 97 | |
| 98 | sbuilder.matchIPDst(IpPrefix.valueOf(hostIp, 32)); |
| 99 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 100 | |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 101 | tbuilder.deferred() |
| 102 | .setEthDst(hostMac) |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 103 | .setEthSrc(config.getDeviceMac(deviceId)) |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 104 | .setOutput(outPort); |
| 105 | |
| 106 | TrafficTreatment treatment = tbuilder.build(); |
| 107 | TrafficSelector selector = sbuilder.build(); |
| 108 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 109 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 110 | .builder().fromApp(srManager.appId).makePermanent() |
| 111 | .withSelector(selector).withTreatment(treatment) |
| 112 | .withPriority(100).withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 113 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 114 | log.debug("Installing IPv4 forwarding objective " |
| 115 | + "for host {} in switch {}", hostIp, deviceId); |
| 116 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 117 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Populates IP flow rules for the subnets of the destination router. |
| 122 | * |
| 123 | * @param deviceId switch ID to set the rules |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 124 | * @param subnets subnet information |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 125 | * @param destSw destination switch ID |
| 126 | * @param nextHops next hop switch ID list |
| 127 | * @return true if all rules are set successfully, false otherwise |
| 128 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 129 | public boolean populateIpRuleForSubnet(DeviceId deviceId, |
| 130 | List<Ip4Prefix> subnets, |
| 131 | DeviceId destSw, |
| 132 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 133 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 134 | for (IpPrefix subnet : subnets) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 135 | if (!populateIpRuleForRouter(deviceId, subnet, destSw, nextHops)) { |
| 136 | return false; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Populates IP flow rules for the router IP address. |
| 145 | * |
| 146 | * @param deviceId device ID to set the rules |
| 147 | * @param ipPrefix the IP address of the destination router |
| 148 | * @param destSw device ID of the destination router |
| 149 | * @param nextHops next hop switch ID list |
| 150 | * @return true if all rules are set successfully, false otherwise |
| 151 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 152 | public boolean populateIpRuleForRouter(DeviceId deviceId, |
| 153 | IpPrefix ipPrefix, DeviceId destSw, |
| 154 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 155 | |
| 156 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 157 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 158 | |
| 159 | sbuilder.matchIPDst(ipPrefix); |
| 160 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 161 | |
| 162 | NeighborSet ns = null; |
| 163 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 164 | // If the next hop is the same as the final destination, then MPLS label |
| 165 | // is not set. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 166 | if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 167 | tbuilder.deferred().decNwTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 168 | ns = new NeighborSet(nextHops); |
| 169 | } else { |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 170 | tbuilder.deferred().copyTtlOut(); |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 171 | ns = new NeighborSet(nextHops, config.getSegmentId(destSw)); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 172 | } |
| 173 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 174 | TrafficTreatment treatment = tbuilder.build(); |
| 175 | TrafficSelector selector = sbuilder.build(); |
| 176 | |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 177 | if (srManager.getNextObjectiveId(deviceId, ns) <= 0) { |
| 178 | log.warn("No next objective in {} for ns: {}", deviceId, ns); |
| 179 | return false; |
| 180 | } |
| 181 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 182 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 183 | .builder() |
| 184 | .fromApp(srManager.appId) |
| 185 | .makePermanent() |
| 186 | .nextStep(srManager.getNextObjectiveId(deviceId, ns)) |
| 187 | .withTreatment(treatment) |
| 188 | .withSelector(selector) |
| 189 | .withPriority(100) |
| 190 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 191 | log.debug("Installing IPv4 forwarding objective " |
sangho | 834e4b0 | 2015-05-01 09:38:25 -0700 | [diff] [blame] | 192 | + "for router IP/subnet {} in switch {}", |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 193 | ipPrefix, |
| 194 | deviceId); |
| 195 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 196 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 197 | |
| 198 | return true; |
| 199 | } |
| 200 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 201 | /** |
| 202 | * Populates MPLS flow rules to all transit routers. |
| 203 | * |
| 204 | * @param deviceId device ID of the switch to set the rules |
| 205 | * @param destSwId destination switch device ID |
| 206 | * @param nextHops next hops switch ID list |
| 207 | * @return true if all rules are set successfully, false otherwise |
| 208 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 209 | public boolean populateMplsRule(DeviceId deviceId, DeviceId destSwId, |
| 210 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 211 | |
| 212 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 213 | List<ForwardingObjective.Builder> fwdObjBuilders = new ArrayList<ForwardingObjective.Builder>(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 214 | |
| 215 | // TODO Handle the case of Bos == false |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 216 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(config.getSegmentId(destSwId))); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 217 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
| 218 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 219 | // If the next hop is the destination router, do PHP |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 220 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 221 | log.debug("populateMplsRule: Installing MPLS forwarding objective for " |
| 222 | + "label {} in switch {} with PHP", |
| 223 | config.getSegmentId(destSwId), |
| 224 | deviceId); |
| 225 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 226 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 227 | getMplsForwardingObjective(deviceId, |
| 228 | destSwId, |
| 229 | nextHops, |
| 230 | true, |
| 231 | true); |
| 232 | // TODO: Check with Sangho on why we need this |
| 233 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 234 | getMplsForwardingObjective(deviceId, |
| 235 | destSwId, |
| 236 | nextHops, |
| 237 | true, |
| 238 | false); |
| 239 | if (fwdObjBosBuilder != null) { |
| 240 | fwdObjBuilders.add(fwdObjBosBuilder); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 241 | } else { |
| 242 | log.warn("Failed to set MPLS rules."); |
| 243 | return false; |
| 244 | } |
| 245 | } else { |
Srikanth Vavilapalli | 2318191 | 2015-05-04 09:48:09 -0700 | [diff] [blame] | 246 | log.debug("Installing MPLS forwarding objective for " |
| 247 | + "label {} in switch {} without PHP", |
| 248 | config.getSegmentId(destSwId), |
| 249 | deviceId); |
| 250 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 251 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 252 | getMplsForwardingObjective(deviceId, |
| 253 | destSwId, |
| 254 | nextHops, |
| 255 | false, |
| 256 | true); |
| 257 | // TODO: Check with Sangho on why we need this |
| 258 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 259 | getMplsForwardingObjective(deviceId, |
| 260 | destSwId, |
| 261 | nextHops, |
| 262 | false, |
| 263 | false); |
| 264 | if (fwdObjBosBuilder != null) { |
| 265 | fwdObjBuilders.add(fwdObjBosBuilder); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 266 | } else { |
| 267 | log.warn("Failed to set MPLS rules."); |
| 268 | return false; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | TrafficSelector selector = sbuilder.build(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 273 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
| 274 | ((Builder) ((Builder) fwdObjBuilder.fromApp(srManager.appId) |
| 275 | .makePermanent()).withSelector(selector) |
| 276 | .withPriority(100)) |
| 277 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 278 | srManager.flowObjectiveService.forward(deviceId, |
| 279 | fwdObjBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 280 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | return true; |
| 284 | } |
| 285 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 286 | private ForwardingObjective.Builder getMplsForwardingObjective(DeviceId deviceId, |
| 287 | DeviceId destSw, |
| 288 | Set<DeviceId> nextHops, |
| 289 | boolean phpRequired, |
| 290 | boolean isBos) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 291 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 292 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 293 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 294 | |
| 295 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 296 | |
| 297 | if (phpRequired) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 298 | log.debug("getMplsForwardingObjective: php required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 299 | tbuilder.deferred().copyTtlIn(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 300 | if (isBos) { |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 301 | tbuilder.deferred().popMpls(Ethernet.TYPE_IPV4).decNwTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 302 | } else { |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 303 | tbuilder.deferred().popMpls(Ethernet.MPLS_UNICAST).decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 304 | } |
| 305 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 306 | log.debug("getMplsForwardingObjective: php not required"); |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 307 | tbuilder.deferred().decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 308 | } |
| 309 | |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 310 | if (!isECMPSupportedInTransitRouter() && !config.isEdgeDevice(deviceId)) { |
sangho | 45b009c | 2015-05-07 13:30:57 -0700 | [diff] [blame] | 311 | PortNumber port = selectOnePort(deviceId, nextHops); |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 312 | DeviceId nextHop = (DeviceId) nextHops.toArray()[0]; |
sangho | 45b009c | 2015-05-07 13:30:57 -0700 | [diff] [blame] | 313 | if (port == null) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 314 | log.warn("No link from {} to {}", deviceId, nextHops); |
| 315 | return null; |
| 316 | } |
sangho | 1e57565 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 317 | tbuilder.deferred() |
| 318 | .setEthSrc(config.getDeviceMac(deviceId)) |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 319 | .setEthDst(config.getDeviceMac(nextHop)) |
sangho | 45b009c | 2015-05-07 13:30:57 -0700 | [diff] [blame] | 320 | .setOutput(port); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 321 | fwdBuilder.withTreatment(tbuilder.build()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 322 | } else { |
| 323 | NeighborSet ns = new NeighborSet(nextHops); |
sangho | 5f1e457 | 2015-05-06 11:42:31 -0700 | [diff] [blame] | 324 | fwdBuilder.withTreatment(tbuilder.build()); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 325 | fwdBuilder.nextStep(srManager |
| 326 | .getNextObjectiveId(deviceId, ns)); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 329 | return fwdBuilder; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 330 | } |
| 331 | |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 332 | private boolean isECMPSupportedInTransitRouter() { |
| 333 | |
| 334 | // TODO: remove this function when objectives subsystem is supported. |
| 335 | return false; |
| 336 | } |
| 337 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 338 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 339 | * Populates VLAN flows rules. All packets are forwarded to TMAC table. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 340 | * |
| 341 | * @param deviceId switch ID to set the rules |
| 342 | */ |
| 343 | public void populateTableVlan(DeviceId deviceId) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 344 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 345 | fob.withKey(Criteria.matchInPort(PortNumber.ALL)) |
| 346 | .addCondition(Criteria.matchVlanId(VlanId.NONE)); |
| 347 | fob.permit().fromApp(srManager.appId); |
| 348 | log.debug("populateTableVlan: Installing filtering objective for untagged packets"); |
| 349 | srManager.flowObjectiveService.filter(deviceId, fob.add()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 353 | * Populates TMAC table rules. IP packets are forwarded to IP table. MPLS |
| 354 | * packets are forwarded to MPLS table. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 355 | * |
| 356 | * @param deviceId switch ID to set the rules |
| 357 | */ |
| 358 | public void populateTableTMac(DeviceId deviceId) { |
| 359 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 360 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 361 | fob.withKey(Criteria.matchInPort(PortNumber.ALL)) |
| 362 | .addCondition(Criteria.matchEthDst(config |
| 363 | .getDeviceMac(deviceId))); |
| 364 | fob.permit().fromApp(srManager.appId); |
| 365 | log.debug("populateTableVlan: Installing filtering objective for router mac"); |
| 366 | srManager.flowObjectiveService.filter(deviceId, fob.add()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 367 | } |
| 368 | |
sangho | 45b009c | 2015-05-07 13:30:57 -0700 | [diff] [blame] | 369 | private PortNumber selectOnePort(DeviceId srcId, Set<DeviceId> destIds) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 370 | |
sangho | 45b009c | 2015-05-07 13:30:57 -0700 | [diff] [blame] | 371 | Set<Link> links = srManager.linkService.getDeviceLinks(srcId); |
| 372 | for (DeviceId destId: destIds) { |
| 373 | for (Link link : links) { |
| 374 | if (link.dst().deviceId().equals(destId)) { |
| 375 | return link.src().port(); |
| 376 | } else if (link.src().deviceId().equals(destId)) { |
| 377 | return link.dst().port(); |
| 378 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | return null; |
| 383 | } |
| 384 | |
| 385 | } |