16 package org.openkilda.floodlight.service.batch;
22 import net.floodlightcontroller.core.FloodlightContext;
23 import net.floodlightcontroller.core.IOFSwitch;
24 import net.floodlightcontroller.core.internal.IOFSwitchService;
25 import net.floodlightcontroller.core.module.FloodlightModuleContext;
26 import net.floodlightcontroller.core.module.IFloodlightService;
27 import org.projectfloodlight.openflow.protocol.OFMessage;
28 import org.projectfloodlight.openflow.protocol.OFType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.util.LinkedList;
33 import java.util.List;
34 import java.util.ListIterator;
37 private static final Logger log = LoggerFactory.getLogger(
OfBatchService.class);
39 private final LinkedList<Task> operations =
new LinkedList<>();
48 log.debug(
"Got io request with {} message(s) from {}", payload.size(), initiator);
50 BatchRecord batch =
new BatchRecord(switchUtils, payload);
51 operations.addLast(
new Task(initiator, batch));
56 operations.removeLast();
61 public void init(FloodlightModuleContext moduleContext) {
62 switchUtils =
new SwitchUtils(moduleContext.getServiceImpl(IOFSwitchService.class));
67 public boolean handle(IOFSwitch sw, OFMessage message, FloodlightContext context) {
68 boolean isHandled =
false;
70 Task completed = null;
72 for (ListIterator<Task> iterator = operations.listIterator(); iterator.hasNext(); ) {
73 Task task = iterator.next();
75 if (!task.batch.handleResponse(message)) {
79 log.debug(
"Message (xId:{}) have matched one of pending io batches", message.getXid());
81 if (task.batch.isComplete()) {
89 if (completed != null) {
90 log.debug(
"Send complete signal to pending command: {}", completed.command);
91 completed.command.ioComplete(completed.batch.getBatch(), completed.batch.isErrors());
99 final BatchRecord batch;
void init(FloodlightModuleContext moduleContext)
void activateSubscription(IFloodlightModuleContext moduleContext, OFType... desiredTypes)
boolean handle(IOFSwitch sw, OFMessage message, FloodlightContext context)
def command(payload, fields)
synchronized void push(org.openkilda.floodlight.command.Command initiator, List< OfPendingMessage > payload)