Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
| 2 | |
| 3 | import java.io.PrintWriter; |
| 4 | import java.io.StringWriter; |
| 5 | import java.util.ArrayList; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 6 | import java.util.LinkedList; |
| 7 | import java.util.List; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 8 | |
| 9 | import net.floodlightcontroller.util.MACAddress; |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 10 | import net.onrc.onos.graph.DBOperation; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 12 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 13 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 14 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 15 | import net.onrc.onos.ofcontroller.util.*; |
| 16 | |
| 17 | import org.slf4j.Logger; |
| 18 | import org.slf4j.LoggerFactory; |
| 19 | |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 20 | import com.tinkerpop.blueprints.impls.ramcloud.PerfMon; |
| 21 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Class for performing Flow-related operations on the Database. |
| 24 | */ |
Pavlin Radoslavov | 6bfaea6 | 2013-12-03 14:55:57 -0800 | [diff] [blame] | 25 | public class FlowDatabaseOperation { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 26 | private final static Logger log = LoggerFactory.getLogger(FlowDatabaseOperation.class); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 27 | private static final boolean measureONOSFlowTimeProp = Long.valueOf(System.getProperty("benchmark.measureONOSFlow", "0")) != 0; |
| 28 | private static final boolean measureONOSFlowEntryTimeProp = Long.valueOf(System.getProperty("benchmark.measureONOSFlowEntry", "0")) != 0; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Add a flow. |
| 32 | * |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 33 | * @param dbHandler the Graph Database handler to use. |
| 34 | * @param flowPath the Flow Path to install. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 35 | * @return true on success, otherwise false. |
| 36 | */ |
onlab-qa | 38805cd | 2013-12-06 20:08:54 -0800 | [diff] [blame] | 37 | static boolean addFlow(DBOperation dbHandler, FlowPath flowPath) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 38 | IFlowPath flowObj = null; |
| 39 | boolean found = false; |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 40 | long startAddFlow = 0; |
| 41 | long endAddFlow = 0; |
| 42 | long endSearchExistingFlowPathTime = 0; |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 43 | long startCreateNewFlowPathTime = 0; |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 44 | long endCreateNewFlowPathTime = 0; |
| 45 | long startFollowExistingFlowEntries = 0; |
| 46 | long endFollowExistingFlowEntries = 0; |
| 47 | long accTimeRemovingFlowEntriesFromFlowPath = 0; |
| 48 | long accTimeRemovingFlowEntriesFromDB = 0; |
| 49 | long startSettingFlowPathProps = 0; |
| 50 | long endSettingFlowPathProps = 0; |
| 51 | int numPropsSet = 0; |
| 52 | long accTimeAddFlowEntries = 0; |
| 53 | int numNewFlowEntries = 0; |
| 54 | LinkedList<long[]> flowEntryTimes = new LinkedList<>(); |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 55 | PerfMon pm = PerfMon.getInstance(); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 56 | |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 57 | pm.addflowpath_start(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 58 | try { |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 59 | if ( measureONOSFlowTimeProp ) { |
| 60 | startAddFlow = System.nanoTime(); |
| 61 | } |
yoshi | 4021094 | 2013-12-03 08:21:02 -0800 | [diff] [blame] | 62 | flowObj = dbHandler.searchFlowPath(flowPath.flowId()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 63 | if ( measureONOSFlowTimeProp ) { |
| 64 | endSearchExistingFlowPathTime = System.nanoTime(); |
| 65 | } |
yoshi | 4021094 | 2013-12-03 08:21:02 -0800 | [diff] [blame] | 66 | if (flowObj != null) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 67 | found = true; |
| 68 | } else { |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 69 | if ( measureONOSFlowTimeProp ) { |
| 70 | startCreateNewFlowPathTime = System.nanoTime(); |
| 71 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 72 | flowObj = dbHandler.newFlowPath(); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 73 | if ( measureONOSFlowTimeProp ) { |
| 74 | endCreateNewFlowPathTime = System.nanoTime(); |
| 75 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 76 | } |
| 77 | } catch (Exception e) { |
| 78 | dbHandler.rollback(); |
| 79 | |
| 80 | StringWriter sw = new StringWriter(); |
| 81 | e.printStackTrace(new PrintWriter(sw)); |
| 82 | String stacktrace = sw.toString(); |
| 83 | |
| 84 | log.error(":addFlow FlowId:{} failed: {}", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 85 | flowPath.flowId(), |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 86 | stacktrace); |
| 87 | return false; |
| 88 | } |
| 89 | if (flowObj == null) { |
| 90 | log.error(":addFlow FlowId:{} failed: Flow object not created", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 91 | flowPath.flowId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 92 | dbHandler.rollback(); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 97 | // Remove the old Flow Entries |
| 98 | // |
| 99 | if (found) { |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 100 | if ( measureONOSFlowTimeProp ) { |
| 101 | startFollowExistingFlowEntries = System.nanoTime(); |
| 102 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 103 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 104 | if ( measureONOSFlowTimeProp ) { |
| 105 | endFollowExistingFlowEntries = System.nanoTime(); |
| 106 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 107 | LinkedList<IFlowEntry> deleteFlowEntries = |
| 108 | new LinkedList<IFlowEntry>(); |
| 109 | for (IFlowEntry flowEntryObj : flowEntries) |
| 110 | deleteFlowEntries.add(flowEntryObj); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 111 | if( measureONOSFlowTimeProp ) { |
| 112 | for (IFlowEntry flowEntryObj : deleteFlowEntries) { |
| 113 | long start = System.nanoTime(); |
| 114 | flowObj.removeFlowEntry(flowEntryObj); |
| 115 | accTimeRemovingFlowEntriesFromFlowPath += System.nanoTime() - start; |
| 116 | start = System.nanoTime(); |
| 117 | dbHandler.removeFlowEntry(flowEntryObj); |
| 118 | accTimeRemovingFlowEntriesFromDB += System.nanoTime() - start; |
| 119 | } |
| 120 | } else { |
| 121 | for (IFlowEntry flowEntryObj : deleteFlowEntries) { |
| 122 | flowObj.removeFlowEntry(flowEntryObj); |
| 123 | dbHandler.removeFlowEntry(flowEntryObj); |
| 124 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 128 | if ( measureONOSFlowTimeProp ) { |
| 129 | startSettingFlowPathProps = System.nanoTime(); |
| 130 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 131 | // |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 132 | // Set the Flow key: |
| 133 | // - flowId |
| 134 | // |
| 135 | flowObj.setFlowId(flowPath.flowId().toString()); |
| 136 | flowObj.setType("flow"); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 137 | if ( measureONOSFlowTimeProp ) { |
| 138 | numPropsSet += 2; |
| 139 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 140 | |
| 141 | // |
| 142 | // Set the Flow attributes: |
| 143 | // - flowPath.installerId() |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 144 | // - flowPath.flowPathType() |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 145 | // - flowPath.flowPathUserState() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 146 | // - flowPath.flowPathFlags() |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 147 | // - flowPath.idleTimeout() |
| 148 | // - flowPath.hardTimeout() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 149 | // - flowPath.dataPath().srcPort() |
| 150 | // - flowPath.dataPath().dstPort() |
| 151 | // - flowPath.matchSrcMac() |
| 152 | // - flowPath.matchDstMac() |
| 153 | // - flowPath.matchEthernetFrameType() |
| 154 | // - flowPath.matchVlanId() |
| 155 | // - flowPath.matchVlanPriority() |
| 156 | // - flowPath.matchSrcIPv4Net() |
| 157 | // - flowPath.matchDstIPv4Net() |
| 158 | // - flowPath.matchIpProto() |
| 159 | // - flowPath.matchIpToS() |
| 160 | // - flowPath.matchSrcTcpUdpPort() |
| 161 | // - flowPath.matchDstTcpUdpPort() |
| 162 | // - flowPath.flowEntryActions() |
| 163 | // |
| 164 | flowObj.setInstallerId(flowPath.installerId().toString()); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 165 | flowObj.setFlowPathType(flowPath.flowPathType().toString()); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 166 | flowObj.setFlowPathUserState(flowPath.flowPathUserState().toString()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 167 | flowObj.setFlowPathFlags(flowPath.flowPathFlags().flags()); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 168 | flowObj.setIdleTimeout(flowPath.idleTimeout()); |
| 169 | flowObj.setHardTimeout(flowPath.hardTimeout()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 170 | flowObj.setSrcSwitch(flowPath.dataPath().srcPort().dpid().toString()); |
| 171 | flowObj.setSrcPort(flowPath.dataPath().srcPort().port().value()); |
| 172 | flowObj.setDstSwitch(flowPath.dataPath().dstPort().dpid().toString()); |
| 173 | flowObj.setDstPort(flowPath.dataPath().dstPort().port().value()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 174 | if ( measureONOSFlowTimeProp ) { |
| 175 | numPropsSet += 10; |
| 176 | } |
| 177 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 178 | if (flowPath.flowEntryMatch().matchSrcMac()) { |
| 179 | flowObj.setMatchSrcMac(flowPath.flowEntryMatch().srcMac().toString()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 180 | if ( measureONOSFlowTimeProp ) { |
| 181 | ++numPropsSet; |
| 182 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 183 | } |
| 184 | if (flowPath.flowEntryMatch().matchDstMac()) { |
| 185 | flowObj.setMatchDstMac(flowPath.flowEntryMatch().dstMac().toString()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 186 | if ( measureONOSFlowTimeProp ) { |
| 187 | ++numPropsSet; |
| 188 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 189 | } |
| 190 | if (flowPath.flowEntryMatch().matchEthernetFrameType()) { |
| 191 | flowObj.setMatchEthernetFrameType(flowPath.flowEntryMatch().ethernetFrameType()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 192 | if ( measureONOSFlowTimeProp ) { |
| 193 | ++numPropsSet; |
| 194 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 195 | } |
| 196 | if (flowPath.flowEntryMatch().matchVlanId()) { |
| 197 | flowObj.setMatchVlanId(flowPath.flowEntryMatch().vlanId()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 198 | if ( measureONOSFlowTimeProp ) { |
| 199 | ++numPropsSet; |
| 200 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 201 | } |
| 202 | if (flowPath.flowEntryMatch().matchVlanPriority()) { |
| 203 | flowObj.setMatchVlanPriority(flowPath.flowEntryMatch().vlanPriority()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 204 | if ( measureONOSFlowTimeProp ) { |
| 205 | ++numPropsSet; |
| 206 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 207 | } |
| 208 | if (flowPath.flowEntryMatch().matchSrcIPv4Net()) { |
| 209 | flowObj.setMatchSrcIPv4Net(flowPath.flowEntryMatch().srcIPv4Net().toString()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 210 | if ( measureONOSFlowTimeProp ) { |
| 211 | ++numPropsSet; |
| 212 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 213 | } |
| 214 | if (flowPath.flowEntryMatch().matchDstIPv4Net()) { |
| 215 | flowObj.setMatchDstIPv4Net(flowPath.flowEntryMatch().dstIPv4Net().toString()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 216 | if ( measureONOSFlowTimeProp ) { |
| 217 | ++numPropsSet; |
| 218 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 219 | } |
| 220 | if (flowPath.flowEntryMatch().matchIpProto()) { |
| 221 | flowObj.setMatchIpProto(flowPath.flowEntryMatch().ipProto()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 222 | if ( measureONOSFlowTimeProp ) { |
| 223 | ++numPropsSet; |
| 224 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 225 | } |
| 226 | if (flowPath.flowEntryMatch().matchIpToS()) { |
| 227 | flowObj.setMatchIpToS(flowPath.flowEntryMatch().ipToS()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 228 | if ( measureONOSFlowTimeProp ) { |
| 229 | ++numPropsSet; |
| 230 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 231 | } |
| 232 | if (flowPath.flowEntryMatch().matchSrcTcpUdpPort()) { |
| 233 | flowObj.setMatchSrcTcpUdpPort(flowPath.flowEntryMatch().srcTcpUdpPort()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 234 | if ( measureONOSFlowTimeProp ) { |
| 235 | ++numPropsSet; |
| 236 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 237 | } |
| 238 | if (flowPath.flowEntryMatch().matchDstTcpUdpPort()) { |
| 239 | flowObj.setMatchDstTcpUdpPort(flowPath.flowEntryMatch().dstTcpUdpPort()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 240 | if ( measureONOSFlowTimeProp ) { |
| 241 | ++numPropsSet; |
| 242 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 243 | } |
| 244 | if (! flowPath.flowEntryActions().actions().isEmpty()) { |
| 245 | flowObj.setActions(flowPath.flowEntryActions().toString()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 246 | if ( measureONOSFlowTimeProp ) { |
| 247 | ++numPropsSet; |
| 248 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 249 | } |
Pavlin Radoslavov | bcc86ef | 2013-10-26 12:06:25 -0700 | [diff] [blame] | 250 | flowObj.setDataPathSummary(flowPath.dataPath().dataPathSummary()); |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 251 | if ( measureONOSFlowTimeProp ) { |
| 252 | ++numPropsSet; |
| 253 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 254 | |
| 255 | if (found) |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 256 | flowObj.setFlowPathUserState("FP_USER_MODIFY"); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 257 | else |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 258 | flowObj.setFlowPathUserState("FP_USER_ADD"); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 259 | |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 260 | if ( measureONOSFlowTimeProp ) { |
| 261 | ++numPropsSet; |
| 262 | } |
| 263 | |
| 264 | if ( measureONOSFlowTimeProp ) { |
| 265 | endSettingFlowPathProps = System.nanoTime(); |
| 266 | } |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 267 | pm.addflowpath_end(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 268 | // Flow edges: |
| 269 | // HeadFE |
| 270 | |
| 271 | |
| 272 | // |
| 273 | // Flow Entries: |
| 274 | // flowPath.dataPath().flowEntries() |
| 275 | // |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 276 | pm.addflowentry_start(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 277 | for (FlowEntry flowEntry : flowPath.dataPath().flowEntries()) { |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 278 | if (flowEntry.flowEntryUserState() == FlowEntryUserState.FE_USER_DELETE) |
| 279 | continue; // Skip: all Flow Entries were deleted earlier |
| 280 | |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 281 | pm.addflowentry_incr(); |
| 282 | |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 283 | long startAddFlowEntry = 0, endAddFlowEntry; |
| 284 | if( measureONOSFlowTimeProp ) { |
| 285 | startAddFlowEntry = System.nanoTime(); |
| 286 | } |
| 287 | IFlowEntry iFlowEntry = addFlowEntry(dbHandler, flowObj, flowEntry); |
| 288 | if( measureONOSFlowTimeProp ) { |
| 289 | endAddFlowEntry = System.nanoTime(); |
| 290 | accTimeAddFlowEntries += endAddFlowEntry - startAddFlowEntry; |
| 291 | |
| 292 | flowEntryTimes.addLast( new long[]{flowEntry.flowId().value(), endAddFlowEntry - startAddFlowEntry} ); |
| 293 | } |
| 294 | if ( iFlowEntry == null) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 295 | dbHandler.rollback(); |
| 296 | return false; |
| 297 | } |
| 298 | } |
Yuta HIGUCHI | dad0a2d | 2014-01-06 15:52:52 -0800 | [diff] [blame] | 299 | pm.addflowentry_end(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 300 | dbHandler.commit(); |
| 301 | |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 302 | |
| 303 | if ( measureONOSFlowTimeProp ) { |
| 304 | endAddFlow = System.nanoTime(); |
| 305 | |
Yuta HIGUCHI | 0b4fbaf | 2014-01-04 22:23:05 -0800 | [diff] [blame] | 306 | log.error("Performance addFlow(_,{}) -- " |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 307 | + "GrandTotal: {} " |
| 308 | + "only FlowPathTotal: {} " |
| 309 | + "searchExistingFlowPath: {} " |
| 310 | + "createNewFlowPathTime: {}" |
| 311 | + "followExistingFlowEntries: {} " |
| 312 | + "accTimeRemovingFlowEntriesFromFlowPath: {} " |
| 313 | + "accTimeRemovingFlowEntriesFromDB: {} " |
| 314 | + "settingFlowPathProps: {} #Props: {} " |
| 315 | + "accFlowEntries: {} #FEs: {}", |
| 316 | flowPath.flowId(), |
| 317 | (endAddFlow - startAddFlow), |
| 318 | (endSettingFlowPathProps - startAddFlow), |
| 319 | (endSearchExistingFlowPathTime - startAddFlow), |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 320 | (endCreateNewFlowPathTime - startCreateNewFlowPathTime), |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 321 | (endFollowExistingFlowEntries - startFollowExistingFlowEntries), |
| 322 | (accTimeRemovingFlowEntriesFromFlowPath), |
| 323 | (accTimeRemovingFlowEntriesFromDB), |
| 324 | (endSettingFlowPathProps - startSettingFlowPathProps), numPropsSet, |
| 325 | accTimeAddFlowEntries, numNewFlowEntries |
| 326 | ); |
| 327 | |
| 328 | // Each FlowEntries |
| 329 | final String strFlowId = flowPath.flowId().toString(); |
| 330 | for ( long[] idFE_Time : flowEntryTimes ) { |
Yuta HIGUCHI | 0b4fbaf | 2014-01-04 22:23:05 -0800 | [diff] [blame] | 331 | log.error("Performance addFlowEntry(_,{},{})@addFlow -- FlowEntryTotal: {}", |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 332 | strFlowId, |
| 333 | "0x" + Long.toHexString(idFE_Time[0]), |
| 334 | idFE_Time[1]); |
| 335 | } |
| 336 | } |
| 337 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 338 | return true; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Add a flow entry to the Network MAP. |
| 343 | * |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 344 | * @param dbHandler the Graph Database handler to use. |
| 345 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 346 | * @param flowEntry the Flow Entry to install. |
| 347 | * @return the added Flow Entry object on success, otherwise null. |
| 348 | */ |
onlab-qa | 38805cd | 2013-12-06 20:08:54 -0800 | [diff] [blame] | 349 | static IFlowEntry addFlowEntry(DBOperation dbHandler, |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 350 | IFlowPath flowObj, |
| 351 | FlowEntry flowEntry) { |
| 352 | // Flow edges |
| 353 | // HeadFE (TODO) |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 354 | long startAddFlowEntry = 0; |
| 355 | long endAddFlowEntry = 0; |
| 356 | |
| 357 | long endSearchFlowEntry = 0; |
| 358 | |
| 359 | long startCreateNewFlowEntry = 0; |
| 360 | long endCreateNewFlowEntry = 0; |
| 361 | |
| 362 | long startSetProperties = 0; |
| 363 | long endSetProperties = 0; |
| 364 | int numProperties = 0; |
| 365 | |
| 366 | long startSearchSwitch = 0; |
| 367 | long endSearchSwitch = 0; |
| 368 | |
| 369 | long startAddEdgeToSwitch =0; |
| 370 | long endAddEdgeToSwitch =0; |
| 371 | |
| 372 | long startSearchInPort = 0; |
| 373 | long endSearchInPort = 0; |
| 374 | |
| 375 | long startAddEdgeToInPort =0; |
| 376 | long endAddEdgeToInPort =0; |
| 377 | |
| 378 | long startSearchOutPort = 0; |
| 379 | long endSearchOutPort = 0; |
| 380 | |
| 381 | long startAddEdgeToOutPort =0; |
| 382 | long endAddEdgeToOutPort =0; |
| 383 | |
| 384 | long startAddEdgeBetweenFlowPath = 0; |
| 385 | long endAddEdgeBetweenFlowPath = 0; |
| 386 | |
| 387 | if (measureONOSFlowEntryTimeProp) { |
| 388 | startAddFlowEntry = System.nanoTime(); |
| 389 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 390 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 391 | IFlowEntry flowEntryObj = null; |
| 392 | boolean found = false; |
| 393 | try { |
Yuta HIGUCHI | c27a6c9 | 2014-01-07 11:51:11 -0800 | [diff] [blame] | 394 | flowEntryObj = dbHandler.searchFlowEntry(flowEntry.flowEntryId()); |
| 395 | if (measureONOSFlowEntryTimeProp) { |
| 396 | endSearchFlowEntry = System.nanoTime(); |
| 397 | } |
| 398 | if (flowEntryObj != null) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 399 | found = true; |
| 400 | } else { |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 401 | if (measureONOSFlowEntryTimeProp) { |
| 402 | startCreateNewFlowEntry = System.nanoTime(); |
| 403 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 404 | flowEntryObj = dbHandler.newFlowEntry(); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 405 | if (measureONOSFlowEntryTimeProp) { |
| 406 | endCreateNewFlowEntry = System.nanoTime(); |
| 407 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 408 | } |
| 409 | } catch (Exception e) { |
| 410 | log.error(":addFlow FlowEntryId:{} failed", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 411 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 412 | return null; |
| 413 | } |
| 414 | if (flowEntryObj == null) { |
| 415 | log.error(":addFlow FlowEntryId:{} failed: FlowEntry object not created", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 416 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 417 | return null; |
| 418 | } |
| 419 | |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 420 | if (measureONOSFlowEntryTimeProp) { |
| 421 | startSetProperties = System.nanoTime(); |
| 422 | } |
Yuta HIGUCHI | 8685f9c | 2014-01-07 15:53:28 -0800 | [diff] [blame] | 423 | |
Toshio Koide | 7f76e9e | 2014-01-09 22:06:35 -0800 | [diff] [blame] | 424 | FlowEntryProperty flowProp = new FlowEntryProperty(dbHandler, flowEntryObj); |
Yuta HIGUCHI | 8685f9c | 2014-01-07 15:53:28 -0800 | [diff] [blame] | 425 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 426 | // |
| 427 | // Set the Flow Entry key: |
| 428 | // - flowEntry.flowEntryId() |
| 429 | // |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 430 | flowProp.setFlowEntryId(flowEntry.flowEntryId().toString()); |
| 431 | flowProp.setType("flow_entry"); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 432 | if (measureONOSFlowEntryTimeProp) { |
| 433 | numProperties += 2; |
| 434 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 435 | |
Yuta HIGUCHI | 37c5547 | 2014-01-03 11:42:27 -0800 | [diff] [blame] | 436 | // |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 437 | // Set the Flow Entry Edges and attributes: |
| 438 | // - Switch edge |
| 439 | // - InPort edge |
| 440 | // - OutPort edge |
| 441 | // |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 442 | // - flowEntry.idleTimeout() |
| 443 | // - flowEntry.hardTimeout() |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 444 | // - flowEntry.dpid() |
| 445 | // - flowEntry.flowEntryUserState() |
| 446 | // - flowEntry.flowEntrySwitchState() |
| 447 | // - flowEntry.flowEntryErrorState() |
| 448 | // - flowEntry.matchInPort() |
| 449 | // - flowEntry.matchSrcMac() |
| 450 | // - flowEntry.matchDstMac() |
| 451 | // - flowEntry.matchEthernetFrameType() |
| 452 | // - flowEntry.matchVlanId() |
| 453 | // - flowEntry.matchVlanPriority() |
| 454 | // - flowEntry.matchSrcIPv4Net() |
| 455 | // - flowEntry.matchDstIPv4Net() |
| 456 | // - flowEntry.matchIpProto() |
| 457 | // - flowEntry.matchIpToS() |
| 458 | // - flowEntry.matchSrcTcpUdpPort() |
| 459 | // - flowEntry.matchDstTcpUdpPort() |
| 460 | // - flowEntry.actionOutputPort() |
| 461 | // - flowEntry.actions() |
| 462 | // |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 463 | if (measureONOSFlowEntryTimeProp) { |
| 464 | startSearchSwitch = System.nanoTime(); |
| 465 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 466 | ISwitchObject sw = dbHandler.searchSwitch(flowEntry.dpid().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 467 | if (measureONOSFlowEntryTimeProp) { |
| 468 | endSearchSwitch = System.nanoTime(); |
| 469 | } |
| 470 | |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 471 | flowProp.setIdleTimeout(flowEntry.idleTimeout()); |
| 472 | flowProp.setHardTimeout(flowEntry.hardTimeout()); |
| 473 | flowProp.setSwitchDpid(flowEntry.dpid().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 474 | if (measureONOSFlowEntryTimeProp) { |
| 475 | numProperties += 3; |
| 476 | } |
| 477 | |
| 478 | if (measureONOSFlowEntryTimeProp) { |
| 479 | startAddEdgeToSwitch = System.nanoTime(); |
| 480 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 481 | flowEntryObj.setSwitch(sw); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 482 | if (measureONOSFlowEntryTimeProp) { |
| 483 | endAddEdgeToSwitch = System.nanoTime(); |
| 484 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 485 | if (flowEntry.flowEntryMatch().matchInPort()) { |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 486 | if (measureONOSFlowEntryTimeProp) { |
| 487 | startSearchInPort = System.nanoTime(); |
| 488 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 489 | IPortObject inport = |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 490 | dbHandler.searchPort(flowEntry.dpid().toString(), |
| 491 | flowEntry.flowEntryMatch().inPort().value()); |
| 492 | if (measureONOSFlowEntryTimeProp) { |
| 493 | endSearchInPort = System.nanoTime(); |
| 494 | } |
| 495 | |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 496 | flowProp.setMatchInPort(flowEntry.flowEntryMatch().inPort().value()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 497 | if (measureONOSFlowEntryTimeProp) { |
| 498 | ++numProperties; |
| 499 | } |
| 500 | |
| 501 | if (measureONOSFlowEntryTimeProp) { |
| 502 | startAddEdgeToInPort = System.nanoTime(); |
| 503 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 504 | flowEntryObj.setInPort(inport); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 505 | if (measureONOSFlowEntryTimeProp) { |
| 506 | endAddEdgeToInPort = System.nanoTime(); |
| 507 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 508 | } |
| 509 | if (flowEntry.flowEntryMatch().matchSrcMac()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 510 | flowProp.setMatchSrcMac(flowEntry.flowEntryMatch().srcMac().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 511 | if (measureONOSFlowEntryTimeProp) { |
| 512 | ++numProperties; |
| 513 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 514 | } |
| 515 | if (flowEntry.flowEntryMatch().matchDstMac()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 516 | flowProp.setMatchDstMac(flowEntry.flowEntryMatch().dstMac().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 517 | if (measureONOSFlowEntryTimeProp) { |
| 518 | ++numProperties; |
| 519 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 520 | } |
| 521 | if (flowEntry.flowEntryMatch().matchEthernetFrameType()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 522 | flowProp.setMatchEthernetFrameType(flowEntry.flowEntryMatch().ethernetFrameType()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 523 | if (measureONOSFlowEntryTimeProp) { |
| 524 | ++numProperties; |
| 525 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 526 | } |
| 527 | if (flowEntry.flowEntryMatch().matchVlanId()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 528 | flowProp.setMatchVlanId(flowEntry.flowEntryMatch().vlanId()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 529 | if (measureONOSFlowEntryTimeProp) { |
| 530 | ++numProperties; |
| 531 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 532 | } |
| 533 | if (flowEntry.flowEntryMatch().matchVlanPriority()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 534 | flowProp.setMatchVlanPriority(flowEntry.flowEntryMatch().vlanPriority()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 535 | if (measureONOSFlowEntryTimeProp) { |
| 536 | ++numProperties; |
| 537 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 538 | } |
| 539 | if (flowEntry.flowEntryMatch().matchSrcIPv4Net()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 540 | flowProp.setMatchSrcIPv4Net(flowEntry.flowEntryMatch().srcIPv4Net().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 541 | if (measureONOSFlowEntryTimeProp) { |
| 542 | ++numProperties; |
| 543 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 544 | } |
| 545 | if (flowEntry.flowEntryMatch().matchDstIPv4Net()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 546 | flowProp.setMatchDstIPv4Net(flowEntry.flowEntryMatch().dstIPv4Net().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 547 | if (measureONOSFlowEntryTimeProp) { |
| 548 | ++numProperties; |
| 549 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 550 | } |
| 551 | if (flowEntry.flowEntryMatch().matchIpProto()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 552 | flowProp.setMatchIpProto(flowEntry.flowEntryMatch().ipProto()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 553 | if (measureONOSFlowEntryTimeProp) { |
| 554 | ++numProperties; |
| 555 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 556 | } |
| 557 | if (flowEntry.flowEntryMatch().matchIpToS()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 558 | flowProp.setMatchIpToS(flowEntry.flowEntryMatch().ipToS()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 559 | if (measureONOSFlowEntryTimeProp) { |
| 560 | ++numProperties; |
| 561 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 562 | } |
| 563 | if (flowEntry.flowEntryMatch().matchSrcTcpUdpPort()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 564 | flowProp.setMatchSrcTcpUdpPort(flowEntry.flowEntryMatch().srcTcpUdpPort()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 565 | if (measureONOSFlowEntryTimeProp) { |
| 566 | ++numProperties; |
| 567 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 568 | } |
| 569 | if (flowEntry.flowEntryMatch().matchDstTcpUdpPort()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 570 | flowProp.setMatchDstTcpUdpPort(flowEntry.flowEntryMatch().dstTcpUdpPort()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 571 | if (measureONOSFlowEntryTimeProp) { |
| 572 | ++numProperties; |
| 573 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | for (FlowEntryAction fa : flowEntry.flowEntryActions().actions()) { |
| 577 | if (fa.actionOutput() != null) { |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 578 | if (measureONOSFlowEntryTimeProp) { |
| 579 | if ( startSearchOutPort != 0 ) log.error("Performance addFlowEntry(_,{},{}) -- Multiple output port action unexpected.", flowEntry.flowId(), flowEntry.flowEntryId()); |
| 580 | startSearchOutPort = System.nanoTime(); |
| 581 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 582 | IPortObject outport = |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 583 | dbHandler.searchPort(flowEntry.dpid().toString(), |
| 584 | fa.actionOutput().port().value()); |
| 585 | if (measureONOSFlowEntryTimeProp) { |
| 586 | endSearchOutPort = System.nanoTime(); |
| 587 | } |
| 588 | |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 589 | flowProp.setActionOutputPort(fa.actionOutput().port().value()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 590 | if (measureONOSFlowEntryTimeProp) { |
| 591 | ++numProperties; |
| 592 | } |
| 593 | |
| 594 | if (measureONOSFlowEntryTimeProp) { |
| 595 | startAddEdgeToOutPort = System.nanoTime(); |
| 596 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 597 | flowEntryObj.setOutPort(outport); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 598 | if (measureONOSFlowEntryTimeProp) { |
| 599 | endAddEdgeToOutPort = System.nanoTime(); |
| 600 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | if (! flowEntry.flowEntryActions().isEmpty()) { |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 604 | flowProp.setActions(flowEntry.flowEntryActions().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 605 | if (measureONOSFlowEntryTimeProp) { |
| 606 | ++numProperties; |
| 607 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | // TODO: Hacks with hard-coded state names! |
| 611 | if (found) |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 612 | flowProp.setUserState("FE_USER_MODIFY"); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 613 | else |
Toshio Koide | 3f23354 | 2014-01-07 14:19:09 -0800 | [diff] [blame] | 614 | flowProp.setUserState("FE_USER_ADD"); |
| 615 | flowProp.setSwitchState(flowEntry.flowEntrySwitchState().toString()); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 616 | if (measureONOSFlowEntryTimeProp) { |
| 617 | numProperties += 2; |
| 618 | } |
Yuta HIGUCHI | 8685f9c | 2014-01-07 15:53:28 -0800 | [diff] [blame] | 619 | flowProp.commitProperties(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 620 | // |
| 621 | // TODO: Take care of the FlowEntryErrorState. |
| 622 | // |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 623 | if (measureONOSFlowEntryTimeProp) { |
| 624 | endSetProperties = System.nanoTime(); |
| 625 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 626 | |
| 627 | // Flow Entries edges: |
| 628 | // Flow |
| 629 | // NextFE (TODO) |
| 630 | if (! found) { |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 631 | if (measureONOSFlowEntryTimeProp) { |
| 632 | startAddEdgeBetweenFlowPath = System.nanoTime(); |
| 633 | } |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 634 | flowObj.addFlowEntry(flowEntryObj); |
| 635 | flowEntryObj.setFlow(flowObj); |
Yuta HIGUCHI | f9ce1c1 | 2014-01-04 23:21:58 -0800 | [diff] [blame] | 636 | if (measureONOSFlowEntryTimeProp) { |
| 637 | endAddEdgeBetweenFlowPath = System.nanoTime(); |
| 638 | } |
| 639 | } |
| 640 | if (measureONOSFlowEntryTimeProp) { |
| 641 | endAddFlowEntry = System.nanoTime(); |
| 642 | |
| 643 | log.error("Performance addFlowEntry(_,{},{}) -- " |
| 644 | + "GrandTotal: {} " |
| 645 | + "SearchExistingFE: {} " |
| 646 | + "CreateNewFE: {} " |
| 647 | + "SetProp+Edge: {} #Props: {} " |
| 648 | + "SearchSwitch: {} " |
| 649 | + "AddEdgeToSwitch: {} " |
| 650 | + "SearchInPort: {} " |
| 651 | + "AddEdgeToInPort: {} " |
| 652 | + "SearchOutPort: {} " |
| 653 | + "AddEdgeToOutPort: {} " |
| 654 | + "AddEdgeBetweenFlowPath: {} " |
| 655 | , flowEntry.flowId(), flowEntry.flowEntryId() |
| 656 | , endAddFlowEntry - startAddFlowEntry |
| 657 | , endSearchFlowEntry - startAddFlowEntry |
| 658 | , endCreateNewFlowEntry - startCreateNewFlowEntry |
| 659 | , endSetProperties - startSetProperties, numProperties |
| 660 | , endSearchSwitch - startSearchSwitch |
| 661 | , endAddEdgeToSwitch - startAddEdgeToSwitch |
| 662 | , endSearchInPort - startSearchInPort |
| 663 | , endAddEdgeToInPort - startAddEdgeToInPort |
| 664 | , endSearchOutPort - startSearchOutPort |
| 665 | , endAddEdgeToOutPort - startAddEdgeToOutPort |
| 666 | , endAddEdgeBetweenFlowPath - startAddEdgeBetweenFlowPath |
| 667 | ); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return flowEntryObj; |
| 671 | } |
| 672 | |
| 673 | /** |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 674 | * Delete a flow entry from the Network MAP. |
| 675 | * |
| 676 | * @param dbHandler the Graph Database handler to use. |
| 677 | * @param flowObj the corresponding Flow Path object for the Flow Entry. |
| 678 | * @param flowEntry the Flow Entry to delete. |
| 679 | * @return true on success, otherwise false. |
| 680 | */ |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 681 | static boolean deleteFlowEntry(DBOperation dbHandler, |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 682 | IFlowPath flowObj, |
| 683 | FlowEntry flowEntry) { |
| 684 | IFlowEntry flowEntryObj = null; |
| 685 | try { |
| 686 | flowEntryObj = dbHandler.searchFlowEntry(flowEntry.flowEntryId()); |
| 687 | } catch (Exception e) { |
| 688 | log.error(":deleteFlowEntry FlowEntryId:{} failed", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 689 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 690 | return false; |
| 691 | } |
| 692 | // |
| 693 | // TODO: Don't print an error for now, because multiple controller |
| 694 | // instances might be deleting the same flow entry. |
| 695 | // |
| 696 | /* |
| 697 | if (flowEntryObj == null) { |
| 698 | log.error(":deleteFlowEntry FlowEntryId:{} failed: FlowEntry object not found", |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 699 | flowEntry.flowEntryId()); |
Pavlin Radoslavov | 7407ab5 | 2013-11-01 22:19:00 -0700 | [diff] [blame] | 700 | return false; |
| 701 | } |
| 702 | */ |
| 703 | if (flowEntryObj == null) |
| 704 | return true; |
| 705 | |
| 706 | flowObj.removeFlowEntry(flowEntryObj); |
| 707 | dbHandler.removeFlowEntry(flowEntryObj); |
| 708 | return true; |
| 709 | } |
| 710 | |
| 711 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 712 | * Delete all previously added flows. |
| 713 | * |
| 714 | * @param dbHandler the Graph Database handler to use. |
| 715 | * @return true on success, otherwise false. |
| 716 | */ |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 717 | static boolean deleteAllFlows(DBOperation dbHandler) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 718 | List<FlowId> allFlowIds = new LinkedList<FlowId>(); |
| 719 | |
| 720 | // Get all Flow IDs |
| 721 | Iterable<IFlowPath> allFlowPaths = dbHandler.getAllFlowPaths(); |
| 722 | for (IFlowPath flowPathObj : allFlowPaths) { |
| 723 | if (flowPathObj == null) |
| 724 | continue; |
| 725 | String flowIdStr = flowPathObj.getFlowId(); |
| 726 | if (flowIdStr == null) |
| 727 | continue; |
| 728 | FlowId flowId = new FlowId(flowIdStr); |
| 729 | allFlowIds.add(flowId); |
| 730 | } |
| 731 | |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 732 | // Delete all flows one-by-one |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 733 | for (FlowId flowId : allFlowIds) { |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 734 | deleteFlow(dbHandler, flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | return true; |
| 738 | } |
| 739 | |
| 740 | /** |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 741 | * Delete a previously added flow. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 742 | * |
| 743 | * @param dbHandler the Graph Database handler to use. |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 744 | * @param flowId the Flow ID of the flow to delete. |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 745 | * @return true on success, otherwise false. |
| 746 | */ |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 747 | static boolean deleteFlow(DBOperation dbHandler, FlowId flowId) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 748 | IFlowPath flowObj = null; |
| 749 | try { |
| 750 | flowObj = dbHandler.searchFlowPath(flowId); |
| 751 | } catch (Exception e) { |
| 752 | // TODO: handle exceptions |
| 753 | dbHandler.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 754 | log.error(":deleteFlow FlowId:{} failed", flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 755 | return false; |
| 756 | } |
| 757 | if (flowObj == null) { |
| 758 | dbHandler.commit(); |
| 759 | return true; // OK: No such flow |
| 760 | } |
| 761 | |
| 762 | // |
| 763 | // Remove all Flow Entries |
| 764 | // |
| 765 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 766 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 767 | flowObj.removeFlowEntry(flowEntryObj); |
| 768 | dbHandler.removeFlowEntry(flowEntryObj); |
| 769 | } |
| 770 | // Remove the Flow itself |
| 771 | dbHandler.removeFlowPath(flowObj); |
| 772 | dbHandler.commit(); |
| 773 | |
| 774 | return true; |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Get a previously added flow. |
| 779 | * |
| 780 | * @param dbHandler the Graph Database handler to use. |
| 781 | * @param flowId the Flow ID of the flow to get. |
| 782 | * @return the Flow Path if found, otherwise null. |
| 783 | */ |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 784 | static FlowPath getFlow(DBOperation dbHandler, FlowId flowId) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 785 | IFlowPath flowObj = null; |
| 786 | try { |
| 787 | flowObj = dbHandler.searchFlowPath(flowId); |
| 788 | } catch (Exception e) { |
| 789 | // TODO: handle exceptions |
| 790 | dbHandler.rollback(); |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 791 | log.error(":getFlow FlowId:{} failed", flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 792 | return null; |
| 793 | } |
| 794 | if (flowObj == null) { |
| 795 | dbHandler.commit(); |
| 796 | return null; // Flow not found |
| 797 | } |
| 798 | |
| 799 | // |
| 800 | // Extract the Flow state |
| 801 | // |
| 802 | FlowPath flowPath = extractFlowPath(flowObj); |
| 803 | dbHandler.commit(); |
| 804 | |
| 805 | return flowPath; |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * Get all installed flows by all installers. |
| 810 | * |
| 811 | * @param dbHandler the Graph Database handler to use. |
| 812 | * @return the Flow Paths if found, otherwise null. |
| 813 | */ |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 814 | static ArrayList<FlowPath> getAllFlows(DBOperation dbHandler) { |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 815 | Iterable<IFlowPath> flowPathsObj = null; |
| 816 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 817 | |
| 818 | try { |
| 819 | flowPathsObj = dbHandler.getAllFlowPaths(); |
| 820 | } catch (Exception e) { |
| 821 | // TODO: handle exceptions |
| 822 | dbHandler.rollback(); |
| 823 | log.error(":getAllFlowPaths failed"); |
| 824 | return flowPaths; |
| 825 | } |
| 826 | if ((flowPathsObj == null) || (flowPathsObj.iterator().hasNext() == false)) { |
| 827 | dbHandler.commit(); |
| 828 | return flowPaths; // No Flows found |
| 829 | } |
| 830 | |
| 831 | for (IFlowPath flowObj : flowPathsObj) { |
| 832 | // |
| 833 | // Extract the Flow state |
| 834 | // |
| 835 | FlowPath flowPath = extractFlowPath(flowObj); |
| 836 | if (flowPath != null) |
| 837 | flowPaths.add(flowPath); |
| 838 | } |
| 839 | |
| 840 | dbHandler.commit(); |
| 841 | |
| 842 | return flowPaths; |
| 843 | } |
| 844 | |
| 845 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 846 | * Extract Flow Path State from a Titan Database Object @ref IFlowPath. |
| 847 | * |
| 848 | * @param flowObj the object to extract the Flow Path State from. |
| 849 | * @return the extracted Flow Path State. |
| 850 | */ |
| 851 | private static FlowPath extractFlowPath(IFlowPath flowObj) { |
| 852 | // |
| 853 | // Extract the Flow state |
| 854 | // |
| 855 | String flowIdStr = flowObj.getFlowId(); |
| 856 | String installerIdStr = flowObj.getInstallerId(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 857 | String flowPathType = flowObj.getFlowPathType(); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 858 | String flowPathUserState = flowObj.getFlowPathUserState(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 859 | Long flowPathFlags = flowObj.getFlowPathFlags(); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 860 | Integer idleTimeout = flowObj.getIdleTimeout(); |
| 861 | Integer hardTimeout = flowObj.getHardTimeout(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 862 | String srcSwitchStr = flowObj.getSrcSwitch(); |
| 863 | Short srcPortShort = flowObj.getSrcPort(); |
| 864 | String dstSwitchStr = flowObj.getDstSwitch(); |
| 865 | Short dstPortShort = flowObj.getDstPort(); |
| 866 | |
| 867 | if ((flowIdStr == null) || |
| 868 | (installerIdStr == null) || |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 869 | (flowPathType == null) || |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 870 | (flowPathUserState == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 871 | (flowPathFlags == null) || |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 872 | (idleTimeout == null) || |
| 873 | (hardTimeout == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 874 | (srcSwitchStr == null) || |
| 875 | (srcPortShort == null) || |
| 876 | (dstSwitchStr == null) || |
| 877 | (dstPortShort == null)) { |
| 878 | // TODO: A work-around, becauuse of some bogus database objects |
| 879 | return null; |
| 880 | } |
| 881 | |
| 882 | FlowPath flowPath = new FlowPath(); |
| 883 | flowPath.setFlowId(new FlowId(flowIdStr)); |
| 884 | flowPath.setInstallerId(new CallerId(installerIdStr)); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 885 | flowPath.setFlowPathType(FlowPathType.valueOf(flowPathType)); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 886 | flowPath.setFlowPathUserState(FlowPathUserState.valueOf(flowPathUserState)); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 887 | flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags)); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 888 | flowPath.setIdleTimeout(idleTimeout); |
| 889 | flowPath.setHardTimeout(hardTimeout); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 890 | flowPath.dataPath().srcPort().setDpid(new Dpid(srcSwitchStr)); |
| 891 | flowPath.dataPath().srcPort().setPort(new Port(srcPortShort)); |
| 892 | flowPath.dataPath().dstPort().setDpid(new Dpid(dstSwitchStr)); |
| 893 | flowPath.dataPath().dstPort().setPort(new Port(dstPortShort)); |
| 894 | // |
| 895 | // Extract the match conditions common for all Flow Entries |
| 896 | // |
| 897 | { |
| 898 | FlowEntryMatch match = new FlowEntryMatch(); |
| 899 | String matchSrcMac = flowObj.getMatchSrcMac(); |
| 900 | if (matchSrcMac != null) |
| 901 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 902 | String matchDstMac = flowObj.getMatchDstMac(); |
| 903 | if (matchDstMac != null) |
| 904 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 905 | Short matchEthernetFrameType = flowObj.getMatchEthernetFrameType(); |
| 906 | if (matchEthernetFrameType != null) |
| 907 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 908 | Short matchVlanId = flowObj.getMatchVlanId(); |
| 909 | if (matchVlanId != null) |
| 910 | match.enableVlanId(matchVlanId); |
| 911 | Byte matchVlanPriority = flowObj.getMatchVlanPriority(); |
| 912 | if (matchVlanPriority != null) |
| 913 | match.enableVlanPriority(matchVlanPriority); |
| 914 | String matchSrcIPv4Net = flowObj.getMatchSrcIPv4Net(); |
| 915 | if (matchSrcIPv4Net != null) |
| 916 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 917 | String matchDstIPv4Net = flowObj.getMatchDstIPv4Net(); |
| 918 | if (matchDstIPv4Net != null) |
| 919 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 920 | Byte matchIpProto = flowObj.getMatchIpProto(); |
| 921 | if (matchIpProto != null) |
| 922 | match.enableIpProto(matchIpProto); |
| 923 | Byte matchIpToS = flowObj.getMatchIpToS(); |
| 924 | if (matchIpToS != null) |
| 925 | match.enableIpToS(matchIpToS); |
| 926 | Short matchSrcTcpUdpPort = flowObj.getMatchSrcTcpUdpPort(); |
| 927 | if (matchSrcTcpUdpPort != null) |
| 928 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 929 | Short matchDstTcpUdpPort = flowObj.getMatchDstTcpUdpPort(); |
| 930 | if (matchDstTcpUdpPort != null) |
| 931 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
| 932 | |
| 933 | flowPath.setFlowEntryMatch(match); |
| 934 | } |
| 935 | // |
| 936 | // Extract the actions for the first Flow Entry |
| 937 | // |
| 938 | { |
| 939 | String actionsStr = flowObj.getActions(); |
| 940 | if (actionsStr != null) { |
| 941 | FlowEntryActions flowEntryActions = new FlowEntryActions(actionsStr); |
| 942 | flowPath.setFlowEntryActions(flowEntryActions); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // |
| 947 | // Extract all Flow Entries |
| 948 | // |
| 949 | Iterable<IFlowEntry> flowEntries = flowObj.getFlowEntries(); |
| 950 | for (IFlowEntry flowEntryObj : flowEntries) { |
| 951 | FlowEntry flowEntry = extractFlowEntry(flowEntryObj); |
| 952 | if (flowEntry == null) |
| 953 | continue; |
| 954 | flowPath.dataPath().flowEntries().add(flowEntry); |
| 955 | } |
| 956 | |
| 957 | return flowPath; |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Extract Flow Entry State from a Titan Database Object @ref IFlowEntry. |
| 962 | * |
| 963 | * @param flowEntryObj the object to extract the Flow Entry State from. |
| 964 | * @return the extracted Flow Entry State. |
| 965 | */ |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 966 | public static FlowEntry extractFlowEntry(IFlowEntry flowEntryObj) { |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 967 | IFlowPath flowObj = flowEntryObj.getFlow(); |
| 968 | if (flowObj == null) |
| 969 | return null; |
| 970 | |
| 971 | String flowIdStr = flowObj.getFlowId(); |
| 972 | // |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 973 | String flowEntryIdStr = flowEntryObj.getFlowEntryId(); |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 974 | Integer idleTimeout = flowEntryObj.getIdleTimeout(); |
| 975 | Integer hardTimeout = flowEntryObj.getHardTimeout(); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 976 | String switchDpidStr = flowEntryObj.getSwitchDpid(); |
| 977 | String userState = flowEntryObj.getUserState(); |
| 978 | String switchState = flowEntryObj.getSwitchState(); |
| 979 | |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 980 | if ((flowIdStr == null) || |
| 981 | (flowEntryIdStr == null) || |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 982 | (idleTimeout == null) || |
| 983 | (hardTimeout == null) || |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 984 | (switchDpidStr == null) || |
| 985 | (userState == null) || |
| 986 | (switchState == null)) { |
Brian O'Connor | a8e4980 | 2013-10-30 20:49:59 -0700 | [diff] [blame] | 987 | // TODO: A work-around, because of some bogus database objects |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 988 | return null; |
| 989 | } |
| 990 | |
| 991 | FlowEntry flowEntry = new FlowEntry(); |
| 992 | flowEntry.setFlowEntryId(new FlowEntryId(flowEntryIdStr)); |
Pavlin Radoslavov | cf87e53 | 2013-12-13 18:17:00 -0800 | [diff] [blame] | 993 | flowEntry.setFlowId(new FlowId(flowIdStr)); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 994 | flowEntry.setDpid(new Dpid(switchDpidStr)); |
yoshi | a97632b | 2013-12-17 15:46:08 -0800 | [diff] [blame] | 995 | flowEntry.setIdleTimeout(idleTimeout); |
| 996 | flowEntry.setHardTimeout(hardTimeout); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 997 | |
| 998 | // |
| 999 | // Extract the match conditions |
| 1000 | // |
| 1001 | FlowEntryMatch match = new FlowEntryMatch(); |
| 1002 | Short matchInPort = flowEntryObj.getMatchInPort(); |
| 1003 | if (matchInPort != null) |
| 1004 | match.enableInPort(new Port(matchInPort)); |
| 1005 | String matchSrcMac = flowEntryObj.getMatchSrcMac(); |
| 1006 | if (matchSrcMac != null) |
| 1007 | match.enableSrcMac(MACAddress.valueOf(matchSrcMac)); |
| 1008 | String matchDstMac = flowEntryObj.getMatchDstMac(); |
| 1009 | if (matchDstMac != null) |
| 1010 | match.enableDstMac(MACAddress.valueOf(matchDstMac)); |
| 1011 | Short matchEthernetFrameType = flowEntryObj.getMatchEthernetFrameType(); |
| 1012 | if (matchEthernetFrameType != null) |
| 1013 | match.enableEthernetFrameType(matchEthernetFrameType); |
| 1014 | Short matchVlanId = flowEntryObj.getMatchVlanId(); |
| 1015 | if (matchVlanId != null) |
| 1016 | match.enableVlanId(matchVlanId); |
| 1017 | Byte matchVlanPriority = flowEntryObj.getMatchVlanPriority(); |
| 1018 | if (matchVlanPriority != null) |
| 1019 | match.enableVlanPriority(matchVlanPriority); |
| 1020 | String matchSrcIPv4Net = flowEntryObj.getMatchSrcIPv4Net(); |
| 1021 | if (matchSrcIPv4Net != null) |
| 1022 | match.enableSrcIPv4Net(new IPv4Net(matchSrcIPv4Net)); |
| 1023 | String matchDstIPv4Net = flowEntryObj.getMatchDstIPv4Net(); |
| 1024 | if (matchDstIPv4Net != null) |
| 1025 | match.enableDstIPv4Net(new IPv4Net(matchDstIPv4Net)); |
| 1026 | Byte matchIpProto = flowEntryObj.getMatchIpProto(); |
| 1027 | if (matchIpProto != null) |
| 1028 | match.enableIpProto(matchIpProto); |
| 1029 | Byte matchIpToS = flowEntryObj.getMatchIpToS(); |
| 1030 | if (matchIpToS != null) |
| 1031 | match.enableIpToS(matchIpToS); |
| 1032 | Short matchSrcTcpUdpPort = flowEntryObj.getMatchSrcTcpUdpPort(); |
| 1033 | if (matchSrcTcpUdpPort != null) |
| 1034 | match.enableSrcTcpUdpPort(matchSrcTcpUdpPort); |
| 1035 | Short matchDstTcpUdpPort = flowEntryObj.getMatchDstTcpUdpPort(); |
| 1036 | if (matchDstTcpUdpPort != null) |
| 1037 | match.enableDstTcpUdpPort(matchDstTcpUdpPort); |
| 1038 | flowEntry.setFlowEntryMatch(match); |
| 1039 | |
| 1040 | // |
| 1041 | // Extract the actions |
| 1042 | // |
| 1043 | FlowEntryActions actions = new FlowEntryActions(); |
| 1044 | String actionsStr = flowEntryObj.getActions(); |
| 1045 | if (actionsStr != null) |
| 1046 | actions = new FlowEntryActions(actionsStr); |
| 1047 | flowEntry.setFlowEntryActions(actions); |
| 1048 | flowEntry.setFlowEntryUserState(FlowEntryUserState.valueOf(userState)); |
| 1049 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.valueOf(switchState)); |
| 1050 | // |
| 1051 | // TODO: Take care of FlowEntryErrorState. |
| 1052 | // |
| 1053 | return flowEntry; |
| 1054 | } |
| 1055 | } |