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 | |
| 101 | tbuilder.setEthDst(hostMac) |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 102 | .setEthSrc(config.getDeviceMac(deviceId)) |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 103 | .setOutput(outPort); |
| 104 | |
| 105 | TrafficTreatment treatment = tbuilder.build(); |
| 106 | TrafficSelector selector = sbuilder.build(); |
| 107 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 108 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 109 | .builder().fromApp(srManager.appId).makePermanent() |
| 110 | .withSelector(selector).withTreatment(treatment) |
| 111 | .withPriority(100).withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 112 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 113 | log.debug("Installing IPv4 forwarding objective " |
| 114 | + "for host {} in switch {}", hostIp, deviceId); |
| 115 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 116 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Populates IP flow rules for the subnets of the destination router. |
| 121 | * |
| 122 | * @param deviceId switch ID to set the rules |
Srikanth Vavilapalli | 4db76e3 | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 123 | * @param subnets subnet information |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 124 | * @param destSw destination switch ID |
| 125 | * @param nextHops next hop switch ID list |
| 126 | * @return true if all rules are set successfully, false otherwise |
| 127 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 128 | public boolean populateIpRuleForSubnet(DeviceId deviceId, |
| 129 | List<Ip4Prefix> subnets, |
| 130 | DeviceId destSw, |
| 131 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 132 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 133 | for (IpPrefix subnet : subnets) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 134 | if (!populateIpRuleForRouter(deviceId, subnet, destSw, nextHops)) { |
| 135 | return false; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Populates IP flow rules for the router IP address. |
| 144 | * |
| 145 | * @param deviceId device ID to set the rules |
| 146 | * @param ipPrefix the IP address of the destination router |
| 147 | * @param destSw device ID of the destination router |
| 148 | * @param nextHops next hop switch ID list |
| 149 | * @return true if all rules are set successfully, false otherwise |
| 150 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 151 | public boolean populateIpRuleForRouter(DeviceId deviceId, |
| 152 | IpPrefix ipPrefix, DeviceId destSw, |
| 153 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 154 | |
| 155 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 156 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 157 | |
| 158 | sbuilder.matchIPDst(ipPrefix); |
| 159 | sbuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 160 | |
| 161 | NeighborSet ns = null; |
| 162 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 163 | // If the next hop is the same as the final destination, then MPLS label |
| 164 | // is not set. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 165 | if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { |
| 166 | tbuilder.decNwTtl(); |
| 167 | ns = new NeighborSet(nextHops); |
| 168 | } else { |
| 169 | tbuilder.copyTtlOut(); |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 170 | ns = new NeighborSet(nextHops, config.getSegmentId(destSw)); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 171 | } |
| 172 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 173 | TrafficTreatment treatment = tbuilder.build(); |
| 174 | TrafficSelector selector = sbuilder.build(); |
| 175 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 176 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 177 | .builder() |
| 178 | .fromApp(srManager.appId) |
| 179 | .makePermanent() |
| 180 | .nextStep(srManager.getNextObjectiveId(deviceId, ns)) |
| 181 | .withTreatment(treatment) |
| 182 | .withSelector(selector) |
| 183 | .withPriority(100) |
| 184 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 185 | log.debug("Installing IPv4 forwarding objective " |
| 186 | + "for router IP/subnet {} in switch {}", |
| 187 | ipPrefix, |
| 188 | deviceId); |
| 189 | srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 190 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 191 | |
| 192 | return true; |
| 193 | } |
| 194 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 195 | /** |
| 196 | * Populates MPLS flow rules to all transit routers. |
| 197 | * |
| 198 | * @param deviceId device ID of the switch to set the rules |
| 199 | * @param destSwId destination switch device ID |
| 200 | * @param nextHops next hops switch ID list |
| 201 | * @return true if all rules are set successfully, false otherwise |
| 202 | */ |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 203 | public boolean populateMplsRule(DeviceId deviceId, DeviceId destSwId, |
| 204 | Set<DeviceId> nextHops) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 205 | |
| 206 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 207 | List<ForwardingObjective.Builder> fwdObjBuilders = new ArrayList<ForwardingObjective.Builder>(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 208 | |
| 209 | // TODO Handle the case of Bos == false |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 210 | sbuilder.matchMplsLabel(MplsLabel.mplsLabel(config.getSegmentId(destSwId))); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 211 | sbuilder.matchEthType(Ethernet.MPLS_UNICAST); |
| 212 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 213 | // If the next hop is the destination router, do PHP |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 214 | if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 215 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 216 | getMplsForwardingObjective(deviceId, |
| 217 | destSwId, |
| 218 | nextHops, |
| 219 | true, |
| 220 | true); |
| 221 | // TODO: Check with Sangho on why we need this |
| 222 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 223 | getMplsForwardingObjective(deviceId, |
| 224 | destSwId, |
| 225 | nextHops, |
| 226 | true, |
| 227 | false); |
| 228 | if (fwdObjBosBuilder != null) { |
| 229 | fwdObjBuilders.add(fwdObjBosBuilder); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 230 | } else { |
| 231 | log.warn("Failed to set MPLS rules."); |
| 232 | return false; |
| 233 | } |
| 234 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 235 | ForwardingObjective.Builder fwdObjBosBuilder = |
| 236 | getMplsForwardingObjective(deviceId, |
| 237 | destSwId, |
| 238 | nextHops, |
| 239 | false, |
| 240 | true); |
| 241 | // TODO: Check with Sangho on why we need this |
| 242 | ForwardingObjective.Builder fwdObjNoBosBuilder = |
| 243 | getMplsForwardingObjective(deviceId, |
| 244 | destSwId, |
| 245 | nextHops, |
| 246 | false, |
| 247 | false); |
| 248 | if (fwdObjBosBuilder != null) { |
| 249 | fwdObjBuilders.add(fwdObjBosBuilder); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 250 | } else { |
| 251 | log.warn("Failed to set MPLS rules."); |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | TrafficSelector selector = sbuilder.build(); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 257 | for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) { |
| 258 | ((Builder) ((Builder) fwdObjBuilder.fromApp(srManager.appId) |
| 259 | .makePermanent()).withSelector(selector) |
| 260 | .withPriority(100)) |
| 261 | .withFlag(ForwardingObjective.Flag.SPECIFIC); |
| 262 | log.debug("Installing MPLS forwarding objective in switch {}", |
| 263 | deviceId); |
| 264 | srManager.flowObjectiveService.forward(deviceId, |
| 265 | fwdObjBuilder.add()); |
sangho | 20eff1d | 2015-04-13 15:15:58 -0700 | [diff] [blame] | 266 | rulePopulationCounter.incrementAndGet(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | return true; |
| 270 | } |
| 271 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 272 | private ForwardingObjective.Builder getMplsForwardingObjective(DeviceId deviceId, |
| 273 | DeviceId destSw, |
| 274 | Set<DeviceId> nextHops, |
| 275 | boolean phpRequired, |
| 276 | boolean isBos) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 277 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 278 | ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective |
| 279 | .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 280 | |
| 281 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 282 | |
| 283 | if (phpRequired) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 284 | log.debug("getMplsForwardingObjective: php required"); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 285 | tbuilder.copyTtlIn(); |
| 286 | if (isBos) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 287 | tbuilder.popMpls(Ethernet.TYPE_IPV4).decNwTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 288 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 289 | tbuilder.popMpls(Ethernet.MPLS_UNICAST).decMplsTtl(); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 290 | } |
| 291 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 292 | log.debug("getMplsForwardingObjective: php not required"); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 293 | tbuilder.decMplsTtl(); |
| 294 | } |
| 295 | |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 296 | if (!isECMPSupportedInTransitRouter() && !config.isEdgeDevice(deviceId)) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 297 | Link link = selectOneLink(deviceId, nextHops); |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 298 | DeviceId nextHop = (DeviceId) nextHops.toArray()[0]; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 299 | if (link == null) { |
| 300 | log.warn("No link from {} to {}", deviceId, nextHops); |
| 301 | return null; |
| 302 | } |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 303 | tbuilder.setEthSrc(config.getDeviceMac(deviceId)) |
| 304 | .setEthDst(config.getDeviceMac(nextHop)) |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 305 | .setOutput(link.src().port()); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 306 | fwdBuilder.withTreatment(tbuilder.build()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 307 | } else { |
| 308 | NeighborSet ns = new NeighborSet(nextHops); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 309 | fwdBuilder.nextStep(srManager |
| 310 | .getNextObjectiveId(deviceId, ns)); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 313 | return fwdBuilder; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 314 | } |
| 315 | |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 316 | private boolean isECMPSupportedInTransitRouter() { |
| 317 | |
| 318 | // TODO: remove this function when objectives subsystem is supported. |
| 319 | return false; |
| 320 | } |
| 321 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 322 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 323 | * Populates VLAN flows rules. All packets are forwarded to TMAC table. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 324 | * |
| 325 | * @param deviceId switch ID to set the rules |
| 326 | */ |
| 327 | public void populateTableVlan(DeviceId deviceId) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 328 | FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); |
| 329 | fob.withKey(Criteria.matchInPort(PortNumber.ALL)) |
| 330 | .addCondition(Criteria.matchVlanId(VlanId.NONE)); |
| 331 | fob.permit().fromApp(srManager.appId); |
| 332 | log.debug("populateTableVlan: Installing filtering objective for untagged packets"); |
| 333 | srManager.flowObjectiveService.filter(deviceId, fob.add()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 337 | * Populates TMAC table rules. IP packets are forwarded to IP table. MPLS |
| 338 | * packets are forwarded to MPLS table. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 339 | * |
| 340 | * @param deviceId switch ID to set the rules |
| 341 | */ |
| 342 | public void populateTableTMac(DeviceId deviceId) { |
| 343 | |
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.matchEthDst(config |
| 347 | .getDeviceMac(deviceId))); |
| 348 | fob.permit().fromApp(srManager.appId); |
| 349 | log.debug("populateTableVlan: Installing filtering objective for router mac"); |
| 350 | srManager.flowObjectiveService.filter(deviceId, fob.add()); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 351 | } |
| 352 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 353 | private Link selectOneLink(DeviceId srcId, Set<DeviceId> destIds) { |
| 354 | |
| 355 | Set<Link> links = srManager.linkService.getDeviceEgressLinks(srcId); |
| 356 | DeviceId destId = (DeviceId) destIds.toArray()[0]; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 357 | for (Link link : links) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 358 | if (link.dst().deviceId().equals(destId)) { |
| 359 | return link; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return null; |
| 364 | } |
| 365 | |
| 366 | } |