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