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