blob: a5fa1aa5b949fd946799e292e43880232b4d2a9b [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.flowprogrammer;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -07002
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -07003import java.io.IOException;
Naoki Shiota7d0cf272013-11-05 10:18:12 -08004import java.util.ArrayDeque;
5import java.util.ArrayList;
Pavlin Radoslavovab3f8862013-12-04 18:35:53 -08006import java.util.Collection;
Naoki Shiota7d0cf272013-11-05 10:18:12 -08007import java.util.EnumSet;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -07008import java.util.HashMap;
Naoki Shiotaf03592e2013-11-27 11:20:39 -08009import java.util.HashSet;
Pavlin Radoslavovab3f8862013-12-04 18:35:53 -080010import java.util.LinkedList;
Naoki Shiota7d0cf272013-11-05 10:18:12 -080011import java.util.List;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070012import java.util.Map;
Naoki Shiota8df97bc2014-03-13 18:42:23 -070013import java.util.Queue;
Naoki Shiota5c8d19f2013-11-05 15:52:38 -080014import java.util.Set;
Naoki Shiotad6ef3b32014-03-13 18:42:23 -070015import java.util.concurrent.ConcurrentHashMap;
Naoki Shiotac1601d32013-11-20 10:47:34 -080016import java.util.concurrent.ExecutionException;
Naoki Shiota05334692014-03-18 16:06:36 -070017import java.util.concurrent.locks.Condition;
18import java.util.concurrent.locks.Lock;
19import java.util.concurrent.locks.ReentrantLock;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070020
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070021import net.floodlightcontroller.core.FloodlightContext;
Naoki Shiotac1601d32013-11-20 10:47:34 -080022import net.floodlightcontroller.core.IFloodlightProviderService;
23import net.floodlightcontroller.core.IOFMessageListener;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070024import net.floodlightcontroller.core.IOFSwitch;
Naoki Shiotac1601d32013-11-20 10:47:34 -080025import net.floodlightcontroller.core.internal.OFMessageFuture;
26import net.floodlightcontroller.core.module.FloodlightModuleContext;
27import net.floodlightcontroller.threadpool.IThreadPoolService;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -080028import net.floodlightcontroller.util.MACAddress;
Naoki Shiota7d0cf272013-11-05 10:18:12 -080029import net.floodlightcontroller.util.OFMessageDamper;
Jonathan Hart23701d12014-04-03 10:45:48 -070030import net.onrc.onos.core.util.FlowEntry;
31import net.onrc.onos.core.util.FlowEntryAction;
Jonathan Harta99ec672014-04-03 11:30:34 -070032import net.onrc.onos.core.util.FlowEntryAction.ActionEnqueue;
33import net.onrc.onos.core.util.FlowEntryAction.ActionOutput;
34import net.onrc.onos.core.util.FlowEntryAction.ActionSetEthernetAddr;
35import net.onrc.onos.core.util.FlowEntryAction.ActionSetIPv4Addr;
36import net.onrc.onos.core.util.FlowEntryAction.ActionSetIpToS;
37import net.onrc.onos.core.util.FlowEntryAction.ActionSetTcpUdpPort;
38import net.onrc.onos.core.util.FlowEntryAction.ActionSetVlanId;
39import net.onrc.onos.core.util.FlowEntryAction.ActionSetVlanPriority;
40import net.onrc.onos.core.util.FlowEntryAction.ActionStripVlan;
Jonathan Hart23701d12014-04-03 10:45:48 -070041import net.onrc.onos.core.util.FlowEntryActions;
42import net.onrc.onos.core.util.FlowEntryMatch;
43import net.onrc.onos.core.util.FlowEntryUserState;
44import net.onrc.onos.core.util.IPv4Net;
45import net.onrc.onos.core.util.Pair;
46import net.onrc.onos.core.util.Port;
Jonathan Harta99ec672014-04-03 11:30:34 -070047
48import org.openflow.protocol.OFBarrierReply;
49import org.openflow.protocol.OFBarrierRequest;
50import org.openflow.protocol.OFFlowMod;
51import org.openflow.protocol.OFMatch;
52import org.openflow.protocol.OFMessage;
53import org.openflow.protocol.OFPacketOut;
54import org.openflow.protocol.OFPort;
55import org.openflow.protocol.OFType;
56import org.openflow.protocol.action.OFAction;
57import org.openflow.protocol.action.OFActionDataLayerDestination;
58import org.openflow.protocol.action.OFActionDataLayerSource;
59import org.openflow.protocol.action.OFActionEnqueue;
60import org.openflow.protocol.action.OFActionNetworkLayerDestination;
61import org.openflow.protocol.action.OFActionNetworkLayerSource;
62import org.openflow.protocol.action.OFActionNetworkTypeOfService;
63import org.openflow.protocol.action.OFActionOutput;
64import org.openflow.protocol.action.OFActionStripVirtualLan;
65import org.openflow.protocol.action.OFActionTransportLayerDestination;
66import org.openflow.protocol.action.OFActionTransportLayerSource;
67import org.openflow.protocol.action.OFActionVirtualLanIdentifier;
68import org.openflow.protocol.action.OFActionVirtualLanPriorityCodePoint;
69import org.openflow.protocol.factory.BasicFactory;
70import org.slf4j.Logger;
71import org.slf4j.LoggerFactory;
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070072
73/**
Naoki Shiotab485d412013-11-26 12:04:19 -080074 * FlowPusher is a implementation of FlowPusherService.
75 * FlowPusher assigns one message queue instance for each one switch.
76 * Number of message processing threads is configurable by constructor, and
Ray Milkey8e5170e2014-04-02 12:09:55 -070077 * one thread can handle multiple message queues. Each queue will be assigned to
Naoki Shiotab485d412013-11-26 12:04:19 -080078 * a thread according to hash function defined by getHash().
79 * Each processing thread reads messages from queues and sends it to switches
80 * in round-robin. Processing thread also calculates rate of sending to suppress
81 * excessive message sending.
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070082 *
Ray Milkey8e5170e2014-04-02 12:09:55 -070083 * @author Naoki Shiota
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -070084 */
Naoki Shiotac1601d32013-11-20 10:47:34 -080085public class FlowPusher implements IFlowPusherService, IOFMessageListener {
Ray Milkeyec838942014-04-09 11:28:43 -070086 private static final Logger log = LoggerFactory.getLogger(FlowPusher.class);
Naoki Shiota8df97bc2014-03-13 18:42:23 -070087 protected static final int DEFAULT_NUMBER_THREAD = 1;
Naoki Shiota7d0cf272013-11-05 10:18:12 -080088
Naoki Shiota7d0cf272013-11-05 10:18:12 -080089 // TODO: Values copied from elsewhere (class LearningSwitch).
90 // The local copy should go away!
91 //
92 protected static final int OFMESSAGE_DAMPER_CAPACITY = 50000; // TODO: find sweet spot
Ray Milkey8e5170e2014-04-02 12:09:55 -070093 protected static final int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms
94
Naoki Shiota7d0bcfa2013-11-13 10:43:33 -080095 // Number of messages sent to switch at once
96 protected static final int MAX_MESSAGE_SEND = 100;
Naoki Shiota7d0cf272013-11-05 10:18:12 -080097
Ray Milkey8e5170e2014-04-02 12:09:55 -070098 private static class SwitchQueueEntry {
99 OFMessage msg;
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700100
Ray Milkey8e5170e2014-04-02 12:09:55 -0700101 public SwitchQueueEntry(OFMessage msg) {
102 this.msg = msg;
103 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700104
Ray Milkey8e5170e2014-04-02 12:09:55 -0700105 public OFMessage getOFMessage() {
106 return msg;
107 }
108 }
Naoki Shiotacf1acca2013-10-31 11:40:32 -0700109
Ray Milkey8e5170e2014-04-02 12:09:55 -0700110 /**
111 * SwitchQueue represents message queue attached to a switch.
112 * This consists of queue itself and variables used for limiting sending rate.
113 *
114 * @author Naoki Shiota
115 */
116 private class SwitchQueue {
Ray Milkey2476cac2014-04-08 11:03:21 -0700117 List<Queue<SwitchQueueEntry>> rawQueues;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700118 QueueState state;
Naoki Shiota7d0cf272013-11-05 10:18:12 -0800119
Ray Milkey8e5170e2014-04-02 12:09:55 -0700120 // Max rate of sending message (bytes/ms). 0 implies no limitation.
Ray Milkey2476cac2014-04-08 11:03:21 -0700121 long maxRate = 0; // 0 indicates no limitation
122 long lastSentTime = 0;
123 long lastSentSize = 0;
Naoki Shiota05334692014-03-18 16:06:36 -0700124
Ray Milkey8e5170e2014-04-02 12:09:55 -0700125 // "To be deleted" flag
126 boolean toBeDeleted = false;
Naoki Shiota7d0cf272013-11-05 10:18:12 -0800127
Ray Milkey8e5170e2014-04-02 12:09:55 -0700128 SwitchQueue() {
Ray Milkey2476cac2014-04-08 11:03:21 -0700129 rawQueues = new ArrayList<Queue<SwitchQueueEntry>>(
Ray Milkey8e5170e2014-04-02 12:09:55 -0700130 MsgPriority.values().length);
131 for (int i = 0; i < MsgPriority.values().length; ++i) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700132 rawQueues.add(i, new ArrayDeque<SwitchQueueEntry>());
Ray Milkey8e5170e2014-04-02 12:09:55 -0700133 }
Naoki Shiota7d0cf272013-11-05 10:18:12 -0800134
Ray Milkey8e5170e2014-04-02 12:09:55 -0700135 state = QueueState.READY;
136 }
Naoki Shiotae3199732013-11-25 16:14:43 -0800137
Ray Milkey8e5170e2014-04-02 12:09:55 -0700138 /**
139 * Check if sending rate is within the rate
140 *
141 * @param current Current time
142 * @return true if within the rate
143 */
144 boolean isSendable(long current) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700145 if (maxRate == 0) {
Ray Milkey8e5170e2014-04-02 12:09:55 -0700146 // no limitation
147 return true;
148 }
Naoki Shiotae3199732013-11-25 16:14:43 -0800149
Ray Milkey2476cac2014-04-08 11:03:21 -0700150 if (current == lastSentTime) {
Ray Milkey8e5170e2014-04-02 12:09:55 -0700151 return false;
152 }
Pavlin Radoslavovab3f8862013-12-04 18:35:53 -0800153
Ray Milkey8e5170e2014-04-02 12:09:55 -0700154 // Check if sufficient time (from aspect of rate) elapsed or not.
Ray Milkey2476cac2014-04-08 11:03:21 -0700155 long rate = lastSentSize / (current - lastSentTime);
156 return (rate < maxRate);
Ray Milkey8e5170e2014-04-02 12:09:55 -0700157 }
Pavlin Radoslavovab3f8862013-12-04 18:35:53 -0800158
Ray Milkey8e5170e2014-04-02 12:09:55 -0700159 /**
160 * Log time and size of last sent data.
161 *
162 * @param current Time to be sent.
163 * @param size Size of sent data (in bytes).
164 */
165 void logSentData(long current, long size) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700166 lastSentTime = current;
167 lastSentSize = size;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700168 }
Naoki Shiota8df97bc2014-03-13 18:42:23 -0700169
Ray Milkey8e5170e2014-04-02 12:09:55 -0700170 boolean add(SwitchQueueEntry entry, MsgPriority priority) {
171 Queue<SwitchQueueEntry> queue = getQueue(priority);
172 if (queue == null) {
173 log.error("Unexpected priority : ", priority);
174 return false;
175 }
176 return queue.add(entry);
177 }
Pavlin Radoslavovab3f8862013-12-04 18:35:53 -0800178
Ray Milkey8e5170e2014-04-02 12:09:55 -0700179 /**
180 * Poll single appropriate entry object according to QueueState.
181 *
182 * @return Entry object.
183 */
184 SwitchQueueEntry poll() {
185 switch (state) {
186 case READY: {
Ray Milkey2476cac2014-04-08 11:03:21 -0700187 for (int i = 0; i < rawQueues.size(); ++i) {
188 SwitchQueueEntry entry = rawQueues.get(i).poll();
Ray Milkey8e5170e2014-04-02 12:09:55 -0700189 if (entry != null) {
190 return entry;
191 }
192 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800193
Ray Milkey8e5170e2014-04-02 12:09:55 -0700194 return null;
195 }
196 case SUSPENDED: {
197 // Only polling from high priority queue
198 SwitchQueueEntry entry = getQueue(MsgPriority.HIGH).poll();
199 return entry;
200 }
201 default:
202 log.error("Unexpected QueueState : ", state);
203 return null;
204 }
205 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800206
Ray Milkey8e5170e2014-04-02 12:09:55 -0700207 /**
208 * Check if this object has any messages in the queues to be sent
209 *
210 * @return True if there are some messages to be sent.
211 */
212 boolean hasMessageToSend() {
213 switch (state) {
214 case READY:
Ray Milkey2476cac2014-04-08 11:03:21 -0700215 for (Queue<SwitchQueueEntry> queue : rawQueues) {
Ray Milkey8e5170e2014-04-02 12:09:55 -0700216 if (!queue.isEmpty()) {
217 return true;
218 }
219 }
220 break;
221 case SUSPENDED:
222 // Only checking high priority queue
223 return (!getQueue(MsgPriority.HIGH).isEmpty());
224 default:
225 log.error("Unexpected QueueState : ", state);
226 return false;
227 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800228
Ray Milkey8e5170e2014-04-02 12:09:55 -0700229 return false;
230 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800231
Ray Milkey8e5170e2014-04-02 12:09:55 -0700232 Queue<SwitchQueueEntry> getQueue(MsgPriority priority) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700233 return rawQueues.get(priority.ordinal());
Ray Milkey8e5170e2014-04-02 12:09:55 -0700234 }
235 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800236
Ray Milkey8e5170e2014-04-02 12:09:55 -0700237 /**
238 * BarrierInfo holds information to specify barrier message sent to switch.
239 *
240 * @author Naoki
241 */
242 private static class BarrierInfo {
243 final long dpid;
244 final int xid;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800245
Ray Milkey8e5170e2014-04-02 12:09:55 -0700246 static BarrierInfo create(IOFSwitch sw, OFBarrierRequest req) {
247 return new BarrierInfo(sw.getId(), req.getXid());
248 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800249
Ray Milkey8e5170e2014-04-02 12:09:55 -0700250 static BarrierInfo create(IOFSwitch sw, OFBarrierReply rpy) {
251 return new BarrierInfo(sw.getId(), rpy.getXid());
252 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800253
Ray Milkey8e5170e2014-04-02 12:09:55 -0700254 private BarrierInfo(long dpid, int xid) {
255 this.dpid = dpid;
256 this.xid = xid;
257 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800258
Ray Milkey8e5170e2014-04-02 12:09:55 -0700259 // Auto generated code by Eclipse
260 @Override
261 public int hashCode() {
262 final int prime = 31;
263 int result = 1;
264 result = prime * result + (int) (dpid ^ (dpid >>> 32));
265 result = prime * result + xid;
266 return result;
267 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800268
Ray Milkey8e5170e2014-04-02 12:09:55 -0700269 @Override
270 public boolean equals(Object obj) {
271 if (this == obj)
272 return true;
273 if (obj == null)
274 return false;
275 if (getClass() != obj.getClass())
276 return false;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800277
Ray Milkey8e5170e2014-04-02 12:09:55 -0700278 BarrierInfo other = (BarrierInfo) obj;
279 return (this.dpid == other.dpid) && (this.xid == other.xid);
280 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800281
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800282
Ray Milkey8e5170e2014-04-02 12:09:55 -0700283 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800284
Ray Milkey8e5170e2014-04-02 12:09:55 -0700285 private OFMessageDamper messageDamper = null;
286 private IThreadPoolService threadPool = null;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800287
Ray Milkey8e5170e2014-04-02 12:09:55 -0700288 private FloodlightContext context = null;
289 private BasicFactory factory = null;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800290
Ray Milkey8e5170e2014-04-02 12:09:55 -0700291 // Map of threads versus dpid
292 private Map<Long, FlowPusherThread> threadMap = null;
293 // Map from (DPID and transaction ID) to Future objects.
294 private Map<BarrierInfo, OFBarrierReplyFuture> barrierFutures
295 = new ConcurrentHashMap<BarrierInfo, OFBarrierReplyFuture>();
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800296
Ray Milkey2476cac2014-04-08 11:03:21 -0700297 private int numberThread;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800298
Ray Milkey8e5170e2014-04-02 12:09:55 -0700299 /**
300 * Main thread that reads messages from queues and sends them to switches.
301 *
302 * @author Naoki Shiota
303 */
304 private class FlowPusherThread extends Thread {
305 private Map<IOFSwitch, SwitchQueue> assignedQueues
306 = new ConcurrentHashMap<IOFSwitch, SwitchQueue>();
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800307
Ray Milkey8e5170e2014-04-02 12:09:55 -0700308 final Lock queuingLock = new ReentrantLock();
309 final Condition messagePushed = queuingLock.newCondition();
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800310
Ray Milkey8e5170e2014-04-02 12:09:55 -0700311 @Override
312 public void run() {
313 this.setName("FlowPusherThread " + this.getId());
314 while (true) {
315 while (!queuesHasMessageToSend()) {
316 queuingLock.lock();
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800317
Ray Milkey8e5170e2014-04-02 12:09:55 -0700318 try {
319 // wait for message pushed to queue
320 messagePushed.await();
321 } catch (InterruptedException e) {
322 // Interrupted to be shut down (not an error)
323 log.debug("FlowPusherThread is interrupted");
324 return;
325 } finally {
326 queuingLock.unlock();
327 }
328 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800329
Ray Milkey8e5170e2014-04-02 12:09:55 -0700330 // for safety of concurrent access, copy set of key objects
331 Set<IOFSwitch> keys = new HashSet<IOFSwitch>(assignedQueues.size());
332 for (IOFSwitch sw : assignedQueues.keySet()) {
333 keys.add(sw);
334 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800335
Ray Milkey8e5170e2014-04-02 12:09:55 -0700336 for (IOFSwitch sw : keys) {
337 SwitchQueue queue = assignedQueues.get(sw);
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800338
Ray Milkey8e5170e2014-04-02 12:09:55 -0700339 if (sw == null || queue == null) {
340 continue;
341 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800342
Ray Milkey8e5170e2014-04-02 12:09:55 -0700343 synchronized (queue) {
344 processQueue(sw, queue, MAX_MESSAGE_SEND);
345 if (queue.toBeDeleted && !queue.hasMessageToSend()) {
346 // remove queue if flagged to be.
347 assignedQueues.remove(sw);
348 }
349 }
350 }
351 }
352 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800353
Ray Milkey8e5170e2014-04-02 12:09:55 -0700354 /**
355 * Read messages from queue and send them to the switch.
356 * If number of messages excess the limit, stop sending messages.
357 *
358 * @param sw Switch to which messages will be sent.
359 * @param queue Queue of messages.
360 * @param max_msg Limitation of number of messages to be sent. If set to 0,
361 * all messages in queue will be sent.
362 */
363 private void processQueue(IOFSwitch sw, SwitchQueue queue, int max_msg) {
364 // check sending rate and determine it to be sent or not
Ray Milkey2476cac2014-04-08 11:03:21 -0700365 long currentTime = System.currentTimeMillis();
Ray Milkey8e5170e2014-04-02 12:09:55 -0700366 long size = 0;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800367
Ray Milkey2476cac2014-04-08 11:03:21 -0700368 if (queue.isSendable(currentTime)) {
Ray Milkey8e5170e2014-04-02 12:09:55 -0700369 int i = 0;
370 while (queue.hasMessageToSend()) {
371 // Number of messages excess the limit
372 if (0 < max_msg && max_msg <= i) {
373 break;
374 }
375 ++i;
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800376
Ray Milkey8e5170e2014-04-02 12:09:55 -0700377 SwitchQueueEntry queueEntry;
378 synchronized (queue) {
379 queueEntry = queue.poll();
380 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800381
Ray Milkey8e5170e2014-04-02 12:09:55 -0700382 OFMessage msg = queueEntry.getOFMessage();
383 try {
384 messageDamper.write(sw, msg, context);
385 if (log.isTraceEnabled()) {
386 log.trace("Pusher sends message : {}", msg);
387 }
388 size += msg.getLength();
389 } catch (IOException e) {
390 e.printStackTrace();
391 log.error("Exception in sending message ({}) : {}", msg, e);
392 }
393 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800394
Ray Milkey8e5170e2014-04-02 12:09:55 -0700395 sw.flush();
Ray Milkey2476cac2014-04-08 11:03:21 -0700396 queue.logSentData(currentTime, size);
Ray Milkey8e5170e2014-04-02 12:09:55 -0700397 }
398 }
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -0800399
Ray Milkey8e5170e2014-04-02 12:09:55 -0700400 private boolean queuesHasMessageToSend() {
401 for (SwitchQueue queue : assignedQueues.values()) {
402 if (queue.hasMessageToSend()) {
403 return true;
404 }
405 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700406
Ray Milkey8e5170e2014-04-02 12:09:55 -0700407 return false;
408 }
Naoki Shiota05334692014-03-18 16:06:36 -0700409
Ray Milkey8e5170e2014-04-02 12:09:55 -0700410 private void notifyMessagePushed() {
411 queuingLock.lock();
412 try {
413 messagePushed.signal();
414 } finally {
415 queuingLock.unlock();
416 }
417 }
418 }
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700419
Ray Milkey8e5170e2014-04-02 12:09:55 -0700420 /**
421 * Initialize object with one thread.
422 */
423 public FlowPusher() {
Ray Milkey2476cac2014-04-08 11:03:21 -0700424 numberThread = DEFAULT_NUMBER_THREAD;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700425 }
Naoki Shiota2e2fc2b2013-11-12 11:21:36 -0800426
Ray Milkey8e5170e2014-04-02 12:09:55 -0700427 /**
428 * Initialize object with threads of given number.
429 *
430 * @param number_thread Number of threads to handle messages.
431 */
432 public FlowPusher(int number_thread) {
433 if (number_thread > 0) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700434 this.numberThread = number_thread;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700435 } else {
Ray Milkey2476cac2014-04-08 11:03:21 -0700436 this.numberThread = DEFAULT_NUMBER_THREAD;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700437 }
438 }
Naoki Shiota81dbe302013-11-21 15:35:38 -0800439
Ray Milkey8e5170e2014-04-02 12:09:55 -0700440 /**
441 * Set parameters needed for sending messages.
442 *
443 * @param context FloodlightContext used for sending messages.
444 * If null, FlowPusher uses default context.
445 * @param modContext FloodlightModuleContext used for acquiring
446 * ThreadPoolService and registering MessageListener.
447 * @param factory Factory object to create OFMessage objects.
448 * @param damper Message damper used for sending messages.
449 * If null, FlowPusher creates its own damper object.
450 */
451 public void init(FloodlightContext context,
452 FloodlightModuleContext modContext,
453 BasicFactory factory,
454 OFMessageDamper damper) {
455 this.context = context;
456 this.factory = factory;
457 this.threadPool = modContext.getServiceImpl(IThreadPoolService.class);
458 IFloodlightProviderService flservice
459 = modContext.getServiceImpl(IFloodlightProviderService.class);
460 flservice.addOFMessageListener(OFType.BARRIER_REPLY, this);
Naoki Shiotac1601d32013-11-20 10:47:34 -0800461
Ray Milkey8e5170e2014-04-02 12:09:55 -0700462 if (damper != null) {
463 messageDamper = damper;
464 } else {
465 // use default values
466 messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
467 EnumSet.of(OFType.FLOW_MOD),
468 OFMESSAGE_DAMPER_TIMEOUT);
469 }
470 }
Naoki Shiotae3199732013-11-25 16:14:43 -0800471
Ray Milkey8e5170e2014-04-02 12:09:55 -0700472 /**
473 * Begin processing queue.
474 */
475 public void start() {
476 if (factory == null) {
477 log.error("FlowPusher not yet initialized.");
478 return;
479 }
Naoki Shiotac1601d32013-11-20 10:47:34 -0800480
Ray Milkey8e5170e2014-04-02 12:09:55 -0700481 threadMap = new HashMap<Long, FlowPusherThread>();
Ray Milkey2476cac2014-04-08 11:03:21 -0700482 for (long i = 0; i < numberThread; ++i) {
Ray Milkey8e5170e2014-04-02 12:09:55 -0700483 FlowPusherThread thread = new FlowPusherThread();
Naoki Shiotac1601d32013-11-20 10:47:34 -0800484
Ray Milkey8e5170e2014-04-02 12:09:55 -0700485 threadMap.put(i, thread);
486 thread.start();
487 }
488 }
Naoki Shiotac1601d32013-11-20 10:47:34 -0800489
Ray Milkey8e5170e2014-04-02 12:09:55 -0700490 @Override
491 public boolean suspend(IOFSwitch sw) {
492 SwitchQueue queue = getQueue(sw);
Naoki Shiotad6ef3b32014-03-13 18:42:23 -0700493
Ray Milkey8e5170e2014-04-02 12:09:55 -0700494 if (queue == null) {
495 // create queue in case suspend is called before first message addition
496 queue = createQueueImpl(sw);
497 }
498
499 synchronized (queue) {
500 if (queue.state == QueueState.READY) {
501 queue.state = QueueState.SUSPENDED;
502 return true;
503 }
504 return false;
505 }
506 }
507
508 @Override
509 public boolean resume(IOFSwitch sw) {
510 SwitchQueue queue = getQueue(sw);
511
512 if (queue == null) {
513 log.error("No queue is attached to DPID : {}", sw.getId());
514 return false;
515 }
516
517 synchronized (queue) {
518 if (queue.state == QueueState.SUSPENDED) {
519 queue.state = QueueState.READY;
520
521 // Free the latch if queue has any messages
522 FlowPusherThread thread = getProcessingThread(sw);
523 if (queue.hasMessageToSend()) {
524 thread.notifyMessagePushed();
525 }
526 return true;
527 }
528 return false;
529 }
530 }
531
532 @Override
533 public QueueState getState(IOFSwitch sw) {
534 SwitchQueue queue = getQueue(sw);
535
536 if (queue == null) {
537 return QueueState.UNKNOWN;
538 }
539
540 return queue.state;
541 }
542
543 /**
544 * Stop processing queue and exit thread.
545 */
546 public void stop() {
547 if (threadMap == null) {
548 return;
549 }
550
551 for (FlowPusherThread t : threadMap.values()) {
552 t.interrupt();
553 }
554 }
555
556 @Override
557 public void setRate(IOFSwitch sw, long rate) {
558 SwitchQueue queue = getQueue(sw);
559 if (queue == null) {
560 queue = createQueueImpl(sw);
561 }
562
563 if (rate > 0) {
564 log.debug("rate for {} is set to {}", sw.getId(), rate);
565 synchronized (queue) {
Ray Milkey2476cac2014-04-08 11:03:21 -0700566 queue.maxRate = rate;
Ray Milkey8e5170e2014-04-02 12:09:55 -0700567 }
568 }
569 }
570
571 @Override
572 public boolean createQueue(IOFSwitch sw) {
573 SwitchQueue queue = createQueueImpl(sw);
574
575 return (queue != null);
576 }
577
578 protected SwitchQueue createQueueImpl(IOFSwitch sw) {
579 SwitchQueue queue = getQueue(sw);
580 if (queue != null) {
581 return queue;
582 }
583
584 FlowPusherThread proc = getProcessingThread(sw);
585 queue = new SwitchQueue();
586 queue.state = QueueState.READY;
587 proc.assignedQueues.put(sw, queue);
588
589 return queue;
590 }
591
592 @Override
593 public boolean deleteQueue(IOFSwitch sw) {
594 return deleteQueue(sw, false);
595 }
596
597 @Override
598 public boolean deleteQueue(IOFSwitch sw, boolean forceStop) {
599 FlowPusherThread proc = getProcessingThread(sw);
600
601 if (forceStop) {
602 SwitchQueue queue = proc.assignedQueues.remove(sw);
603 if (queue == null) {
604 return false;
605 }
606 return true;
607 } else {
608 SwitchQueue queue = getQueue(sw);
609 if (queue == null) {
610 return false;
611 }
612 synchronized (queue) {
613 queue.toBeDeleted = true;
614 }
615 return true;
616 }
617 }
618
619 @Override
620 public boolean add(IOFSwitch sw, OFMessage msg) {
621 return add(sw, msg, MsgPriority.NORMAL);
622 }
623
624 @Override
625 public boolean add(IOFSwitch sw, OFMessage msg, MsgPriority priority) {
626 return addMessageImpl(sw, msg, priority);
627 }
628
629 @Override
630 public void pushFlowEntries(
631 Collection<Pair<IOFSwitch, FlowEntry>> entries) {
632 pushFlowEntries(entries, MsgPriority.NORMAL);
633 }
634
635 @Override
636 public void pushFlowEntries(
637 Collection<Pair<IOFSwitch, FlowEntry>> entries, MsgPriority priority) {
638
639 for (Pair<IOFSwitch, FlowEntry> entry : entries) {
640 add(entry.first, entry.second, priority);
641 }
642 }
643
644 @Override
645 public void pushFlowEntry(IOFSwitch sw, FlowEntry flowEntry) {
646 pushFlowEntry(sw, flowEntry, MsgPriority.NORMAL);
647 }
648
649 @Override
650 public void pushFlowEntry(IOFSwitch sw, FlowEntry flowEntry, MsgPriority priority) {
651 Collection<Pair<IOFSwitch, FlowEntry>> entries =
652 new LinkedList<Pair<IOFSwitch, FlowEntry>>();
653
654 entries.add(new Pair<IOFSwitch, FlowEntry>(sw, flowEntry));
655 pushFlowEntries(entries, priority);
656 }
657
658 /**
659 * Create a message from FlowEntry and add it to the queue of the switch.
660 *
661 * @param sw Switch to which message is pushed.
662 * @param flowEntry FlowEntry object used for creating message.
663 * @return true if message is successfully added to a queue.
664 */
665 private boolean add(IOFSwitch sw, FlowEntry flowEntry, MsgPriority priority) {
666 //
667 // Create the OpenFlow Flow Modification Entry to push
668 //
669 OFFlowMod fm = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD);
670 long cookie = flowEntry.flowEntryId().value();
671
672 short flowModCommand = OFFlowMod.OFPFC_ADD;
673 if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_ADD) {
674 flowModCommand = OFFlowMod.OFPFC_ADD;
675 } else if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_MODIFY) {
676 flowModCommand = OFFlowMod.OFPFC_MODIFY_STRICT;
677 } else if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE) {
678 flowModCommand = OFFlowMod.OFPFC_DELETE_STRICT;
679 } else {
680 // Unknown user state. Ignore the entry
681 log.debug(
682 "Flow Entry ignored (FlowEntryId = {}): unknown user state {}",
683 flowEntry.flowEntryId(),
684 flowEntry.flowEntryUserState());
685 return false;
686 }
687
688 //
689 // Fetch the match conditions.
690 //
691 // NOTE: The Flow matching conditions common for all Flow Entries are
692 // used ONLY if a Flow Entry does NOT have the corresponding matching
693 // condition set.
694 //
695 OFMatch match = new OFMatch();
696 match.setWildcards(OFMatch.OFPFW_ALL);
697 FlowEntryMatch flowEntryMatch = flowEntry.flowEntryMatch();
698
699 // Match the Incoming Port
700 Port matchInPort = flowEntryMatch.inPort();
701 if (matchInPort != null) {
702 match.setInputPort(matchInPort.value());
703 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_IN_PORT);
704 }
705
706 // Match the Source MAC address
707 MACAddress matchSrcMac = flowEntryMatch.srcMac();
708 if (matchSrcMac != null) {
709 match.setDataLayerSource(matchSrcMac.toString());
710 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_SRC);
711 }
712
713 // Match the Destination MAC address
714 MACAddress matchDstMac = flowEntryMatch.dstMac();
715 if (matchDstMac != null) {
716 match.setDataLayerDestination(matchDstMac.toString());
717 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_DST);
718 }
719
720 // Match the Ethernet Frame Type
721 Short matchEthernetFrameType = flowEntryMatch.ethernetFrameType();
722 if (matchEthernetFrameType != null) {
723 match.setDataLayerType(matchEthernetFrameType);
724 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE);
725 }
726
727 // Match the VLAN ID
728 Short matchVlanId = flowEntryMatch.vlanId();
729 if (matchVlanId != null) {
730 match.setDataLayerVirtualLan(matchVlanId);
731 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_VLAN);
732 }
733
734 // Match the VLAN priority
735 Byte matchVlanPriority = flowEntryMatch.vlanPriority();
736 if (matchVlanPriority != null) {
737 match.setDataLayerVirtualLanPriorityCodePoint(matchVlanPriority);
738 match.setWildcards(match.getWildcards()
739 & ~OFMatch.OFPFW_DL_VLAN_PCP);
740 }
741
742 // Match the Source IPv4 Network prefix
743 IPv4Net matchSrcIPv4Net = flowEntryMatch.srcIPv4Net();
744 if (matchSrcIPv4Net != null) {
745 match.setFromCIDR(matchSrcIPv4Net.toString(), OFMatch.STR_NW_SRC);
746 }
747
748 // Natch the Destination IPv4 Network prefix
749 IPv4Net matchDstIPv4Net = flowEntryMatch.dstIPv4Net();
750 if (matchDstIPv4Net != null) {
751 match.setFromCIDR(matchDstIPv4Net.toString(), OFMatch.STR_NW_DST);
752 }
753
754 // Match the IP protocol
755 Byte matchIpProto = flowEntryMatch.ipProto();
756 if (matchIpProto != null) {
757 match.setNetworkProtocol(matchIpProto);
758 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_NW_PROTO);
759 }
760
761 // Match the IP ToS (DSCP field, 6 bits)
762 Byte matchIpToS = flowEntryMatch.ipToS();
763 if (matchIpToS != null) {
764 match.setNetworkTypeOfService(matchIpToS);
765 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_NW_TOS);
766 }
767
768 // Match the Source TCP/UDP port
769 Short matchSrcTcpUdpPort = flowEntryMatch.srcTcpUdpPort();
770 if (matchSrcTcpUdpPort != null) {
771 match.setTransportSource(matchSrcTcpUdpPort);
772 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_TP_SRC);
773 }
774
775 // Match the Destination TCP/UDP port
776 Short matchDstTcpUdpPort = flowEntryMatch.dstTcpUdpPort();
777 if (matchDstTcpUdpPort != null) {
778 match.setTransportDestination(matchDstTcpUdpPort);
779 match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_TP_DST);
780 }
781
782 //
783 // Fetch the actions
784 //
785 Short actionOutputPort = null;
786 List<OFAction> openFlowActions = new ArrayList<OFAction>();
787 int actionsLen = 0;
788 FlowEntryActions flowEntryActions = flowEntry.flowEntryActions();
789 //
790 for (FlowEntryAction action : flowEntryActions.actions()) {
791 ActionOutput actionOutput = action.actionOutput();
792 ActionSetVlanId actionSetVlanId = action.actionSetVlanId();
793 ActionSetVlanPriority actionSetVlanPriority = action
794 .actionSetVlanPriority();
795 ActionStripVlan actionStripVlan = action.actionStripVlan();
796 ActionSetEthernetAddr actionSetEthernetSrcAddr = action
797 .actionSetEthernetSrcAddr();
798 ActionSetEthernetAddr actionSetEthernetDstAddr = action
799 .actionSetEthernetDstAddr();
800 ActionSetIPv4Addr actionSetIPv4SrcAddr = action
801 .actionSetIPv4SrcAddr();
802 ActionSetIPv4Addr actionSetIPv4DstAddr = action
803 .actionSetIPv4DstAddr();
804 ActionSetIpToS actionSetIpToS = action.actionSetIpToS();
805 ActionSetTcpUdpPort actionSetTcpUdpSrcPort = action
806 .actionSetTcpUdpSrcPort();
807 ActionSetTcpUdpPort actionSetTcpUdpDstPort = action
808 .actionSetTcpUdpDstPort();
809 ActionEnqueue actionEnqueue = action.actionEnqueue();
810
811 if (actionOutput != null) {
812 actionOutputPort = actionOutput.port().value();
813 // XXX: The max length is hard-coded for now
814 OFActionOutput ofa = new OFActionOutput(actionOutput.port()
815 .value(), (short) 0xffff);
816 openFlowActions.add(ofa);
817 actionsLen += ofa.getLength();
818 }
819
820 if (actionSetVlanId != null) {
821 OFActionVirtualLanIdentifier ofa = new OFActionVirtualLanIdentifier(
822 actionSetVlanId.vlanId());
823 openFlowActions.add(ofa);
824 actionsLen += ofa.getLength();
825 }
826
827 if (actionSetVlanPriority != null) {
828 OFActionVirtualLanPriorityCodePoint ofa = new OFActionVirtualLanPriorityCodePoint(
829 actionSetVlanPriority.vlanPriority());
830 openFlowActions.add(ofa);
831 actionsLen += ofa.getLength();
832 }
833
834 if (actionStripVlan != null) {
835 if (actionStripVlan.stripVlan() == true) {
836 OFActionStripVirtualLan ofa = new OFActionStripVirtualLan();
837 openFlowActions.add(ofa);
838 actionsLen += ofa.getLength();
839 }
840 }
841
842 if (actionSetEthernetSrcAddr != null) {
843 OFActionDataLayerSource ofa = new OFActionDataLayerSource(
844 actionSetEthernetSrcAddr.addr().toBytes());
845 openFlowActions.add(ofa);
846 actionsLen += ofa.getLength();
847 }
848
849 if (actionSetEthernetDstAddr != null) {
850 OFActionDataLayerDestination ofa = new OFActionDataLayerDestination(
851 actionSetEthernetDstAddr.addr().toBytes());
852 openFlowActions.add(ofa);
853 actionsLen += ofa.getLength();
854 }
855
856 if (actionSetIPv4SrcAddr != null) {
857 OFActionNetworkLayerSource ofa = new OFActionNetworkLayerSource(
858 actionSetIPv4SrcAddr.addr().value());
859 openFlowActions.add(ofa);
860 actionsLen += ofa.getLength();
861 }
862
863 if (actionSetIPv4DstAddr != null) {
864 OFActionNetworkLayerDestination ofa = new OFActionNetworkLayerDestination(
865 actionSetIPv4DstAddr.addr().value());
866 openFlowActions.add(ofa);
867 actionsLen += ofa.getLength();
868 }
869
870 if (actionSetIpToS != null) {
871 OFActionNetworkTypeOfService ofa = new OFActionNetworkTypeOfService(
872 actionSetIpToS.ipToS());
873 openFlowActions.add(ofa);
874 actionsLen += ofa.getLength();
875 }
876
877 if (actionSetTcpUdpSrcPort != null) {
878 OFActionTransportLayerSource ofa = new OFActionTransportLayerSource(
879 actionSetTcpUdpSrcPort.port());
880 openFlowActions.add(ofa);
881 actionsLen += ofa.getLength();
882 }
883
884 if (actionSetTcpUdpDstPort != null) {
885 OFActionTransportLayerDestination ofa = new OFActionTransportLayerDestination(
886 actionSetTcpUdpDstPort.port());
887 openFlowActions.add(ofa);
888 actionsLen += ofa.getLength();
889 }
890
891 if (actionEnqueue != null) {
892 OFActionEnqueue ofa = new OFActionEnqueue(actionEnqueue.port()
893 .value(), actionEnqueue.queueId());
894 openFlowActions.add(ofa);
895 actionsLen += ofa.getLength();
896 }
897 }
898
899 fm.setIdleTimeout((short) flowEntry.idleTimeout())
900 .setHardTimeout((short) flowEntry.hardTimeout())
901 .setPriority((short) flowEntry.priority())
902 .setBufferId(OFPacketOut.BUFFER_ID_NONE).setCookie(cookie)
903 .setCommand(flowModCommand).setMatch(match)
904 .setActions(openFlowActions)
905 .setLengthU(OFFlowMod.MINIMUM_LENGTH + actionsLen);
906 fm.setOutPort(OFPort.OFPP_NONE.getValue());
907 if ((flowModCommand == OFFlowMod.OFPFC_DELETE)
908 || (flowModCommand == OFFlowMod.OFPFC_DELETE_STRICT)) {
909 if (actionOutputPort != null)
910 fm.setOutPort(actionOutputPort);
911 }
912
913 //
914 // Set the OFPFF_SEND_FLOW_REM flag if the Flow Entry is not
915 // permanent.
916 //
917 if ((flowEntry.idleTimeout() != 0) ||
918 (flowEntry.hardTimeout() != 0)) {
919 fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
920 }
921
922 if (log.isTraceEnabled()) {
923 log.trace("Installing flow entry {} into switch DPID: {} flowEntryId: {} srcMac: {} dstMac: {} inPort: {} outPort: {}"
924 , flowEntry.flowEntryUserState()
925 , sw.getStringId()
926 , flowEntry.flowEntryId()
927 , matchSrcMac
928 , matchDstMac
929 , matchInPort
930 , actionOutputPort
931 );
932 }
933
934 return addMessageImpl(sw, fm, priority);
935 }
936
937 /**
938 * Add message to queue
939 *
940 * @param sw
941 * @param msg
942 * @param flowEntryId
943 * @return
944 */
945 protected boolean addMessageImpl(IOFSwitch sw, OFMessage msg, MsgPriority priority) {
946 FlowPusherThread thread = getProcessingThread(sw);
947
948 SwitchQueue queue = getQueue(sw);
949
950 // create queue at first addition of message
951 if (queue == null) {
952 queue = createQueueImpl(sw);
953 }
954
955 SwitchQueueEntry entry = new SwitchQueueEntry(msg);
956
957 synchronized (queue) {
958 queue.add(entry, priority);
959 if (log.isTraceEnabled()) {
960 log.trace("Message is pushed : {}", entry.getOFMessage());
961 }
962 }
963
964 thread.notifyMessagePushed();
965
966 return true;
967 }
968
969 @Override
970 public OFBarrierReply barrier(IOFSwitch sw) {
971 OFMessageFuture<OFBarrierReply> future = barrierAsync(sw);
972 if (future == null) {
973 return null;
974 }
975
976 try {
977 return future.get();
978 } catch (InterruptedException e) {
979 e.printStackTrace();
980 log.error("InterruptedException: {}", e);
981 return null;
982 } catch (ExecutionException e) {
983 e.printStackTrace();
984 log.error("ExecutionException: {}", e);
985 return null;
986 }
987 }
988
989 @Override
990 public OFBarrierReplyFuture barrierAsync(IOFSwitch sw) {
991 // TODO creation of message and future should be moved to OFSwitchImpl
992
993 if (sw == null) {
994 return null;
995 }
996
997 OFBarrierRequest msg = createBarrierRequest(sw);
998
999 OFBarrierReplyFuture future = new OFBarrierReplyFuture(threadPool, sw, msg.getXid());
1000 barrierFutures.put(BarrierInfo.create(sw, msg), future);
1001
1002 addMessageImpl(sw, msg, MsgPriority.NORMAL);
1003
1004 return future;
1005 }
1006
1007 protected OFBarrierRequest createBarrierRequest(IOFSwitch sw) {
1008 OFBarrierRequest msg = (OFBarrierRequest) factory.getMessage(OFType.BARRIER_REQUEST);
1009 msg.setXid(sw.getNextTransactionId());
1010
1011 return msg;
1012 }
1013
1014 /**
1015 * Get a queue attached to a switch.
1016 *
1017 * @param sw Switch object
1018 * @return Queue object
1019 */
1020 protected SwitchQueue getQueue(IOFSwitch sw) {
1021 if (sw == null) {
1022 return null;
1023 }
1024
1025 FlowPusherThread th = getProcessingThread(sw);
1026 if (th == null) {
1027 return null;
1028 }
1029
1030 return th.assignedQueues.get(sw);
1031 }
1032
1033 /**
1034 * Get a hash value correspondent to a switch.
1035 *
1036 * @param sw Switch object
1037 * @return Hash value
1038 */
1039 protected long getHash(IOFSwitch sw) {
1040 // This code assumes DPID is sequentially assigned.
1041 // TODO consider equalization algorithm
Ray Milkey2476cac2014-04-08 11:03:21 -07001042 return sw.getId() % numberThread;
Ray Milkey8e5170e2014-04-02 12:09:55 -07001043 }
1044
1045 /**
1046 * Get a Thread object which processes the queue attached to a switch.
1047 *
1048 * @param sw Switch object
1049 * @return Thread object
1050 */
1051 protected FlowPusherThread getProcessingThread(IOFSwitch sw) {
1052 long hash = getHash(sw);
1053
1054 return threadMap.get(hash);
1055 }
1056
1057 @Override
1058 public String getName() {
1059 return "flowpusher";
1060 }
1061
1062 @Override
1063 public boolean isCallbackOrderingPrereq(OFType type, String name) {
1064 return false;
1065 }
1066
1067 @Override
1068 public boolean isCallbackOrderingPostreq(OFType type, String name) {
1069 return false;
1070 }
1071
1072 @Override
1073 public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
1074 if (log.isTraceEnabled()) {
1075 log.trace("Received BARRIER_REPLY from : {}", sw.getId());
1076 }
1077
1078 if (msg.getType() != OFType.BARRIER_REPLY) {
1079 log.error("Unexpected reply message : {}", msg.getType());
1080 return Command.CONTINUE;
1081 }
1082
1083 OFBarrierReply reply = (OFBarrierReply) msg;
1084 BarrierInfo info = BarrierInfo.create(sw, reply);
1085
1086 // Deliver future if exists
1087 OFBarrierReplyFuture future = barrierFutures.get(info);
1088 if (future != null) {
1089 future.deliverFuture(sw, msg);
1090 barrierFutures.remove(info);
1091 }
1092
1093 return Command.CONTINUE;
1094 }
Naoki Shiotaed4eb5e2013-10-31 10:55:32 -07001095}