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