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