Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.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; |
| 10 | import java.util.concurrent.ExecutionException; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 11 | import java.util.concurrent.Future; |
| 12 | |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 13 | import org.openflow.protocol.OFFlowMod; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 14 | import org.openflow.protocol.OFMatch; |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 15 | import org.openflow.protocol.OFPort; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 16 | import org.openflow.protocol.OFStatisticsRequest; |
| 17 | import org.openflow.protocol.statistics.OFFlowStatisticsReply; |
| 18 | import org.openflow.protocol.statistics.OFFlowStatisticsRequest; |
| 19 | import org.openflow.protocol.statistics.OFStatistics; |
| 20 | import org.openflow.protocol.statistics.OFStatisticsType; |
| 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 24 | import net.floodlightcontroller.core.IOFSwitch; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 25 | import net.onrc.onos.graph.GraphDBOperation; |
| 26 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 27 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Pavlin Radoslavov | 6bfaea6 | 2013-12-03 14:55:57 -0800 | [diff] [blame] | 28 | import net.onrc.onos.ofcontroller.flowmanager.FlowDatabaseOperation; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 29 | import net.onrc.onos.ofcontroller.util.Dpid; |
Pavlin Radoslavov | 6bfaea6 | 2013-12-03 14:55:57 -0800 | [diff] [blame] | 30 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 31 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 32 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 33 | /** |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 34 | * FlowSynchronizer is an implementation of FlowSyncService. |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 35 | * In addition to IFlowSyncService, FlowSynchronizer periodically reads flow |
| 36 | * tables from switches and compare them with GraphDB to drop unnecessary |
| 37 | * flows and/or to install missing flows. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 38 | * @author Brian |
| 39 | * |
| 40 | */ |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 41 | public class FlowSynchronizer implements IFlowSyncService { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 42 | |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 43 | private static Logger log = LoggerFactory.getLogger(FlowSynchronizer.class); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 44 | |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 45 | private GraphDBOperation dbHandler; |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 46 | protected IFlowPusherService pusher; |
| 47 | private Map<IOFSwitch, Thread> switchThreads; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 48 | |
| 49 | public FlowSynchronizer() { |
| 50 | dbHandler = new GraphDBOperation(""); |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 51 | switchThreads = new HashMap<IOFSwitch, Thread>(); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 54 | @Override |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 55 | public void synchronize(IOFSwitch sw) { |
Pavlin Radoslavov | f8c7855 | 2013-11-26 10:56:59 -0800 | [diff] [blame] | 56 | Synchronizer sync = new Synchronizer(sw); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 57 | Thread t = new Thread(sync); |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 58 | switchThreads.put(sw, t); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 59 | t.start(); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 60 | } |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [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) { |
| 64 | Thread t = switchThreads.remove(sw); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 65 | if(t != null) { |
| 66 | t.interrupt(); |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 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. |
| 72 | * @param pusherService FlowPusherService used for sending messages. |
| 73 | */ |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 74 | public void init(IFlowPusherService pusherService) { |
| 75 | pusher = pusherService; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Synchronizer represents main thread of synchronization. |
| 80 | * @author Brian |
| 81 | * |
| 82 | */ |
| 83 | protected class Synchronizer implements Runnable { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 84 | IOFSwitch sw; |
| 85 | ISwitchObject swObj; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 86 | |
Pavlin Radoslavov | f8c7855 | 2013-11-26 10:56:59 -0800 | [diff] [blame] | 87 | public Synchronizer(IOFSwitch sw) { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 88 | this.sw = sw; |
| 89 | Dpid dpid = new Dpid(sw.getId()); |
| 90 | this.swObj = dbHandler.searchSwitch(dpid.toString()); |
| 91 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 92 | |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 93 | @Override |
| 94 | public void run() { |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 95 | // TODO: stop adding other flow entries while synchronizing |
| 96 | //pusher.suspend(sw); |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 97 | Set<FlowEntryWrapper> graphEntries = getFlowEntriesFromGraph(); |
| 98 | Set<FlowEntryWrapper> switchEntries = getFlowEntriesFromSwitch(); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 99 | compare(graphEntries, switchEntries); |
Brian O'Connor | ea1efbe | 2013-11-25 22:57:43 -0800 | [diff] [blame] | 100 | //pusher.resume(sw); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 101 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 102 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 103 | /** |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 104 | * Compare flows entries in GraphDB and switch to pick up necessary |
| 105 | * messages. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 106 | * After picking up, picked messages are added to FlowPusher. |
| 107 | * @param graphEntries Flow entries in GraphDB. |
| 108 | * @param switchEntries Flow entries in switch. |
| 109 | */ |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 110 | private void compare(Set<FlowEntryWrapper> graphEntries, Set<FlowEntryWrapper> switchEntries) { |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 111 | int added = 0, removed = 0, skipped = 0; |
| 112 | for(FlowEntryWrapper entry : switchEntries) { |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 113 | if(graphEntries.contains(entry)) { |
| 114 | graphEntries.remove(entry); |
| 115 | skipped++; |
| 116 | } |
| 117 | else { |
| 118 | // remove flow entry from the switch |
| 119 | entry.removeFromSwitch(sw); |
| 120 | removed++; |
| 121 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 122 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 123 | for(FlowEntryWrapper entry : graphEntries) { |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 124 | // add flow entry to switch |
| 125 | entry.addToSwitch(sw); |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 126 | added++; |
| 127 | } |
| 128 | log.debug("Flow entries added "+ added + ", " + |
| 129 | "Flow entries removed "+ removed + ", " + |
| 130 | "Flow entries skipped " + skipped); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 131 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 132 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Read GraphDB to get FlowEntries associated with a switch. |
| 135 | * @return set of FlowEntries |
| 136 | */ |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 137 | private Set<FlowEntryWrapper> getFlowEntriesFromGraph() { |
| 138 | Set<FlowEntryWrapper> entries = new HashSet<FlowEntryWrapper>(); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 139 | for(IFlowEntry entry : swObj.getFlowEntries()) { |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 140 | FlowEntryWrapper fe = new FlowEntryWrapper(entry); |
| 141 | entries.add(fe); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 142 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 143 | return entries; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 144 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 145 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 146 | /** |
| 147 | * Read flow table from switch and derive FlowEntries from table. |
| 148 | * @return set of FlowEntries |
| 149 | */ |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 150 | private Set<FlowEntryWrapper> getFlowEntriesFromSwitch() { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 151 | |
| 152 | int lengthU = 0; |
| 153 | OFMatch match = new OFMatch(); |
| 154 | match.setWildcards(OFMatch.OFPFW_ALL); |
| 155 | |
| 156 | OFFlowStatisticsRequest stat = new OFFlowStatisticsRequest(); |
| 157 | stat.setOutPort((short) 0xffff); //TODO: OFPort.OFPP_NONE |
| 158 | stat.setTableId((byte) 0xff); // TODO: fix this with enum (ALL TABLES) |
| 159 | stat.setMatch(match); |
| 160 | List<OFStatistics> stats = new ArrayList<OFStatistics>(); |
| 161 | stats.add(stat); |
| 162 | lengthU += stat.getLength(); |
| 163 | |
| 164 | OFStatisticsRequest req = new OFStatisticsRequest(); |
| 165 | req.setStatisticType(OFStatisticsType.FLOW); |
| 166 | req.setStatistics(stats); |
| 167 | lengthU += req.getLengthU(); |
| 168 | req.setLengthU(lengthU); |
| 169 | |
| 170 | List<OFStatistics> entries = null; |
| 171 | try { |
| 172 | Future<List<OFStatistics>> dfuture = sw.getStatistics(req); |
| 173 | entries = dfuture.get(); |
| 174 | } catch (IOException e) { |
| 175 | // TODO Auto-generated catch block |
| 176 | e.printStackTrace(); |
| 177 | } catch (InterruptedException e) { |
| 178 | // TODO Auto-generated catch block |
| 179 | e.printStackTrace(); |
| 180 | } catch (ExecutionException e) { |
| 181 | // TODO Auto-generated catch block |
| 182 | e.printStackTrace(); |
| 183 | } |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 184 | |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 185 | Set<FlowEntryWrapper> results = new HashSet<FlowEntryWrapper>(); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 186 | for(OFStatistics result : entries){ |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 187 | OFFlowStatisticsReply entry = (OFFlowStatisticsReply) result; |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 188 | FlowEntryWrapper fe = new FlowEntryWrapper(entry); |
| 189 | results.add(fe); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 190 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 191 | return results; |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 192 | } |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 193 | |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 196 | /** |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 197 | * FlowEntryWrapper represents abstract FlowEntry which is embodied |
| 198 | * by FlowEntryId (from GraphDB) or OFFlowStatisticsReply (from switch). |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 199 | * @author Brian |
| 200 | * |
| 201 | */ |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 202 | class FlowEntryWrapper { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 203 | FlowEntryId flowEntryId; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 204 | OFFlowStatisticsReply statisticsReply; |
| 205 | |
| 206 | public FlowEntryWrapper(IFlowEntry entry) { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 207 | flowEntryId = new FlowEntryId(entry.getFlowEntryId()); |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 210 | public FlowEntryWrapper(OFFlowStatisticsReply entry) { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 211 | flowEntryId = new FlowEntryId(entry.getCookie()); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 212 | statisticsReply = entry; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 213 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 214 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 215 | /** |
| 216 | * Install this FlowEntry to a switch via FlowPusher. |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 217 | * @param sw Switch to which flow will be installed. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 218 | */ |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 219 | public void addToSwitch(IOFSwitch sw) { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 220 | if (statisticsReply != null) { |
| 221 | log.error("Error adding existing flow entry {} to sw {}", |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 222 | statisticsReply.getCookie(), sw.getId()); |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 223 | return; |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 224 | } |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 225 | |
| 226 | // Get the Flow Entry state from the Network Graph |
| 227 | IFlowEntry iFlowEntry = null; |
| 228 | try { |
| 229 | iFlowEntry = dbHandler.searchFlowEntry(flowEntryId); |
| 230 | } catch (Exception e) { |
| 231 | log.error("Error finding flow entry {} in Network Graph", |
| 232 | flowEntryId); |
| 233 | return; |
| 234 | } |
| 235 | if (iFlowEntry == null) { |
| 236 | log.error("Cannot add flow entry {} to sw {} : flow entry not found", |
| 237 | flowEntryId, sw.getId()); |
| 238 | return; |
| 239 | } |
| 240 | |
Pavlin Radoslavov | 6bfaea6 | 2013-12-03 14:55:57 -0800 | [diff] [blame] | 241 | FlowEntry flowEntry = |
| 242 | FlowDatabaseOperation.extractFlowEntry(iFlowEntry); |
| 243 | if (flowEntry == null) { |
| 244 | log.error("Cannot add flow entry {} to sw {} : flow entry cannot be extracted", |
| 245 | flowEntryId, sw.getId()); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | pusher.add(sw, flowEntry); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 252 | /** |
| 253 | * Remove this FlowEntry from a switch via FlowPusher. |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 254 | * @param sw Switch from which flow will be removed. |
Naoki Shiota | e319973 | 2013-11-25 16:14:43 -0800 | [diff] [blame] | 255 | */ |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 256 | public void removeFromSwitch(IOFSwitch sw) { |
| 257 | if (statisticsReply == null) { |
| 258 | log.error("Error removing non-existent flow entry {} from sw {}", |
| 259 | flowEntryId, sw.getId()); |
| 260 | return; |
| 261 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 262 | |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 263 | // Convert Statistics Reply to Flow Mod, then write it |
| 264 | OFFlowMod fm = new OFFlowMod(); |
| 265 | fm.setCookie(statisticsReply.getCookie()); |
| 266 | fm.setCommand(OFFlowMod.OFPFC_DELETE_STRICT); |
| 267 | fm.setLengthU(OFFlowMod.MINIMUM_LENGTH); |
| 268 | fm.setMatch(statisticsReply.getMatch()); |
| 269 | fm.setPriority(statisticsReply.getPriority()); |
| 270 | fm.setOutPort(OFPort.OFPP_NONE); |
| 271 | |
| 272 | pusher.add(sw, fm); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 273 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 274 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 275 | /** |
| 276 | * Return the hash code of the Flow Entry ID |
| 277 | */ |
| 278 | @Override |
| 279 | public int hashCode() { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 280 | return flowEntryId.hashCode(); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 281 | } |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 282 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 283 | /** |
| 284 | * Returns true of the object is another Flow Entry ID with |
| 285 | * the same value; otherwise, returns false. |
| 286 | * |
| 287 | * @param Object to compare |
Naoki Shiota | b485d41 | 2013-11-26 12:04:19 -0800 | [diff] [blame] | 288 | * @return true if the object has the same Flow Entry ID. |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 289 | */ |
| 290 | @Override |
| 291 | public boolean equals(Object obj){ |
| 292 | if(obj.getClass() == this.getClass()) { |
| 293 | FlowEntryWrapper entry = (FlowEntryWrapper) obj; |
| 294 | // TODO: we need to actually compare the match + actions |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 295 | return this.flowEntryId.equals(entry.flowEntryId); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 296 | } |
| 297 | return false; |
| 298 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 299 | |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 300 | @Override |
| 301 | public String toString() { |
Pavlin Radoslavov | 07fb997 | 2013-12-02 16:20:24 -0800 | [diff] [blame] | 302 | return flowEntryId.toString(); |
Brian O'Connor | e46492e | 2013-11-14 21:11:50 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
Brian O'Connor | 0d6ba51 | 2013-11-05 15:17:44 -0800 | [diff] [blame] | 305 | } |