blob: ed9794c03c6a38883567f8e95c6a9054ff4e4623 [file] [log] [blame]
Saurav Dase3274c82015-05-24 17:21:56 -07001package org.onosproject.driver.pipeline;
2
3
4import com.google.common.cache.Cache;
5import com.google.common.cache.CacheBuilder;
6import com.google.common.cache.RemovalCause;
7import com.google.common.cache.RemovalNotification;
8
9import org.onlab.osgi.ServiceDirectory;
10import org.onlab.packet.Ethernet;
11import org.onlab.packet.IPv4;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070012import org.onlab.packet.TpPort;
Saurav Dase3274c82015-05-24 17:21:56 -070013import org.onlab.packet.VlanId;
14import org.onlab.util.KryoNamespace;
15import org.onosproject.core.ApplicationId;
16import org.onosproject.core.CoreService;
17import org.onosproject.net.DeviceId;
Saurav Das6c44a632015-05-30 22:05:22 -070018import org.onosproject.net.PortNumber;
Saurav Dase3274c82015-05-24 17:21:56 -070019import org.onosproject.net.behaviour.NextGroup;
20import org.onosproject.net.behaviour.Pipeliner;
21import org.onosproject.net.behaviour.PipelinerContext;
22import org.onosproject.net.driver.AbstractHandlerBehaviour;
23import org.onosproject.net.flow.DefaultFlowRule;
24import org.onosproject.net.flow.DefaultTrafficSelector;
25import org.onosproject.net.flow.DefaultTrafficTreatment;
26import org.onosproject.net.flow.FlowRule;
27import org.onosproject.net.flow.FlowRuleOperations;
28import org.onosproject.net.flow.FlowRuleOperationsContext;
29import org.onosproject.net.flow.FlowRuleService;
30import org.onosproject.net.flow.TrafficSelector;
31import org.onosproject.net.flow.TrafficTreatment;
32import org.onosproject.net.flow.criteria.Criterion;
33import org.onosproject.net.flow.criteria.Criteria;
34import org.onosproject.net.flow.criteria.EthCriterion;
35import org.onosproject.net.flow.criteria.PortCriterion;
36import org.onosproject.net.flow.criteria.EthTypeCriterion;
37import org.onosproject.net.flow.criteria.IPCriterion;
38import org.onosproject.net.flow.criteria.VlanIdCriterion;
39import org.onosproject.net.flow.instructions.Instruction;
40import org.onosproject.net.flow.instructions.L2ModificationInstruction;
41import org.onosproject.net.flowobjective.FilteringObjective;
42import org.onosproject.net.flowobjective.FlowObjectiveStore;
43import org.onosproject.net.flowobjective.ForwardingObjective;
44import org.onosproject.net.flowobjective.NextObjective;
45import org.onosproject.net.flowobjective.Objective;
46import org.onosproject.net.flowobjective.ObjectiveError;
47import org.onosproject.net.group.DefaultGroupBucket;
48import org.onosproject.net.group.DefaultGroupDescription;
49import org.onosproject.net.group.DefaultGroupKey;
50import org.onosproject.net.group.Group;
51import org.onosproject.net.group.GroupBucket;
52import org.onosproject.net.group.GroupBuckets;
53import org.onosproject.net.group.GroupDescription;
54import org.onosproject.net.group.GroupEvent;
55import org.onosproject.net.group.GroupKey;
56import org.onosproject.net.group.GroupListener;
57import org.onosproject.net.group.GroupService;
58import org.slf4j.Logger;
59
60import java.util.Collection;
61import java.util.Collections;
62import java.util.Set;
63import java.util.concurrent.Executors;
64import java.util.concurrent.ScheduledExecutorService;
65import java.util.concurrent.TimeUnit;
66import java.util.stream.Collectors;
67
68import static org.onlab.util.Tools.groupedThreads;
69import static org.slf4j.LoggerFactory.getLogger;
70
71/**
72 * Driver for Centec's V350 switches.
73 */
74public class CentecV350Pipeline extends AbstractHandlerBehaviour implements Pipeliner {
75
76 protected static final int PORT_VLAN_TABLE = 0;
77 protected static final int FILTER_TABLE = 1;
78 // TMAC is configured in MAC Table to redirect packets to ROUTE_TABLE.
79 protected static final int MAC_TABLE = 2;
80 protected static final int ROUTE_TABLE = 3;
81
82 private static final long DEFAULT_METADATA = 100;
Saurav Das6c44a632015-05-30 22:05:22 -070083 private static final long DEFAULT_METADATA_MASK = 0xffffffffffffffffL;
Saurav Dase3274c82015-05-24 17:21:56 -070084
85 // Priority used in PORT_VLAN Table, the only priority accepted is PORT_VLAN_TABLE_PRIORITY.
86 // The packet passed PORT+VLAN check will goto FILTER Table.
87 private static final int PORT_VLAN_TABLE_PRIORITY = 0xffff;
88
89 // Priority used in Filter Table.
90 private static final int FILTER_TABLE_CONTROLLER_PRIORITY = 500;
91 // TMAC priority should be lower than controller.
92 private static final int FILTER_TABLE_TMAC_PRIORITY = 200;
93 private static final int FILTER_TABLE_HIGHEST_PRIORITY = 0xffff;
94
95 // Priority used in MAC Table.
96 // We do exact matching for DMAC+metadata, so priority is ignored and required to be set to 0xffff.
97 private static final int MAC_TABLE_PRIORITY = 0xffff;
98
99 // Priority used in Route Table.
100 // We do LPM matching in Route Table, so priority is ignored and required to be set to 0xffff.
101 private static final int ROUTE_TABLE_PRIORITY = 0xffff;
102
103 private static final short BGP_PORT = 179;
104
105 private final Logger log = getLogger(getClass());
106
107 private ServiceDirectory serviceDirectory;
108 private FlowRuleService flowRuleService;
109 private CoreService coreService;
110 private GroupService groupService;
111 private FlowObjectiveStore flowObjectiveStore;
112 private DeviceId deviceId;
113 private ApplicationId appId;
114
115 private KryoNamespace appKryo = new KryoNamespace.Builder()
116 .register(GroupKey.class)
117 .register(DefaultGroupKey.class)
118 .register(CentecV350Group.class)
119 .register(byte[].class)
120 .build();
121
122 private Cache<GroupKey, NextObjective> pendingGroups;
123
124 private ScheduledExecutorService groupChecker =
125 Executors.newScheduledThreadPool(2, groupedThreads("onos/pipeliner",
126 "centec-V350-%d"));
127
128 @Override
129 public void init(DeviceId deviceId, PipelinerContext context) {
130 this.serviceDirectory = context.directory();
131 this.deviceId = deviceId;
132
133 pendingGroups = CacheBuilder.newBuilder()
134 .expireAfterWrite(20, TimeUnit.SECONDS)
135 .removalListener((RemovalNotification<GroupKey, NextObjective> notification) -> {
136 if (notification.getCause() == RemovalCause.EXPIRED) {
137 fail(notification.getValue(), ObjectiveError.GROUPINSTALLATIONFAILED);
138 }
139 }).build();
140
141 groupChecker.scheduleAtFixedRate(new GroupChecker(), 0, 500, TimeUnit.MILLISECONDS);
142
143 coreService = serviceDirectory.get(CoreService.class);
144 flowRuleService = serviceDirectory.get(FlowRuleService.class);
145 groupService = serviceDirectory.get(GroupService.class);
146 flowObjectiveStore = context.store();
147
148 groupService.addListener(new InnerGroupListener());
149
150 appId = coreService.registerApplication(
151 "org.onosproject.driver.CentecV350Pipeline");
152
153 initializePipeline();
154 }
155
156 @Override
157 public void filter(FilteringObjective filteringObjective) {
158 if (filteringObjective.type() == FilteringObjective.Type.PERMIT) {
159 processFilter(filteringObjective,
160 filteringObjective.op() == Objective.Operation.ADD,
161 filteringObjective.appId());
162 } else {
163 fail(filteringObjective, ObjectiveError.UNSUPPORTED);
164 }
165 }
166
167 @Override
168 public void forward(ForwardingObjective fwd) {
169 Collection<FlowRule> rules;
170 FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
171
172 rules = processForward(fwd);
173 switch (fwd.op()) {
174 case ADD:
175 rules.stream()
176 .filter(rule -> rule != null)
177 .forEach(flowBuilder::add);
178 break;
179 case REMOVE:
180 rules.stream()
181 .filter(rule -> rule != null)
182 .forEach(flowBuilder::remove);
183 break;
184 default:
185 fail(fwd, ObjectiveError.UNKNOWN);
186 log.warn("Unknown forwarding type {}", fwd.op());
187 }
188
189
190 flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
191 @Override
192 public void onSuccess(FlowRuleOperations ops) {
193 pass(fwd);
194 }
195
196 @Override
197 public void onError(FlowRuleOperations ops) {
198 fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
199 }
200 }));
201
202 }
203
204 @Override
205 public void next(NextObjective nextObjective) {
206 switch (nextObjective.type()) {
207 case SIMPLE:
208 Collection<TrafficTreatment> treatments = nextObjective.next();
209 if (treatments.size() == 1) {
210 TrafficTreatment treatment = treatments.iterator().next();
211
212 // Since we do not support strip_vlan in PORT_VLAN table, we use mod_vlan
213 // to modify the packet to desired vlan.
214 // Note: if we use push_vlan here, the switch will add a second VLAN tag to the outgoing
215 // packet, which is not what we want.
216 TrafficTreatment.Builder treatmentWithoutPushVlan = DefaultTrafficTreatment.builder();
217 VlanId modVlanId;
218 for (Instruction ins : treatment.allInstructions()) {
219 if (ins.type() == Instruction.Type.L2MODIFICATION) {
220 L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
221 switch (l2ins.subtype()) {
222 case ETH_DST:
223 treatmentWithoutPushVlan.setEthDst(
224 ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
225 break;
226 case ETH_SRC:
227 treatmentWithoutPushVlan.setEthSrc(
228 ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
229 break;
230 case VLAN_ID:
231 modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
232 treatmentWithoutPushVlan.setVlanId(modVlanId);
233 break;
234 default:
235 break;
236 }
237 } else if (ins.type() == Instruction.Type.OUTPUT) {
238 //long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
239 treatmentWithoutPushVlan.add(ins);
240 } else {
241 // Ignore the vlan_pcp action since it's does matter much.
242 log.warn("Driver does not handle this type of TrafficTreatment"
243 + " instruction in nextObjectives: {}", ins.type());
244 }
245 }
246
247 GroupBucket bucket =
248 DefaultGroupBucket.createIndirectGroupBucket(treatmentWithoutPushVlan.build());
249 final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
250 GroupDescription groupDescription
251 = new DefaultGroupDescription(deviceId,
252 GroupDescription.Type.INDIRECT,
253 new GroupBuckets(Collections
254 .singletonList(bucket)),
255 key,
256 null, // let group service determine group id
257 nextObjective.appId());
258 groupService.addGroup(groupDescription);
259 pendingGroups.put(key, nextObjective);
260 }
261 break;
262 case HASHED:
263 case BROADCAST:
264 case FAILOVER:
265 fail(nextObjective, ObjectiveError.UNSUPPORTED);
266 log.warn("Unsupported next objective type {}", nextObjective.type());
267 break;
268 default:
269 fail(nextObjective, ObjectiveError.UNKNOWN);
270 log.warn("Unknown next objective type {}", nextObjective.type());
271 }
272
273 }
274
275 private Collection<FlowRule> processForward(ForwardingObjective fwd) {
276 switch (fwd.flag()) {
277 case SPECIFIC:
278 return processSpecific(fwd);
279 case VERSATILE:
280 return processVersatile(fwd);
281 default:
282 fail(fwd, ObjectiveError.UNKNOWN);
283 log.warn("Unknown forwarding flag {}", fwd.flag());
284 }
285 return Collections.emptySet();
286 }
287
288 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
289 log.warn("Driver does not support versatile forwarding objective");
290 fail(fwd, ObjectiveError.UNSUPPORTED);
291 return Collections.emptySet();
292 }
293
294 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
295 log.debug("Processing specific forwarding objective");
296 TrafficSelector selector = fwd.selector();
297 EthTypeCriterion ethType =
298 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
alshabibcaf1ca22015-06-25 15:18:16 -0700299 if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
Saurav Dase3274c82015-05-24 17:21:56 -0700300 fail(fwd, ObjectiveError.UNSUPPORTED);
301 return Collections.emptySet();
302 }
303
304 // Must have metadata as key.
305 TrafficSelector filteredSelector =
306 DefaultTrafficSelector.builder()
307 .matchEthType(Ethernet.TYPE_IPV4)
308 .matchMetadata(DEFAULT_METADATA)
309 .matchIPDst(
310 ((IPCriterion)
311 selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
312 .build();
313
314 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
315
316 if (fwd.nextId() != null) {
317 NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
318 GroupKey key = appKryo.deserialize(next.data());
319 Group group = groupService.getGroup(deviceId, key);
320 if (group == null) {
321 log.warn("The group left!");
322 fail(fwd, ObjectiveError.GROUPMISSING);
323 return Collections.emptySet();
324 }
325 tb.group(group.id());
326 }
327
328 FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
329 .fromApp(fwd.appId())
330 .withPriority(ROUTE_TABLE_PRIORITY)
331 .forDevice(deviceId)
332 .withSelector(filteredSelector)
333 .withTreatment(tb.build());
334
335 if (fwd.permanent()) {
336 ruleBuilder.makePermanent();
337 } else {
338 ruleBuilder.makeTemporary(fwd.timeout());
339 }
340
341 ruleBuilder.forTable(ROUTE_TABLE);
342
343 return Collections.singletonList(ruleBuilder.build());
344
345 }
346
347 private void processFilter(FilteringObjective filt, boolean install,
348 ApplicationId applicationId) {
349 PortCriterion p;
350 if (!filt.key().equals(Criteria.dummy()) &&
351 filt.key().type() == Criterion.Type.IN_PORT) {
352 p = (PortCriterion) filt.key();
353 } else {
354 log.warn("No key defined in filtering objective from app: {}. Not"
355 + "processing filtering objective", applicationId);
356 fail(filt, ObjectiveError.UNKNOWN);
357 return;
358 }
359
360 // Convert filtering conditions for switch-intfs into flow rules.
361 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
362
363 for (Criterion c : filt.conditions()) {
364 // Here we do a trick to install 2 flow rules to MAC_TABLE and ROUTE_TABLE.
365 if (c.type() == Criterion.Type.ETH_DST) {
366 EthCriterion e = (EthCriterion) c;
367
368 // Install TMAC flow rule.
369 log.debug("adding rule for Termination MAC in Filter Table: {}", e.mac());
370 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
371 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
372 selector.matchEthDst(e.mac());
373 // Add IPv4 matching explicitly since we will redirect it to ROUTE Table
374 // through MAC table.
375 selector.matchEthType(Ethernet.TYPE_IPV4);
376 treatment.transition(MAC_TABLE);
377 FlowRule rule = DefaultFlowRule.builder()
378 .forDevice(deviceId)
379 .withSelector(selector.build())
380 .withTreatment(treatment.build())
381 .withPriority(FILTER_TABLE_TMAC_PRIORITY)
382 .fromApp(applicationId)
383 .makePermanent()
384 .forTable(FILTER_TABLE).build();
385 ops = install ? ops.add(rule) : ops.remove(rule);
386
387 // Must install another rule to direct the IPv4 packets that hit TMAC to
388 // Route table.
389 log.debug("adding rule for Termination MAC in MAC Table: {}", e.mac());
390 selector = DefaultTrafficSelector.builder();
391 treatment = DefaultTrafficTreatment.builder();
392 selector.matchEthDst(e.mac());
393 // MAC_Table must have metadata matching configured, use the default metadata.
394 selector.matchMetadata(DEFAULT_METADATA);
395 treatment.transition(ROUTE_TABLE);
396 rule = DefaultFlowRule.builder()
397 .forDevice(deviceId)
398 .withSelector(selector.build())
399 .withTreatment(treatment.build())
400 .withPriority(MAC_TABLE_PRIORITY)
401 .fromApp(applicationId)
402 .makePermanent()
403 .forTable(MAC_TABLE).build();
404 ops = install ? ops.add(rule) : ops.remove(rule);
405 } else if (c.type() == Criterion.Type.VLAN_VID) {
406 VlanIdCriterion v = (VlanIdCriterion) c;
407 log.debug("adding rule for VLAN: {}", v.vlanId());
408 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
409 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
410 selector.matchVlanId(v.vlanId());
411 selector.matchInPort(p.port());
412 // Although the accepted packets will be sent to filter table, we must
413 // explicitly set goto_table instruction here.
Saurav Das86af8f12015-05-25 23:55:33 -0700414 treatment.writeMetadata(DEFAULT_METADATA, DEFAULT_METADATA_MASK);
415 // set default metadata written by PORT_VLAN Table.
Saurav Dase3274c82015-05-24 17:21:56 -0700416 treatment.transition(FILTER_TABLE);
417 // We do not support strip vlan here, treatment.deferred().popVlan();
Saurav Dase3274c82015-05-24 17:21:56 -0700418 // PORT_VLAN table only accept 0xffff priority since it does exact match only.
419 FlowRule rule = DefaultFlowRule.builder()
420 .forDevice(deviceId)
421 .withSelector(selector.build())
422 .withTreatment(treatment.build())
423 .withPriority(PORT_VLAN_TABLE_PRIORITY)
424 .fromApp(applicationId)
425 .makePermanent()
426 .forTable(PORT_VLAN_TABLE).build();
427 ops = install ? ops.add(rule) : ops.remove(rule);
428 } else if (c.type() == Criterion.Type.IPV4_DST) {
Saurav Das6c44a632015-05-30 22:05:22 -0700429 IPCriterion ipaddr = (IPCriterion) c;
430 log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
431 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
432 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
433 selector.matchEthType(Ethernet.TYPE_IPV4);
434 selector.matchIPDst(ipaddr.ip()); // router IPs to the controller
435 treatment.setOutput(PortNumber.CONTROLLER);
436 FlowRule rule = DefaultFlowRule.builder()
437 .forDevice(deviceId)
438 .withSelector(selector.build())
439 .withTreatment(treatment.build())
440 .withPriority(FILTER_TABLE_CONTROLLER_PRIORITY)
441 .fromApp(applicationId)
442 .makePermanent()
443 .forTable(FILTER_TABLE).build();
444 ops = install ? ops.add(rule) : ops.remove(rule);
Saurav Dase3274c82015-05-24 17:21:56 -0700445 } else {
446 log.warn("Driver does not currently process filtering condition"
447 + " of type: {}", c.type());
448 fail(filt, ObjectiveError.UNSUPPORTED);
449 }
450 }
451
452 // apply filtering flow rules
453 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
454 @Override
455 public void onSuccess(FlowRuleOperations ops) {
456 pass(filt);
457 log.info("Applied filtering rules");
458 }
459
460 @Override
461 public void onError(FlowRuleOperations ops) {
462 fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
463 log.info("Failed to apply filtering rules");
464 }
465 }));
466 }
467
468 private void pass(Objective obj) {
469 if (obj.context().isPresent()) {
470 obj.context().get().onSuccess(obj);
471 }
472 }
473
474 private void fail(Objective obj, ObjectiveError error) {
475 if (obj.context().isPresent()) {
476 obj.context().get().onError(obj, error);
477 }
478 }
479
480 private void initializePipeline() {
481 // CENTEC_V350: PORT_VLAN_TABLE->FILTER_TABLE->MAC_TABLE(TMAC)->ROUTE_TABLE.
482 processPortVlanTable(true);
483 processFilterTable(true);
484 }
485
486 private void processPortVlanTable(boolean install) {
487 // By default the packet are dropped, need install port+vlan by some ways.
488
489 // XXX can we add table-miss-entry to drop? Code says drops by default
490 // XXX TTP description says default goes to table1.
491 // It also says that match is only on vlan -- not port-vlan -- which one is true?
492 }
493
494 private void processFilterTable(boolean install) {
495 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
496 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
497 .builder();
498 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
499 FlowRule rule;
500
501 // Punt ARP packets to controller by default.
502 selector.matchEthType(Ethernet.TYPE_ARP);
503 treatment.punt();
504 rule = DefaultFlowRule.builder()
505 .forDevice(deviceId)
506 .withSelector(selector.build())
507 .withTreatment(treatment.build())
508 .withPriority(FILTER_TABLE_CONTROLLER_PRIORITY)
509 .fromApp(appId)
510 .makePermanent()
511 .forTable(FILTER_TABLE).build();
512 ops = install ? ops.add(rule) : ops.remove(rule);
513
514 // Punt BGP packets to controller directly.
515 selector = DefaultTrafficSelector.builder();
516 treatment = DefaultTrafficTreatment.builder();
517 selector.matchEthType(Ethernet.TYPE_IPV4)
518 .matchIPProtocol(IPv4.PROTOCOL_TCP)
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700519 .matchTcpSrc(TpPort.tpPort(BGP_PORT));
Saurav Dase3274c82015-05-24 17:21:56 -0700520 treatment.punt();
521 rule = DefaultFlowRule.builder()
522 .forDevice(deviceId)
523 .withPriority(FILTER_TABLE_HIGHEST_PRIORITY)
524 .withSelector(selector.build())
525 .withTreatment(treatment.build())
526 .fromApp(appId)
527 .makePermanent()
528 .forTable(FILTER_TABLE).build();
529 ops = install ? ops.add(rule) : ops.remove(rule);
530
531 selector = DefaultTrafficSelector.builder();
532 treatment = DefaultTrafficTreatment.builder();
533 selector.matchEthType(Ethernet.TYPE_IPV4)
534 .matchIPProtocol(IPv4.PROTOCOL_TCP)
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700535 .matchTcpDst(TpPort.tpPort(BGP_PORT));
Saurav Dase3274c82015-05-24 17:21:56 -0700536 treatment.punt();
537 rule = DefaultFlowRule.builder()
538 .forDevice(deviceId)
539 .withPriority(FILTER_TABLE_HIGHEST_PRIORITY)
540 .withSelector(selector.build())
541 .withTreatment(treatment.build())
542 .fromApp(appId)
543 .makePermanent()
544 .forTable(FILTER_TABLE).build();
545
546 ops = install ? ops.add(rule) : ops.remove(rule);
547
548 // Packet will be discard in PORT_VLAN table, no need to install rule in
549 // filter table.
550
551 // XXX does not tell me if packets are going to be dropped by default in
552 // filter table or not? TTP says it will be dropped by default
553
554 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
555 @Override
556 public void onSuccess(FlowRuleOperations ops) {
557 log.info("Provisioned filter table");
558 }
559
560 @Override
561 public void onError(FlowRuleOperations ops) {
562 log.info("Failed to provision filter table");
563 }
564 }));
565 }
566
567 private class InnerGroupListener implements GroupListener {
568 @Override
569 public void event(GroupEvent event) {
570 if (event.type() == GroupEvent.Type.GROUP_ADDED) {
571 GroupKey key = event.subject().appCookie();
572
573 NextObjective obj = pendingGroups.getIfPresent(key);
574 if (obj != null) {
575 flowObjectiveStore.putNextGroup(obj.id(), new CentecV350Group(key));
576 pass(obj);
577 pendingGroups.invalidate(key);
578 }
579 }
580 }
581 }
582
583
584 private class GroupChecker implements Runnable {
585
586 @Override
587 public void run() {
588 Set<GroupKey> keys = pendingGroups.asMap().keySet().stream()
589 .filter(key -> groupService.getGroup(deviceId, key) != null)
590 .collect(Collectors.toSet());
591
592 keys.stream().forEach(key -> {
593 NextObjective obj = pendingGroups.getIfPresent(key);
594 if (obj == null) {
595 return;
596 }
597 pass(obj);
598 pendingGroups.invalidate(key);
599 log.info("Heard back from group service for group {}. "
600 + "Applying pending forwarding objectives", obj.id());
601 flowObjectiveStore.putNextGroup(obj.id(), new CentecV350Group(key));
602 });
603 }
604 }
605
606 private class CentecV350Group implements NextGroup {
607
608 private final GroupKey key;
609
610 public CentecV350Group(GroupKey key) {
611 this.key = key;
612 }
613
614 @SuppressWarnings("unused")
615 public GroupKey key() {
616 return key;
617 }
618
619 @Override
620 public byte[] data() {
621 return appKryo.serialize(key);
622 }
623
624 }
625}