Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.flowprogrammer; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 5 | import java.util.HashMap; |
| 6 | import java.util.HashSet; |
| 7 | import java.util.List; |
| 8 | import java.util.Map; |
| 9 | import java.util.Set; |
Naoki Shiota | 2bdda57 | 2013-12-09 15:05:21 -0800 | [diff] [blame] | 10 | import java.util.concurrent.Callable; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 11 | import java.util.concurrent.ExecutionException; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 12 | import java.util.concurrent.Future; |
Naoki Shiota | 2bdda57 | 2013-12-09 15:05:21 -0800 | [diff] [blame] | 13 | import java.util.concurrent.FutureTask; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 14 | |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFSwitch; |
| 16 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService.MsgPriority; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 17 | import net.onrc.onos.core.util.FlowEntryId; |
| 18 | |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 19 | import org.openflow.protocol.OFFlowMod; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 20 | import org.openflow.protocol.OFMatch; |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 21 | import org.openflow.protocol.OFPort; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 22 | import org.openflow.protocol.OFStatisticsRequest; |
| 23 | import org.openflow.protocol.statistics.OFFlowStatisticsReply; |
| 24 | import org.openflow.protocol.statistics.OFFlowStatisticsRequest; |
| 25 | import org.openflow.protocol.statistics.OFStatistics; |
| 26 | import org.openflow.protocol.statistics.OFStatisticsType; |
| 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
| 29 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 30 | /** |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 31 | * FlowSynchronizer is an implementation of FlowSyncService. |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 32 | * In addition to IFlowSyncService, FlowSynchronizer periodically reads flow |
| 33 | * tables from switches and compare them with GraphDB to drop unnecessary |
| 34 | * flows and/or to install missing flows. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 35 | * |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 36 | * @author Brian |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 37 | */ |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 38 | public class FlowSynchronizer implements IFlowSyncService { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 39 | |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 40 | private static Logger log = LoggerFactory.getLogger(FlowSynchronizer.class); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 41 | |
Pavlin Radoslavov | 4cf8ee5 | 2014-03-26 18:19:58 -0700 | [diff] [blame] | 42 | // TODO: fix when FlowSynchronizer is refactored |
Pavlin Radoslavov | 697f698 | 2014-03-26 15:55:19 -0700 | [diff] [blame] | 43 | // private DBOperation dbHandler; |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 44 | protected IFlowPusherService pusher; |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 45 | private Map<IOFSwitch, FutureTask<SyncResult>> switchThreads; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 46 | |
| 47 | public FlowSynchronizer() { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 48 | // TODO: fix when FlowSynchronizer is refactored |
| 49 | // dbHandler = GraphDBManager.getDBOperation(); |
| 50 | switchThreads = new HashMap<IOFSwitch, FutureTask<SyncResult>>(); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 53 | @Override |
Naoki Shiota | 2bdda57 | 2013-12-09 15:05:21 -0800 | [diff] [blame] | 54 | public Future<SyncResult> synchronize(IOFSwitch sw) { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 55 | Synchronizer sync = new Synchronizer(sw); |
| 56 | FutureTask<SyncResult> task = new FutureTask<SyncResult>(sync); |
| 57 | switchThreads.put(sw, task); |
| 58 | task.run(); |
| 59 | return task; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 60 | } |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 61 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 62 | @Override |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 63 | public void interrupt(IOFSwitch sw) { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 64 | FutureTask<SyncResult> t = switchThreads.remove(sw); |
| 65 | if (t != null) { |
| 66 | t.cancel(true); |
| 67 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 70 | /** |
| 71 | * Initialize Synchronizer. |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 72 | * |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 73 | * @param pusherService FlowPusherService used for sending messages. |
| 74 | */ |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 75 | public void init(IFlowPusherService pusherService) { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 76 | pusher = pusherService; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Synchronizer represents main thread of synchronization. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 81 | * |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 82 | * @author Brian |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 83 | */ |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 84 | protected class Synchronizer implements Callable<SyncResult> { |
| 85 | IOFSwitch sw; |
| 86 | // TODO: fix when FlowSynchronizer is refactored |
| 87 | // ISwitchObject swObj; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 88 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 89 | public Synchronizer(IOFSwitch sw) { |
| 90 | this.sw = sw; |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 91 | // TODO: fix when FlowSynchronizer is refactored |
Pavlin Radoslavov | 3255ae5 | 2014-04-09 13:01:54 -0700 | [diff] [blame] | 92 | // Dpid dpid = new Dpid(sw.getId()); |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 93 | // this.swObj = dbHandler.searchSwitch(dpid.toString()); |
| 94 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 95 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 96 | double graphIDTime, switchTime, compareTime, graphEntryTime, extractTime, pushTime, totalTime; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 97 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 98 | @Override |
| 99 | public SyncResult call() { |
| 100 | pusher.suspend(sw); |
| 101 | try { |
| 102 | long start = System.nanoTime(); |
| 103 | Set<FlowEntryWrapper> graphEntries = getFlowEntriesFromGraph(); |
| 104 | long step1 = System.nanoTime(); |
| 105 | Set<FlowEntryWrapper> switchEntries = getFlowEntriesFromSwitch(); |
| 106 | if (switchEntries == null) { |
| 107 | log.debug("getFlowEntriesFromSwitch() failed"); |
| 108 | return null; |
| 109 | } |
| 110 | long step2 = System.nanoTime(); |
| 111 | SyncResult result = compare(graphEntries, switchEntries); |
| 112 | long step3 = System.nanoTime(); |
| 113 | graphIDTime = (step1 - start); |
| 114 | switchTime = (step2 - step1); |
| 115 | compareTime = (step3 - step2); |
| 116 | totalTime = (step3 - start); |
| 117 | outputTime(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 118 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 119 | return result; |
| 120 | } finally { |
| 121 | pusher.resume(sw); |
| 122 | } |
| 123 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 124 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 125 | private void outputTime() { |
| 126 | double div = Math.pow(10, 6); //convert nanoseconds to ms |
| 127 | graphIDTime /= div; |
| 128 | switchTime /= div; |
| 129 | compareTime = (compareTime - graphEntryTime - extractTime - pushTime) / div; |
| 130 | graphEntryTime /= div; |
| 131 | extractTime /= div; |
| 132 | pushTime /= div; |
| 133 | totalTime /= div; |
| 134 | log.debug("Sync time (ms):{},{},{},{},{},{},{}" |
| 135 | , graphIDTime |
| 136 | , switchTime |
| 137 | , compareTime |
| 138 | , graphEntryTime |
| 139 | , extractTime |
| 140 | , pushTime |
| 141 | , totalTime); |
| 142 | } |
Pavlin Radoslavov | 4cf8ee5 | 2014-03-26 18:19:58 -0700 | [diff] [blame] | 143 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 144 | /** |
| 145 | * Compare flows entries in GraphDB and switch to pick up necessary |
| 146 | * messages. |
| 147 | * After picking up, picked messages are added to FlowPusher. |
| 148 | * |
| 149 | * @param graphEntries Flow entries in GraphDB. |
| 150 | * @param switchEntries Flow entries in switch. |
| 151 | */ |
| 152 | private SyncResult compare(Set<FlowEntryWrapper> graphEntries, Set<FlowEntryWrapper> switchEntries) { |
| 153 | int added = 0, removed = 0, skipped = 0; |
| 154 | for (FlowEntryWrapper entry : switchEntries) { |
| 155 | if (graphEntries.contains(entry)) { |
| 156 | graphEntries.remove(entry); |
| 157 | skipped++; |
| 158 | } else { |
| 159 | // remove flow entry from the switch |
| 160 | entry.removeFromSwitch(sw); |
| 161 | removed++; |
| 162 | } |
| 163 | } |
| 164 | for (FlowEntryWrapper entry : graphEntries) { |
| 165 | // add flow entry to switch |
| 166 | entry.addToSwitch(sw); |
| 167 | graphEntryTime += entry.dbTime; |
| 168 | extractTime += entry.extractTime; |
| 169 | pushTime += entry.pushTime; |
| 170 | added++; |
| 171 | } |
| 172 | log.debug("Flow entries added {}, " + |
| 173 | "Flow entries removed {}, " + |
| 174 | "Flow entries skipped {}" |
| 175 | , added |
| 176 | , removed |
| 177 | , skipped); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 178 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 179 | return new SyncResult(added, removed, skipped); |
| 180 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 181 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Read GraphDB to get FlowEntries associated with a switch. |
| 184 | * |
| 185 | * @return set of FlowEntries |
| 186 | */ |
| 187 | private Set<FlowEntryWrapper> getFlowEntriesFromGraph() { |
| 188 | Set<FlowEntryWrapper> entries = new HashSet<FlowEntryWrapper>(); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 189 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 190 | // TODO: fix when FlowSynchronizer is refactored |
| 191 | /* |
| 192 | for(IFlowEntry entry : swObj.getFlowEntries()) { |
| 193 | FlowEntryWrapper fe = new FlowEntryWrapper(entry); |
| 194 | entries.add(fe); |
| 195 | } |
| 196 | */ |
| 197 | return entries; |
| 198 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 199 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 200 | /** |
| 201 | * Read flow table from switch and derive FlowEntries from table. |
| 202 | * |
| 203 | * @return set of FlowEntries |
| 204 | */ |
| 205 | private Set<FlowEntryWrapper> getFlowEntriesFromSwitch() { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 206 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 207 | int lengthU = 0; |
| 208 | OFMatch match = new OFMatch(); |
| 209 | match.setWildcards(OFMatch.OFPFW_ALL); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 210 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 211 | OFFlowStatisticsRequest stat = new OFFlowStatisticsRequest(); |
| 212 | stat.setOutPort((short) 0xffff); //TODO: OFPort.OFPP_NONE |
| 213 | stat.setTableId((byte) 0xff); // TODO: fix this with enum (ALL TABLES) |
| 214 | stat.setMatch(match); |
| 215 | List<OFStatistics> stats = new ArrayList<OFStatistics>(); |
| 216 | stats.add(stat); |
| 217 | lengthU += stat.getLength(); |
| 218 | |
| 219 | OFStatisticsRequest req = new OFStatisticsRequest(); |
| 220 | req.setStatisticType(OFStatisticsType.FLOW); |
| 221 | req.setStatistics(stats); |
| 222 | lengthU += req.getLengthU(); |
| 223 | req.setLengthU(lengthU); |
| 224 | |
| 225 | List<OFStatistics> entries = null; |
| 226 | try { |
| 227 | Future<List<OFStatistics>> dfuture = sw.getStatistics(req); |
| 228 | entries = dfuture.get(); |
| 229 | } catch (IOException e) { |
| 230 | // TODO Auto-generated catch block |
| 231 | e.printStackTrace(); |
| 232 | return null; |
| 233 | } catch (InterruptedException e) { |
| 234 | // TODO Auto-generated catch block |
| 235 | e.printStackTrace(); |
| 236 | return null; |
| 237 | } catch (ExecutionException e) { |
| 238 | // TODO Auto-generated catch block |
| 239 | e.printStackTrace(); |
| 240 | return null; |
| 241 | } |
| 242 | |
| 243 | Set<FlowEntryWrapper> results = new HashSet<FlowEntryWrapper>(); |
| 244 | for (OFStatistics result : entries) { |
| 245 | OFFlowStatisticsReply entry = (OFFlowStatisticsReply) result; |
| 246 | FlowEntryWrapper fe = new FlowEntryWrapper(entry); |
| 247 | results.add(fe); |
| 248 | } |
| 249 | return results; |
| 250 | } |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 251 | |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 254 | /** |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 255 | * FlowEntryWrapper represents abstract FlowEntry which is embodied |
| 256 | * by FlowEntryId (from GraphDB) or OFFlowStatisticsReply (from switch). |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 257 | * |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 258 | * @author Brian |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 259 | */ |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 260 | class FlowEntryWrapper { |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 261 | FlowEntryId flowEntryId; |
| 262 | // TODO: fix when FlowSynchronizer is refactored |
| 263 | // IFlowEntry iFlowEntry; |
| 264 | OFFlowStatisticsReply statisticsReply; |
Naoki Shiota | f74d5f3 | 2014-01-09 21:29:38 -0800 | [diff] [blame] | 265 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 266 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 267 | // TODO: fix when FlowSynchronizer is refactored |
| 268 | /* |
| 269 | public FlowEntryWrapper(IFlowEntry entry) { |
| 270 | flowEntryId = new FlowEntryId(entry.getFlowEntryId()); |
| 271 | iFlowEntry = entry; |
| 272 | } |
| 273 | */ |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 274 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 275 | public FlowEntryWrapper(OFFlowStatisticsReply entry) { |
| 276 | flowEntryId = new FlowEntryId(entry.getCookie()); |
| 277 | statisticsReply = entry; |
| 278 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 279 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 280 | /** |
| 281 | * Install this FlowEntry to a switch via FlowPusher. |
| 282 | * |
| 283 | * @param sw Switch to which flow will be installed. |
| 284 | */ |
| 285 | double dbTime, extractTime, pushTime; |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 286 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 287 | public void addToSwitch(IOFSwitch sw) { |
| 288 | if (statisticsReply != null) { |
| 289 | log.error("Error adding existing flow entry {} to sw {}", |
| 290 | statisticsReply.getCookie(), sw.getId()); |
| 291 | return; |
Naoki Shiota | f74d5f3 | 2014-01-09 21:29:38 -0800 | [diff] [blame] | 292 | } |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 293 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 294 | double startDB = System.nanoTime(); |
| 295 | // Get the Flow Entry state from the Network Graph |
| 296 | // TODO: fix when FlowSynchronizer is refactored |
| 297 | /* |
| 298 | if (iFlowEntry == null) { |
| 299 | try { |
| 300 | // TODO: fix when FlowSynchronizer is refactored |
| 301 | iFlowEntry = dbHandler.searchFlowEntry(flowEntryId); |
| 302 | } catch (Exception e) { |
| 303 | log.error("Error finding flow entry {} in Network Graph", |
| 304 | flowEntryId); |
| 305 | return; |
| 306 | } |
| 307 | } |
| 308 | */ |
| 309 | dbTime = System.nanoTime() - startDB; |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 310 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 311 | // |
| 312 | // TODO: The old FlowDatabaseOperation class is gone, so the code |
| 313 | // |
| 314 | /* |
| 315 | double startExtract = System.nanoTime(); |
| 316 | FlowEntry flowEntry = |
| 317 | FlowDatabaseOperation.extractFlowEntry(iFlowEntry); |
| 318 | if (flowEntry == null) { |
| 319 | log.error("Cannot add flow entry {} to sw {} : flow entry cannot be extracted", |
| 320 | flowEntryId, sw.getId()); |
| 321 | return; |
| 322 | } |
| 323 | extractTime = System.nanoTime() - startExtract; |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 324 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 325 | double startPush = System.nanoTime(); |
| 326 | pusher.pushFlowEntry(sw, flowEntry, MsgPriority.HIGH); |
| 327 | pushTime = System.nanoTime() - startPush; |
| 328 | */ |
| 329 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 330 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 331 | /** |
| 332 | * Remove this FlowEntry from a switch via FlowPusher. |
| 333 | * |
| 334 | * @param sw Switch from which flow will be removed. |
| 335 | */ |
| 336 | public void removeFromSwitch(IOFSwitch sw) { |
| 337 | if (statisticsReply == null) { |
| 338 | log.error("Error removing non-existent flow entry {} from sw {}", |
| 339 | flowEntryId, sw.getId()); |
| 340 | return; |
| 341 | } |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 342 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 343 | // Convert Statistics Reply to Flow Mod, then write it |
| 344 | OFFlowMod fm = new OFFlowMod(); |
| 345 | fm.setCookie(statisticsReply.getCookie()); |
| 346 | fm.setCommand(OFFlowMod.OFPFC_DELETE_STRICT); |
| 347 | fm.setLengthU(OFFlowMod.MINIMUM_LENGTH); |
| 348 | fm.setMatch(statisticsReply.getMatch()); |
| 349 | fm.setPriority(statisticsReply.getPriority()); |
| 350 | fm.setOutPort(OFPort.OFPP_NONE); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 351 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 352 | pusher.add(sw, fm, MsgPriority.HIGH); |
| 353 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 354 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 355 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 356 | * Return the hash code of the Flow Entry ID. |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 357 | */ |
| 358 | @Override |
| 359 | public int hashCode() { |
| 360 | return flowEntryId.hashCode(); |
| 361 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 362 | |
Ray Milkey | 8e5170e | 2014-04-02 12:09:55 -0700 | [diff] [blame] | 363 | /** |
| 364 | * Returns true of the object is another Flow Entry ID with |
| 365 | * the same value; otherwise, returns false. |
| 366 | * |
| 367 | * @param Object to compare |
| 368 | * @return true if the object has the same Flow Entry ID. |
| 369 | */ |
| 370 | @Override |
| 371 | public boolean equals(Object obj) { |
| 372 | if (obj != null && obj.getClass() == this.getClass()) { |
| 373 | FlowEntryWrapper entry = (FlowEntryWrapper) obj; |
| 374 | // TODO: we need to actually compare the match + actions |
| 375 | return this.flowEntryId.equals(entry.flowEntryId); |
| 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public String toString() { |
| 382 | return flowEntryId.toString(); |
| 383 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 384 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 385 | } |