blob: 2ee51d7e4e65600ea3e7b28b3dd083df40e12a09 [file] [log] [blame]
Naoki Shiotac2a699a2013-10-31 15:36:01 -07001package net.onrc.onos.ofcontroller.flowmanager;
2
3import java.util.HashMap;
4import java.util.Map;
5import java.util.Queue;
6import java.util.Set;
7
8import net.floodlightcontroller.core.IOFSwitch;
9
10import org.openflow.protocol.OFMessage;
11
12/**
13 * Represents table of message queues attached to each switch.
14 * Each message should be ADD/DELETE of flow.
15 * (MODIFY of flow might be handled, but future work)
16 * @author Naoki Shiota
17 *
18 */
19public class FlowQueueTable {
20
21 public enum QueueState {
Naoki Shiota2ca26f32013-10-31 17:14:13 -070022 READY, // Synchronized and working
23 SYNCHRONIZING, // Synchronization is running
24// SUSPENDED, // Synchronized but stopping sending messages
Naoki Shiotac2a699a2013-10-31 15:36:01 -070025 }
26
27 private class QueueInfo {
28 QueueState state;
29
30 // Max rate of sending message (bytes/sec). 0 implies no limitation.
31 long max_rate = 0;
Naoki Shiotac2a699a2013-10-31 15:36:01 -070032 }
33
34 private Map< IOFSwitch, Queue<OFMessage> > queues
35 = new HashMap< IOFSwitch, Queue<OFMessage> >();
36 private Map<IOFSwitch, QueueInfo> queue_info
37 = new HashMap<IOFSwitch, QueueInfo>();
38
39 public FlowQueueTable() {
40 // TODO Auto-generated constructor stub
41 }
42
43 /**
44 * Add flow queue for given switch.
45 * Note queue should be given by caller so that caller can select data
46 * structure suitable for its processing.
47 * @param sw
48 * @param queue
49 */
50 public void addSwitchQueue(IOFSwitch sw, Queue<OFMessage> queue) {
51 QueueInfo info = new QueueInfo();
52
53 if (queues.containsKey(sw)) {
54 return;
55 }
56
57 queues.put(sw, queue);
58 queue_info.put(sw, info);
59 }
60
61 /**
62 * Delete flow queue for given switch.
63 * @param sw
64 */
65 public void deleteSwitchQueue(IOFSwitch sw) {
66 if (! queues.containsKey(sw)) {
67 return;
68 }
69
70 queues.remove(sw);
71 queue_info.remove(sw);
72 }
73
74 /**
75 * Get flow queue for given switch.
76 * @param sw
77 * @return
78 */
79 public Queue<OFMessage> getQueue(IOFSwitch sw) {
80 return queues.get(sw);
81 }
82
83 public Set<IOFSwitch> getSwitches() {
84 return queues.keySet();
85 }
86
87 /**
88 * Get state of flow queue for given switch.
89 * @param sw
90 */
91 public QueueState getQueueState(IOFSwitch sw) {
92 QueueInfo info = queue_info.get(sw);
93 if (info == null) {
94 return null;
95 }
96
97 return info.state;
98 }
99
100 /**
101 * Set state of flow queue for given switch.
102 * @param sw
103 * @param state
104 */
105 public void setQueueState(IOFSwitch sw, QueueState state) {
106 QueueInfo info = queue_info.get(sw);
107 if (info == null) {
108 return;
109 }
110
111 info.state = state;
112 }
113
114 /**
115 * Get maximum rate for given switch.
116 * @param sw
117 */
118 public long getQueueRate(IOFSwitch sw) {
119 QueueInfo info = queue_info.get(sw);
120 if (info == null) {
121 return 0;
122 }
123
124 return info.max_rate;
125 }
126
127 /**
128 * Set maximum rate for given switch.
129 * @param sw
130 * @param rate
131 */
132 public void setQueueRate(IOFSwitch sw, long rate) {
133 QueueInfo info = queue_info.get(sw);
134 if (info == null) {
135 return;
136 }
137
138 info.max_rate = rate;
139 }
140
141 /**
Naoki Shiotac2a699a2013-10-31 15:36:01 -0700142 * Get a lock for queue for given switch.
143 * If locked already, wait for unlock.
144 * @param sw
145 */
146 public void lockQueue(IOFSwitch sw) {
147 // TODO not yet implement
148 }
149
150 /**
151 * Get a lock for queue for given switch.
152 * If locked already, return false at once.
153 * @param sw
154 * @return
155 */
156 public boolean lockQueueIfAvailable(IOFSwitch sw) {
157 // TODO not yet implement
158 return false;
159 }
160
161 /** Release a lock for queue for given switch.
162 * @param sw
163 */
164 public void unlockQueue(IOFSwitch sw) {
165 // TODO not yet implement
166 }
167}