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