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