alshabib | aebe775 | 2015-04-07 17:45:42 -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.driver.pipeline; |
| 17 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 18 | import com.google.common.cache.Cache; |
| 19 | import com.google.common.cache.CacheBuilder; |
| 20 | import com.google.common.cache.RemovalCause; |
| 21 | import com.google.common.cache.RemovalNotification; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 22 | import org.onlab.osgi.ServiceDirectory; |
| 23 | import org.onlab.packet.Ethernet; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 26 | import org.onlab.util.KryoNamespace; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
| 29 | import org.onosproject.net.DeviceId; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 30 | import org.onosproject.net.behaviour.NextGroup; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 31 | import org.onosproject.net.behaviour.Pipeliner; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.PipelinerContext; |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 33 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultFlowRule; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.FlowRule; |
| 38 | import org.onosproject.net.flow.FlowRuleOperations; |
| 39 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 40 | import org.onosproject.net.flow.FlowRuleService; |
| 41 | import org.onosproject.net.flow.TrafficSelector; |
| 42 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.Criteria; |
| 44 | import org.onosproject.net.flow.criteria.Criterion; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 45 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 46 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 47 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 48 | import org.onosproject.net.flowobjective.NextObjective; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 49 | import org.onosproject.net.flowobjective.Objective; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 51 | import org.onosproject.net.group.DefaultGroupBucket; |
| 52 | import org.onosproject.net.group.DefaultGroupDescription; |
| 53 | import org.onosproject.net.group.DefaultGroupKey; |
| 54 | import org.onosproject.net.group.Group; |
| 55 | import org.onosproject.net.group.GroupBucket; |
| 56 | import org.onosproject.net.group.GroupBuckets; |
| 57 | import org.onosproject.net.group.GroupDescription; |
| 58 | import org.onosproject.net.group.GroupEvent; |
| 59 | import org.onosproject.net.group.GroupKey; |
| 60 | import org.onosproject.net.group.GroupListener; |
| 61 | import org.onosproject.net.group.GroupService; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 62 | import org.slf4j.Logger; |
| 63 | |
| 64 | import java.util.Collection; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 65 | import java.util.Collections; |
| 66 | import java.util.Set; |
| 67 | import java.util.concurrent.Executors; |
| 68 | import java.util.concurrent.ScheduledExecutorService; |
| 69 | import java.util.concurrent.TimeUnit; |
| 70 | import java.util.stream.Collectors; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 71 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 72 | import static org.onlab.util.Tools.groupedThreads; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 73 | import static org.slf4j.LoggerFactory.getLogger; |
| 74 | |
| 75 | /** |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 76 | * OpenvSwitch emulation of the Corsa pipeline handler. |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 77 | */ |
Thomas Vachuska | facc3f5 | 2015-04-10 08:58:36 -0700 | [diff] [blame] | 78 | public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeliner { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 79 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 80 | |
| 81 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 82 | protected static final int MAC_TABLE = 0; |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 83 | protected static final int VLAN_MPLS_TABLE = 1; |
| 84 | protected static final int VLAN_TABLE = 2; |
| 85 | //protected static final int MPLS_TABLE = 3; |
| 86 | protected static final int ETHER_TABLE = 4; |
| 87 | protected static final int COS_MAP_TABLE = 5; |
| 88 | protected static final int FIB_TABLE = 6; |
| 89 | protected static final int LOCAL_TABLE = 9; |
| 90 | |
| 91 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 92 | private static final int CONTROLLER_PRIORITY = 255; |
| 93 | private static final int DROP_PRIORITY = 0; |
| 94 | private static final int HIGHEST_PRIORITY = 0xffff; |
| 95 | |
| 96 | private final Logger log = getLogger(getClass()); |
| 97 | |
| 98 | private ServiceDirectory serviceDirectory; |
| 99 | private FlowRuleService flowRuleService; |
| 100 | private CoreService coreService; |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 101 | private GroupService groupService; |
| 102 | private FlowObjectiveStore flowObjectiveStore; |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 103 | private DeviceId deviceId; |
| 104 | private ApplicationId appId; |
| 105 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 106 | private KryoNamespace appKryo = new KryoNamespace.Builder() |
| 107 | .register(GroupKey.class) |
| 108 | .register(DefaultGroupKey.class) |
| 109 | .register(CorsaGroup.class) |
| 110 | .register(byte[].class) |
| 111 | .build(); |
| 112 | |
| 113 | private Cache<GroupKey, NextObjective> pendingGroups; |
| 114 | |
| 115 | private ScheduledExecutorService groupChecker = |
| 116 | Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner", |
| 117 | "ovs-corsa-%d")); |
| 118 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 119 | @Override |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 120 | public void init(DeviceId deviceId, PipelinerContext context) { |
| 121 | this.serviceDirectory = context.directory(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 122 | this.deviceId = deviceId; |
| 123 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 124 | pendingGroups = CacheBuilder.newBuilder() |
| 125 | .expireAfterWrite(20, TimeUnit.SECONDS) |
| 126 | .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> { |
| 127 | if (notification.getCause() == RemovalCause.EXPIRED) { |
| 128 | fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED); |
| 129 | } |
| 130 | }).build(); |
| 131 | |
| 132 | groupChecker.scheduleAtFixedRate(new GroupChecker(), 0, 500, TimeUnit.MILLISECONDS); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 133 | |
| 134 | coreService = serviceDirectory.get(CoreService.class); |
| 135 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 136 | groupService = serviceDirectory.get(GroupService.class); |
| 137 | flowObjectiveStore = context.store(); |
| 138 | |
| 139 | groupService.addListener(new InnerGroupListener()); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 140 | |
| 141 | appId = coreService.registerApplication( |
| 142 | "org.onosproject.driver.OVSCorsaPipeline"); |
| 143 | |
| 144 | pushDefaultRules(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 148 | public void filter(FilteringObjective filteringObjective) { |
| 149 | if (filteringObjective.type() == FilteringObjective.Type.PERMIT) { |
| 150 | processFilter(filteringObjective, |
| 151 | filteringObjective.op() == Objective.Operation.ADD, |
| 152 | filteringObjective.appId()); |
| 153 | } else { |
| 154 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 155 | } |
| 156 | } |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 157 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 158 | @Override |
| 159 | public void forward(ForwardingObjective fwd) { |
| 160 | Collection<FlowRule> rules; |
| 161 | FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder(); |
| 162 | |
| 163 | rules = processForward(fwd); |
| 164 | switch (fwd.op()) { |
| 165 | case ADD: |
| 166 | rules.stream() |
| 167 | .filter(rule -> rule != null) |
| 168 | .forEach(flowBuilder::add); |
| 169 | break; |
| 170 | case REMOVE: |
| 171 | rules.stream() |
| 172 | .filter(rule -> rule != null) |
| 173 | .forEach(flowBuilder::remove); |
| 174 | break; |
| 175 | default: |
| 176 | fail(fwd, ObjectiveError.UNKNOWN); |
| 177 | log.warn("Unknown forwarding type {}", fwd.op()); |
| 178 | } |
| 179 | |
| 180 | |
| 181 | flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() { |
| 182 | @Override |
| 183 | public void onSuccess(FlowRuleOperations ops) { |
| 184 | pass(fwd); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | public void onError(FlowRuleOperations ops) { |
| 189 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 190 | } |
| 191 | })); |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 192 | |
| 193 | } |
| 194 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 195 | @Override |
| 196 | public void next(NextObjective nextObjective) { |
| 197 | switch (nextObjective.type()) { |
| 198 | case SIMPLE: |
| 199 | Collection<TrafficTreatment> treatments = nextObjective.next(); |
| 200 | if (treatments.size() == 1) { |
| 201 | TrafficTreatment treatment = treatments.iterator().next(); |
| 202 | GroupBucket bucket = |
| 203 | DefaultGroupBucket.createIndirectGroupBucket(treatment); |
| 204 | final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id())); |
| 205 | GroupDescription groupDescription |
| 206 | = new DefaultGroupDescription(deviceId, |
| 207 | GroupDescription.Type.INDIRECT, |
| 208 | new GroupBuckets(Collections |
| 209 | .singletonList(bucket)), |
| 210 | key, |
| 211 | nextObjective.appId()); |
| 212 | groupService.addGroup(groupDescription); |
| 213 | pendingGroups.put(key, nextObjective); |
| 214 | } |
| 215 | break; |
| 216 | case HASHED: |
| 217 | case BROADCAST: |
| 218 | case FAILOVER: |
| 219 | fail(nextObjective, ObjectiveError.UNSUPPORTED); |
| 220 | log.warn("Unsupported next objective type {}", nextObjective.type()); |
| 221 | break; |
| 222 | default: |
| 223 | fail(nextObjective, ObjectiveError.UNKNOWN); |
| 224 | log.warn("Unknown next objective type {}", nextObjective.type()); |
| 225 | } |
| 226 | |
| 227 | } |
| 228 | |
| 229 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 230 | switch (fwd.flag()) { |
| 231 | case SPECIFIC: |
| 232 | return processSpecific(fwd); |
| 233 | case VERSATILE: |
| 234 | return processVersatile(fwd); |
| 235 | default: |
| 236 | fail(fwd, ObjectiveError.UNKNOWN); |
| 237 | log.warn("Unknown forwarding flag {}", fwd.flag()); |
| 238 | } |
| 239 | return Collections.emptySet(); |
| 240 | } |
| 241 | |
| 242 | private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 243 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 244 | return Collections.emptySet(); |
| 245 | } |
| 246 | |
| 247 | private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { |
| 248 | log.warn("Processing specific"); |
| 249 | TrafficSelector selector = fwd.selector(); |
| 250 | Criteria.EthTypeCriterion ethType = |
| 251 | (Criteria.EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 252 | if (ethType == null || ethType.ethType() != Ethernet.TYPE_IPV4) { |
| 253 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 254 | return Collections.emptySet(); |
| 255 | } |
| 256 | |
| 257 | TrafficSelector filteredSelector = |
| 258 | DefaultTrafficSelector.builder() |
| 259 | .matchEthType(Ethernet.TYPE_IPV4) |
| 260 | .matchIPDst( |
| 261 | ((Criteria.IPCriterion) |
| 262 | selector.getCriterion(Criterion.Type.IPV4_DST)).ip()) |
| 263 | .build(); |
| 264 | |
| 265 | NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId()); |
| 266 | |
| 267 | GroupKey key = appKryo.deserialize(next.data()); |
| 268 | |
| 269 | Group group = groupService.getGroup(deviceId, key); |
| 270 | |
| 271 | if (group == null) { |
| 272 | log.warn("The group left!"); |
| 273 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 274 | return Collections.emptySet(); |
| 275 | } |
| 276 | |
| 277 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 278 | .group(group.id()) |
| 279 | .build(); |
| 280 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 281 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 282 | .fromApp(fwd.appId()) |
| 283 | .withPriority(fwd.priority()) |
| 284 | .forDevice(deviceId) |
| 285 | .withSelector(filteredSelector) |
| 286 | .withTreatment(treatment); |
| 287 | |
| 288 | if (fwd.permanent()) { |
| 289 | ruleBuilder.makePermanent(); |
| 290 | } else { |
| 291 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 292 | } |
| 293 | |
| 294 | ruleBuilder.forTable(FIB_TABLE); |
| 295 | |
| 296 | |
| 297 | return Collections.singletonList(ruleBuilder.build()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 298 | |
| 299 | } |
| 300 | |
| 301 | private void processFilter(FilteringObjective filt, boolean install, |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 302 | ApplicationId applicationId) { |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 303 | // This driver only processes filtering criteria defined with switch |
| 304 | // ports as the key |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 305 | Criteria.PortCriterion p; |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 306 | if (!filt.key().equals(Criteria.dummy()) && |
| 307 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 308 | p = (Criteria.PortCriterion) filt.key(); |
| 309 | } else { |
| 310 | log.warn("No key defined in filtering objective from app: {}. Not" |
| 311 | + "processing filtering objective", applicationId); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 312 | fail(filt, ObjectiveError.UNKNOWN); |
| 313 | return; |
alshabib | 910aff1 | 2015-04-09 16:55:57 -0700 | [diff] [blame] | 314 | } |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 315 | // convert filtering conditions for switch-intfs into flowrules |
| 316 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 317 | for (Criterion c : filt.conditions()) { |
| 318 | if (c.type() == Criterion.Type.ETH_DST) { |
| 319 | Criteria.EthCriterion e = (Criteria.EthCriterion) c; |
| 320 | log.debug("adding rule for MAC: {}", e.mac()); |
| 321 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 322 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 323 | selector.matchEthDst(e.mac()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 324 | treatment.transition(VLAN_MPLS_TABLE); |
| 325 | FlowRule rule = DefaultFlowRule.builder() |
| 326 | .forDevice(deviceId) |
| 327 | .withSelector(selector.build()) |
| 328 | .withTreatment(treatment.build()) |
| 329 | .withPriority(CONTROLLER_PRIORITY) |
| 330 | .fromApp(applicationId) |
| 331 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 332 | .forTable(MAC_TABLE).build(); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 333 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 334 | } else if (c.type() == Criterion.Type.VLAN_VID) { |
| 335 | Criteria.VlanIdCriterion v = (Criteria.VlanIdCriterion) c; |
| 336 | log.debug("adding rule for VLAN: {}", v.vlanId()); |
| 337 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 338 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 339 | selector.matchVlanId(v.vlanId()); |
| 340 | selector.matchInPort(p.port()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 341 | treatment.transition(ETHER_TABLE); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 342 | treatment.deferred().popVlan(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 343 | FlowRule rule = DefaultFlowRule.builder() |
| 344 | .forDevice(deviceId) |
| 345 | .withSelector(selector.build()) |
| 346 | .withTreatment(treatment.build()) |
| 347 | .withPriority(CONTROLLER_PRIORITY) |
| 348 | .fromApp(applicationId) |
| 349 | .makePermanent() |
| 350 | .forTable(VLAN_TABLE).build(); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 351 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 352 | } else if (c.type() == Criterion.Type.IPV4_DST) { |
| 353 | Criteria.IPCriterion ip = (Criteria.IPCriterion) c; |
| 354 | log.debug("adding rule for IP: {}", ip.ip()); |
| 355 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 356 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 357 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 358 | selector.matchIPDst(ip.ip()); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 359 | treatment.transition(LOCAL_TABLE); |
| 360 | FlowRule rule = DefaultFlowRule.builder() |
| 361 | .forDevice(deviceId) |
| 362 | .withSelector(selector.build()) |
| 363 | .withTreatment(treatment.build()) |
| 364 | .withPriority(HIGHEST_PRIORITY) |
| 365 | .fromApp(applicationId) |
| 366 | .makePermanent() |
| 367 | .forTable(FIB_TABLE).build(); |
| 368 | |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 369 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 370 | } else { |
| 371 | log.warn("Driver does not currently process filtering condition" |
| 372 | + " of type: {}", c.type()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 373 | fail(filt, ObjectiveError.UNSUPPORTED); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | // apply filtering flow rules |
| 377 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 378 | @Override |
| 379 | public void onSuccess(FlowRuleOperations ops) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 380 | pass(filt); |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 381 | log.info("Applied filtering rules"); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void onError(FlowRuleOperations ops) { |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 386 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 387 | log.info("Failed to apply filtering rules"); |
Saurav Das | cfd63d2 | 2015-04-13 16:08:24 -0700 | [diff] [blame] | 388 | } |
| 389 | })); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 390 | } |
| 391 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 392 | private void pass(Objective obj) { |
| 393 | if (obj.context().isPresent()) { |
| 394 | obj.context().get().onSuccess(obj); |
| 395 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 396 | } |
| 397 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 398 | private void fail(Objective obj, ObjectiveError error) { |
| 399 | if (obj.context().isPresent()) { |
| 400 | obj.context().get().onError(obj, error); |
| 401 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 402 | } |
| 403 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 404 | private void pushDefaultRules() { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 405 | processMacTable(true); |
| 406 | processVlanMplsTable(true); |
| 407 | processVlanTable(true); |
| 408 | processEtherTable(true); |
| 409 | processCosTable(true); |
| 410 | processFibTable(true); |
| 411 | processLocalTable(true); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 414 | private void processMacTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 415 | TrafficSelector.Builder selector; |
| 416 | TrafficTreatment.Builder treatment; |
| 417 | |
| 418 | // Bcast rule |
| 419 | selector = DefaultTrafficSelector.builder(); |
| 420 | treatment = DefaultTrafficTreatment.builder(); |
| 421 | |
| 422 | selector.matchEthDst(MacAddress.BROADCAST); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 423 | treatment.transition(VLAN_MPLS_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 424 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 425 | FlowRule rule = DefaultFlowRule.builder() |
| 426 | .forDevice(deviceId) |
| 427 | .withSelector(selector.build()) |
| 428 | .withTreatment(treatment.build()) |
| 429 | .withPriority(CONTROLLER_PRIORITY) |
| 430 | .fromApp(appId) |
| 431 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 432 | .forTable(MAC_TABLE).build(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 433 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 434 | |
| 435 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 436 | |
| 437 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 438 | |
| 439 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 440 | //Drop rule |
| 441 | selector = DefaultTrafficSelector.builder(); |
| 442 | treatment = DefaultTrafficTreatment.builder(); |
| 443 | |
| 444 | treatment.drop(); |
| 445 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 446 | rule = DefaultFlowRule.builder() |
| 447 | .forDevice(deviceId) |
| 448 | .withSelector(selector.build()) |
| 449 | .withTreatment(treatment.build()) |
| 450 | .withPriority(DROP_PRIORITY) |
| 451 | .fromApp(appId) |
| 452 | .makePermanent() |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 453 | .forTable(MAC_TABLE).build(); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 454 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 455 | |
| 456 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 457 | |
| 458 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 459 | @Override |
| 460 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 461 | log.info("Provisioned mac table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 466 | log.info("Failed to provision mac table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 467 | } |
| 468 | })); |
| 469 | |
| 470 | } |
| 471 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 472 | private void processVlanMplsTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 473 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 474 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 475 | .builder(); |
| 476 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 477 | FlowRule rule; |
| 478 | |
| 479 | selector.matchVlanId(VlanId.ANY); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 480 | treatment.transition(VLAN_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 481 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 482 | rule = DefaultFlowRule.builder() |
| 483 | .forDevice(deviceId) |
| 484 | .withSelector(selector.build()) |
| 485 | .withTreatment(treatment.build()) |
| 486 | .withPriority(CONTROLLER_PRIORITY) |
| 487 | .fromApp(appId) |
| 488 | .makePermanent() |
| 489 | .forTable(VLAN_MPLS_TABLE).build(); |
| 490 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 491 | |
| 492 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 493 | |
| 494 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 495 | @Override |
| 496 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 497 | log.info("Provisioned vlan/mpls table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | @Override |
| 501 | public void onError(FlowRuleOperations ops) { |
| 502 | log.info( |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 503 | "Failed to provision vlan/mpls table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 504 | } |
| 505 | })); |
| 506 | |
| 507 | } |
| 508 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 509 | private void processVlanTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 510 | TrafficSelector.Builder selector; |
| 511 | TrafficTreatment.Builder treatment; |
| 512 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 513 | FlowRule rule; |
| 514 | |
| 515 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 516 | //Drop rule |
| 517 | selector = DefaultTrafficSelector.builder(); |
| 518 | treatment = DefaultTrafficTreatment.builder(); |
| 519 | |
| 520 | treatment.drop(); |
| 521 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 522 | rule = DefaultFlowRule.builder() |
| 523 | .forDevice(deviceId) |
| 524 | .withSelector(selector.build()) |
| 525 | .withTreatment(treatment.build()) |
| 526 | .withPriority(DROP_PRIORITY) |
| 527 | .fromApp(appId) |
| 528 | .makePermanent() |
| 529 | .forTable(VLAN_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 530 | |
| 531 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 532 | |
| 533 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 534 | @Override |
| 535 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 536 | log.info("Provisioned vlan table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | @Override |
| 540 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 541 | log.info("Failed to provision vlan table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 542 | } |
| 543 | })); |
| 544 | } |
| 545 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 546 | private void processEtherTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 547 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 548 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 549 | .builder(); |
| 550 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 551 | FlowRule rule; |
| 552 | |
| 553 | selector.matchEthType(Ethernet.TYPE_ARP); |
| 554 | treatment.punt(); |
| 555 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 556 | rule = DefaultFlowRule.builder() |
| 557 | .forDevice(deviceId) |
| 558 | .withSelector(selector.build()) |
| 559 | .withTreatment(treatment.build()) |
| 560 | .withPriority(CONTROLLER_PRIORITY) |
| 561 | .fromApp(appId) |
| 562 | .makePermanent() |
| 563 | .forTable(ETHER_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 564 | |
| 565 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 566 | |
| 567 | selector = DefaultTrafficSelector.builder(); |
| 568 | treatment = DefaultTrafficTreatment.builder(); |
| 569 | |
| 570 | selector.matchEthType(Ethernet.TYPE_IPV4); |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 571 | treatment.transition(COS_MAP_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 572 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 573 | rule = DefaultFlowRule.builder() |
| 574 | .forDevice(deviceId) |
| 575 | .withPriority(CONTROLLER_PRIORITY) |
| 576 | .withSelector(selector.build()) |
| 577 | .withTreatment(treatment.build()) |
| 578 | .fromApp(appId) |
| 579 | .makePermanent() |
| 580 | .forTable(ETHER_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 581 | |
| 582 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 583 | |
| 584 | //Drop rule |
| 585 | selector = DefaultTrafficSelector.builder(); |
| 586 | treatment = DefaultTrafficTreatment.builder(); |
| 587 | |
| 588 | treatment.drop(); |
| 589 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 590 | rule = DefaultFlowRule.builder() |
| 591 | .forDevice(deviceId) |
| 592 | .withSelector(selector.build()) |
| 593 | .withTreatment(treatment.build()) |
| 594 | .withPriority(DROP_PRIORITY) |
| 595 | .fromApp(appId) |
| 596 | .makePermanent() |
| 597 | .forTable(ETHER_TABLE).build(); |
| 598 | |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 599 | |
| 600 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 601 | |
| 602 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 603 | @Override |
| 604 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 605 | log.info("Provisioned ether table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 610 | log.info("Failed to provision ether table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 611 | } |
| 612 | })); |
| 613 | |
| 614 | } |
| 615 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 616 | private void processCosTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 617 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 618 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 619 | .builder(); |
| 620 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 621 | FlowRule rule; |
| 622 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 623 | treatment.transition(FIB_TABLE); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 624 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 625 | rule = DefaultFlowRule.builder() |
| 626 | .forDevice(deviceId) |
| 627 | .withSelector(selector.build()) |
| 628 | .withTreatment(treatment.build()) |
| 629 | .withPriority(DROP_PRIORITY) |
| 630 | .fromApp(appId) |
| 631 | .makePermanent() |
| 632 | .forTable(COS_MAP_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 633 | |
| 634 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 635 | |
| 636 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 637 | @Override |
| 638 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 639 | log.info("Provisioned cos table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | @Override |
| 643 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 644 | log.info("Failed to provision cos table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 645 | } |
| 646 | })); |
| 647 | |
| 648 | } |
| 649 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 650 | private void processFibTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 651 | TrafficSelector.Builder selector; |
| 652 | TrafficTreatment.Builder treatment; |
| 653 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 654 | FlowRule rule; |
| 655 | |
| 656 | //Drop rule |
| 657 | selector = DefaultTrafficSelector.builder(); |
| 658 | treatment = DefaultTrafficTreatment.builder(); |
| 659 | |
| 660 | treatment.drop(); |
| 661 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 662 | rule = DefaultFlowRule.builder() |
| 663 | .forDevice(deviceId) |
| 664 | .withSelector(selector.build()) |
| 665 | .withTreatment(treatment.build()) |
| 666 | .withPriority(DROP_PRIORITY) |
| 667 | .fromApp(appId) |
| 668 | .makePermanent() |
| 669 | .forTable(FIB_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 670 | |
| 671 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 672 | |
| 673 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 674 | @Override |
| 675 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 676 | log.info("Provisioned FIB table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | @Override |
| 680 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 681 | log.info("Failed to provision FIB table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 682 | } |
| 683 | })); |
| 684 | } |
| 685 | |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 686 | private void processLocalTable(boolean install) { |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 687 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 688 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment |
| 689 | .builder(); |
| 690 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 691 | FlowRule rule; |
| 692 | |
| 693 | treatment.punt(); |
| 694 | |
alshabib | d17abc2 | 2015-04-21 18:26:35 -0700 | [diff] [blame] | 695 | rule = DefaultFlowRule.builder() |
| 696 | .forDevice(deviceId) |
| 697 | .withSelector(selector.build()) |
| 698 | .withTreatment(treatment.build()) |
| 699 | .withPriority(CONTROLLER_PRIORITY) |
| 700 | .fromApp(appId) |
| 701 | .makePermanent() |
| 702 | .forTable(LOCAL_TABLE).build(); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 703 | |
| 704 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 705 | |
| 706 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 707 | @Override |
| 708 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 709 | log.info("Provisioned Local table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | @Override |
| 713 | public void onError(FlowRuleOperations ops) { |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 714 | log.info("Failed to provision Local table"); |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 715 | } |
| 716 | })); |
| 717 | } |
| 718 | |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 719 | private class InnerGroupListener implements GroupListener { |
| 720 | @Override |
| 721 | public void event(GroupEvent event) { |
| 722 | if (event.type() == GroupEvent.Type.GROUP_ADDED) { |
| 723 | GroupKey key = event.subject().appCookie(); |
| 724 | |
| 725 | NextObjective obj = pendingGroups.getIfPresent(key); |
| 726 | if (obj != null) { |
| 727 | flowObjectiveStore.putNextGroup(obj.id(), new CorsaGroup(key)); |
| 728 | pass(obj); |
| 729 | pendingGroups.invalidate(key); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | |
| 736 | private class GroupChecker implements Runnable { |
| 737 | |
| 738 | @Override |
| 739 | public void run() { |
| 740 | Set<GroupKey> keys = pendingGroups.asMap().keySet().stream() |
| 741 | .filter(key -> groupService.getGroup(deviceId, key) != null) |
| 742 | .collect(Collectors.toSet()); |
| 743 | |
| 744 | keys.stream().forEach(key -> { |
| 745 | NextObjective obj = pendingGroups.getIfPresent(key); |
| 746 | if (obj == null) { |
| 747 | return; |
| 748 | } |
| 749 | pass(obj); |
| 750 | pendingGroups.invalidate(key); |
Saurav Das | 3ea4662 | 2015-04-22 14:01:34 -0700 | [diff] [blame] | 751 | log.info("Heard back from group service for group {}", obj.id()); |
alshabib | 2a441c6 | 2015-04-13 18:39:38 -0700 | [diff] [blame] | 752 | flowObjectiveStore.putNextGroup(obj.id(), new CorsaGroup(key)); |
| 753 | }); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | private class CorsaGroup implements NextGroup { |
| 758 | |
| 759 | private final GroupKey key; |
| 760 | |
| 761 | public CorsaGroup(GroupKey key) { |
| 762 | this.key = key; |
| 763 | } |
| 764 | |
| 765 | public GroupKey key() { |
| 766 | return key; |
| 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public byte[] data() { |
| 771 | return appKryo.serialize(key); |
| 772 | } |
| 773 | |
| 774 | } |
alshabib | aebe775 | 2015-04-07 17:45:42 -0700 | [diff] [blame] | 775 | } |