Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 6 | import org.codehaus.jackson.annotate.JsonIgnore; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 7 | import org.easymock.EasyMock; |
| 8 | import org.openflow.util.HexString; |
| 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| 11 | |
| 12 | import com.tinkerpop.blueprints.Vertex; |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 13 | import com.tinkerpop.frames.Property; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 14 | import com.tinkerpop.frames.annotations.gremlin.GremlinParam; |
| 15 | |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 16 | import net.onrc.onos.graph.GraphDBConnection; |
| 17 | import net.onrc.onos.graph.GraphDBOperation; |
| 18 | import net.onrc.onos.graph.IDBConnection; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 19 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject; |
| 20 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 21 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 22 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 23 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 24 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 25 | import net.onrc.onos.ofcontroller.util.FlowId; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Mock class of GraphDBOperation which provides additional setter to construct a graph for test. |
| 29 | * This object simply caches parameters set up by override interfaces and reflect them when commit(). |
| 30 | * *ForTest() methods are exempt from cache, parameters through those methods are reflected soon. |
| 31 | * @author Naoki Shiota |
| 32 | * |
| 33 | */ |
| 34 | public class TestableGraphDBOperation extends GraphDBOperation { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 35 | protected final static Logger log = LoggerFactory.getLogger(TestableGraphDBOperation.class); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 36 | |
| 37 | protected List<TestSwitchObject> switches; |
| 38 | protected List<TestPortObject> ports; |
| 39 | protected List<TestDeviceObject> devices; |
| 40 | protected List<TestFlowPath> paths; |
| 41 | protected List<TestFlowEntry> entries; |
| 42 | |
| 43 | protected List<TestSwitchObject> switchesToAdd; |
| 44 | protected List<TestPortObject> portsToAdd; |
| 45 | protected List<TestDeviceObject> devicesToAdd; |
| 46 | protected List<TestFlowPath> pathsToAdd; |
| 47 | protected List<TestFlowEntry> entriesToAdd; |
| 48 | |
| 49 | protected List<TestSwitchObject> switchesToRemove; |
| 50 | protected List<TestPortObject> portsToRemove; |
| 51 | protected List<TestDeviceObject> devicesToRemove; |
| 52 | protected List<TestFlowPath> pathsToRemove; |
| 53 | protected List<TestFlowEntry> entriesToRemove; |
| 54 | |
| 55 | // Testable implementations of INetMapTopologyObject interfaces |
| 56 | |
| 57 | public static class TestSwitchObject implements ISwitchObject { |
| 58 | private String state,type,dpid; |
| 59 | private List<IPortObject> ports; |
| 60 | private List<IDeviceObject> devices; |
| 61 | private List<IFlowEntry> entries; |
| 62 | |
| 63 | private String stateToUpdate, typeToUpdate, dpidToUpdate; |
| 64 | private List<IPortObject> portsToAdd; |
| 65 | private List<IPortObject> portsToRemove; |
| 66 | |
| 67 | public TestSwitchObject() { |
| 68 | type = "switch"; |
| 69 | |
| 70 | ports = new ArrayList<IPortObject>(); |
| 71 | portsToAdd = new ArrayList<IPortObject>(); |
| 72 | portsToRemove = new ArrayList<IPortObject>(); |
| 73 | devices = new ArrayList<IDeviceObject>(); |
| 74 | entries = new ArrayList<IFlowEntry>(); |
| 75 | |
| 76 | clearUncommitedData(); |
| 77 | } |
| 78 | |
| 79 | public void commit() { |
| 80 | for(IPortObject port : portsToAdd) { |
| 81 | ports.add(port); |
| 82 | } |
| 83 | for(IPortObject port : portsToRemove) { |
| 84 | ports.remove(port); |
| 85 | } |
| 86 | if(stateToUpdate != null) { state = stateToUpdate; } |
| 87 | if(typeToUpdate != null) { type = typeToUpdate; } |
| 88 | if(dpidToUpdate != null) { dpid = dpidToUpdate; } |
| 89 | |
| 90 | clearUncommitedData(); |
| 91 | } |
| 92 | |
| 93 | public void rollback() { |
| 94 | clearUncommitedData(); |
| 95 | } |
| 96 | |
| 97 | public void clearUncommitedData() { |
| 98 | portsToAdd.clear(); |
| 99 | portsToRemove.clear(); |
| 100 | stateToUpdate = typeToUpdate = dpidToUpdate = null; |
| 101 | } |
| 102 | |
| 103 | public void setStateForTest(String state) { this.state = state; } |
| 104 | public void setTypeForTest(String type) { this.type = type; } |
| 105 | public void setDpidForTest(String dpid) { this.dpid = dpid; } |
| 106 | public void addPortForTest(TestPortObject port) { ports.add(port); } |
| 107 | public void addDeviceForTest(TestDeviceObject dev) { devices.add(dev); } |
| 108 | public void addEntryForTest(TestFlowEntry entry) { entries.add(entry); } |
| 109 | |
| 110 | @Override |
| 111 | public String getState() { return state; } |
| 112 | |
| 113 | @Override |
| 114 | public void setState(String state) { this.stateToUpdate = state; } |
| 115 | |
| 116 | @Override |
| 117 | public String getType() { return type ; } |
| 118 | |
| 119 | @Override |
| 120 | public void setType(String type) { this.typeToUpdate = type; } |
| 121 | |
| 122 | // Not support for test |
| 123 | @Override |
| 124 | public Vertex asVertex() { return null; } |
| 125 | |
| 126 | @Override |
| 127 | public String getDPID() { return dpid; } |
| 128 | |
| 129 | @Override |
| 130 | public void setDPID(String dpid) { this.dpidToUpdate = dpid; } |
| 131 | |
| 132 | @Override |
| 133 | public Iterable<IPortObject> getPorts() { return ports; } |
| 134 | |
| 135 | @Override |
| 136 | public IPortObject getPort(@GremlinParam("port_num") short port_num) { |
| 137 | for(IPortObject port : ports) { |
| 138 | if(port.getNumber() == port_num) { |
| 139 | return port; |
| 140 | } |
| 141 | } |
| 142 | return null; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void addPort(IPortObject port) { portsToAdd.add(port); } |
| 147 | |
| 148 | @Override |
| 149 | public void removePort(IPortObject port) { portsToRemove.add(port); } |
| 150 | |
| 151 | @Override |
| 152 | public Iterable<IDeviceObject> getDevices() { return devices; } |
| 153 | |
| 154 | @Override |
| 155 | public Iterable<IFlowEntry> getFlowEntries() { return entries; } |
| 156 | } |
| 157 | |
| 158 | public static class TestPortObject implements IPortObject { |
| 159 | private String state,type,desc; |
| 160 | private Short number; |
| 161 | private Integer port_state; |
| 162 | private ISwitchObject sw; |
| 163 | |
| 164 | private List<IPortObject> linkedPorts; |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 165 | private List<IPortObject> reverseLinkedPorts; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 166 | private List<IDeviceObject> devices; |
| 167 | private List<IFlowEntry> inflows,outflows; |
| 168 | |
| 169 | private String stateToUpdate,typeToUpdate,descToUpdate; |
| 170 | private Short numberToUpdate; |
| 171 | private Integer port_stateToUpdate; |
| 172 | |
| 173 | private List<IPortObject> linkedPortsToAdd; |
| 174 | private List<IPortObject> linkedPortsToRemove; |
| 175 | private List<IDeviceObject> devicesToAdd; |
| 176 | private List<IDeviceObject> devicesToRemove; |
| 177 | |
| 178 | |
| 179 | public TestPortObject() { |
| 180 | type = "port"; |
| 181 | |
| 182 | linkedPorts = new ArrayList<IPortObject>(); |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 183 | reverseLinkedPorts = new ArrayList<IPortObject>(); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 184 | linkedPortsToAdd = new ArrayList<IPortObject>(); |
| 185 | linkedPortsToRemove = new ArrayList<IPortObject>(); |
| 186 | devices = new ArrayList<IDeviceObject>(); |
| 187 | devicesToAdd = new ArrayList<IDeviceObject>(); |
| 188 | devicesToRemove = new ArrayList<IDeviceObject>(); |
| 189 | inflows = new ArrayList<IFlowEntry>(); |
| 190 | outflows = new ArrayList<IFlowEntry>(); |
| 191 | |
| 192 | clearUncommitedData(); |
| 193 | } |
| 194 | |
| 195 | public void commit() { |
| 196 | for(IPortObject port : linkedPortsToAdd) { linkedPorts.add(port); } |
| 197 | for(IPortObject port : linkedPortsToRemove) { linkedPorts.remove(port); } |
| 198 | for(IDeviceObject dev : devicesToAdd) { devices.add(dev); } |
| 199 | for(IDeviceObject dev : devicesToRemove) { devices.remove(dev); } |
| 200 | |
| 201 | if(stateToUpdate != null) { state = stateToUpdate; } |
| 202 | if(typeToUpdate != null) { type = typeToUpdate; } |
| 203 | if(descToUpdate != null) { desc = descToUpdate; } |
| 204 | if(numberToUpdate != null) { number = numberToUpdate; } |
| 205 | if(port_stateToUpdate != null) { port_state = port_stateToUpdate; } |
| 206 | |
| 207 | clearUncommitedData(); |
| 208 | } |
| 209 | |
| 210 | public void rollback() { |
| 211 | clearUncommitedData(); |
| 212 | } |
| 213 | |
| 214 | public void clearUncommitedData() { |
| 215 | linkedPortsToAdd.clear(); |
| 216 | linkedPortsToRemove.clear(); |
| 217 | devicesToAdd.clear(); |
| 218 | devicesToRemove.clear(); |
| 219 | stateToUpdate = typeToUpdate = descToUpdate = null; |
| 220 | port_stateToUpdate = null; |
| 221 | numberToUpdate = null; |
| 222 | } |
| 223 | |
| 224 | // Setter methods for test |
| 225 | public void setStateForTest(String state) { this.state = state; } |
| 226 | public void setTypeForTest(String type) { this.type = type; } |
| 227 | public void setDescForTest(String desc) { this.desc = desc; } |
| 228 | public void setNumberForTest(Short number) { this.number = number; } |
| 229 | public void setPortStateForTest(Integer state) { this.port_state = state; } |
| 230 | public void setSwitchForTest(ISwitchObject sw) { this.sw = sw; } |
| 231 | public void addLinkedPortForTest(TestPortObject port) { this.linkedPorts.add(port); } |
| 232 | public void addInflowForTest(TestFlowEntry entry) { inflows.add(entry); } |
| 233 | public void addOutflowForTest(TestFlowEntry entry) { outflows.add(entry); } |
| 234 | |
| 235 | // Override methods for mock IPortObject |
| 236 | @Override |
| 237 | public String getState() { return state; } |
| 238 | |
| 239 | @Override |
| 240 | public void setState(String state) { this.stateToUpdate = state; } |
| 241 | |
| 242 | @Override |
| 243 | public String getType() { return type; } |
| 244 | |
| 245 | @Override |
| 246 | public void setType(String type) { this.typeToUpdate = type; } |
| 247 | |
| 248 | // not support for test |
| 249 | @Override |
| 250 | public Vertex asVertex() { |
| 251 | return null; |
| 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public Short getNumber() { return number; } |
| 256 | |
| 257 | @Override |
| 258 | public void setNumber(Short n) { this.numberToUpdate = n; } |
| 259 | |
| 260 | @Override |
| 261 | public String getDesc() { return desc; } |
| 262 | |
| 263 | @Override |
| 264 | public void setDesc(String s) { this.descToUpdate = s; } |
| 265 | |
| 266 | @Override |
| 267 | public Integer getPortState() { return port_state; } |
| 268 | |
| 269 | @Override |
| 270 | public void setPortState(Integer s) { this.port_stateToUpdate = s; } |
| 271 | |
| 272 | @Override |
| 273 | public ISwitchObject getSwitch() { return sw; } |
| 274 | |
| 275 | @Override |
| 276 | public Iterable<IDeviceObject> getDevices() { return devices; } |
| 277 | |
| 278 | @Override |
| 279 | public void setDevice(IDeviceObject device) { devicesToAdd.add(device); } |
| 280 | |
| 281 | @Override |
| 282 | public void removeDevice(IDeviceObject device) { devicesToRemove.add(device); } |
| 283 | |
| 284 | @Override |
| 285 | public Iterable<IFlowEntry> getInFlowEntries() { return inflows; } |
| 286 | |
| 287 | @Override |
| 288 | public Iterable<IFlowEntry> getOutFlowEntries() { return outflows; } |
| 289 | |
| 290 | @Override |
| 291 | public Iterable<IPortObject> getLinkedPorts() { return linkedPorts; } |
| 292 | |
| 293 | @Override |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 294 | public Iterable<IPortObject> getReverseLinkedPorts() { return reverseLinkedPorts; } |
| 295 | |
| 296 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 297 | public void removeLink(IPortObject dest_port) { linkedPortsToRemove.add(dest_port); } |
| 298 | |
| 299 | @Override |
| 300 | public void setLinkPort(IPortObject dest_port) { linkedPortsToAdd.add(dest_port); } |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 301 | |
| 302 | @Override |
| 303 | @JsonIgnore |
| 304 | @Property("port_id") |
| 305 | public void setPortId(String id) { |
| 306 | // TODO Auto-generated method stub |
| 307 | |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | @JsonIgnore |
| 312 | @Property("port_id") |
| 313 | public String getPortId() { |
| 314 | // TODO Auto-generated method stub |
| 315 | return null; |
| 316 | } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | public static class TestDeviceObject implements IDeviceObject { |
| 320 | private String state,type,mac,ipaddr; |
| 321 | private List<IPortObject> ports; |
| 322 | private List<ISwitchObject> switches; |
| 323 | |
| 324 | private String stateToUpdate,typeToUpdate,macToUpdate,ipaddrToUpdate; |
| 325 | private List<IPortObject> portsToAdd; |
| 326 | private List<IPortObject> portsToRemove; |
| 327 | |
| 328 | public TestDeviceObject() { |
| 329 | type = "device"; |
| 330 | |
| 331 | ports = new ArrayList<IPortObject>(); |
| 332 | portsToAdd = new ArrayList<IPortObject>(); |
| 333 | portsToRemove = new ArrayList<IPortObject>(); |
| 334 | switches = new ArrayList<ISwitchObject>(); |
| 335 | |
| 336 | clearUncommitedData(); |
| 337 | } |
| 338 | |
| 339 | public void commit() { |
| 340 | for(IPortObject port : portsToAdd) { |
| 341 | ports.add(port); |
| 342 | } |
| 343 | for(IPortObject port : portsToRemove) { |
| 344 | ports.remove(port); |
| 345 | } |
| 346 | |
| 347 | if(stateToUpdate != null) { state = stateToUpdate; } |
| 348 | if(typeToUpdate != null) { type = typeToUpdate; } |
| 349 | if(macToUpdate != null) { mac = macToUpdate; } |
| 350 | if(ipaddrToUpdate != null) { ipaddr = ipaddrToUpdate; } |
| 351 | |
| 352 | clearUncommitedData(); |
| 353 | } |
| 354 | |
| 355 | public void rollback() { |
| 356 | clearUncommitedData(); |
| 357 | } |
| 358 | |
| 359 | public void clearUncommitedData() { |
| 360 | ports.clear(); |
| 361 | portsToAdd.clear(); |
| 362 | portsToRemove.clear(); |
| 363 | |
| 364 | stateToUpdate = typeToUpdate = macToUpdate = ipaddrToUpdate = null; |
| 365 | } |
| 366 | |
| 367 | // Setter methods for test |
| 368 | public void setStateForTest(String state) { this.state = state; } |
| 369 | public void setTypeForTest(String type) { this.type = type; } |
| 370 | public void setMacForTest(String mac) { this.mac = mac; } |
| 371 | public void setIpaddrForTest(String ipaddr) { this.ipaddr = ipaddr; } |
| 372 | public void addSwitchForTest(ISwitchObject sw) { switches.add(sw); } |
| 373 | public void addPortForTest(IPortObject port) { ports.add(port); } |
| 374 | |
| 375 | |
| 376 | // Override methods |
| 377 | @Override |
| 378 | public String getState() { return state; } |
| 379 | |
| 380 | @Override |
| 381 | public void setState(String state) { stateToUpdate = state; } |
| 382 | |
| 383 | @Override |
| 384 | public String getType() { return type; } |
| 385 | |
| 386 | @Override |
| 387 | public void setType(String type) { typeToUpdate = type; } |
| 388 | |
| 389 | @Override |
| 390 | public Vertex asVertex() { |
| 391 | // TODO Auto-generated method stub |
| 392 | return null; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public String getMACAddress() { return mac; } |
| 397 | |
| 398 | @Override |
| 399 | public void setMACAddress(String macaddr) { macToUpdate = macaddr; } |
| 400 | |
| 401 | @Override |
| 402 | public String getIPAddress() { return ipaddr; } |
| 403 | |
| 404 | @Override |
| 405 | public void setIPAddress(String ipaddr) { ipaddrToUpdate = ipaddr; } |
| 406 | |
| 407 | @Override |
| 408 | public Iterable<IPortObject> getAttachedPorts() { |
| 409 | return ports; } |
| 410 | |
| 411 | @Override |
| 412 | public void setHostPort(IPortObject port) { portsToAdd.add(port); } |
| 413 | |
| 414 | @Override |
| 415 | public void removeHostPort(IPortObject port) { portsToRemove.add(port); } |
| 416 | |
| 417 | @Override |
| 418 | public Iterable<ISwitchObject> getSwitch() { return switches; } |
| 419 | } |
| 420 | |
| 421 | public static class TestFlowPath implements IFlowPath { |
| 422 | private String state,type,flowId,installerId,srcSw,dstSw; |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 423 | private String flowPathType; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 424 | private String flowPathUserState; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 425 | private Long flowPathFlags; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 426 | private String dataPathSummary; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 427 | private Short srcPort,dstPort; |
| 428 | private String matchSrcMac,matchDstMac; |
| 429 | private Short matchEthernetFrameType; |
| 430 | private Short matchVlanId; |
| 431 | private Byte matchVlanPriority; |
| 432 | private String matchSrcIpaddr,matchDstIpaddr; |
| 433 | private Byte matchIpProto, matchIpToS; |
| 434 | private Short matchSrcTcpUdpPort, matchDstTcpUdpPort; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 435 | private String actions; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 436 | |
| 437 | private List<IFlowEntry> entries; |
| 438 | private List<ISwitchObject> switches; |
| 439 | |
| 440 | private String stateToUpdate,typeToUpdate,flowIdToUpdate,installerIdToUpdate,srcSwToUpdate,dstSwToUpdate; |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 441 | private String flowPathTypeToUpdate; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 442 | private String flowPathUserStateToUpdate; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 443 | private Long flowPathFlagsToUpdate; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 444 | private String dataPathSummaryToUpdate; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 445 | private Short srcPortToUpdate,dstPortToUpdate; |
| 446 | private String matchSrcMacToUpdate,matchDstMacToUpdate; |
| 447 | private Short matchEthernetFrameTypeToUpdate; |
| 448 | private Short matchVlanIdToUpdate; |
| 449 | private Byte matchVlanPriorityToUpdate; |
| 450 | private String matchSrcIpaddrToUpdate,matchDstIpaddrToUpdate; |
| 451 | private Byte matchIpProtoToUpdate, matchIpToSToUpdate; |
| 452 | private Short matchSrcTcpUdpPortToUpdate, matchDstTcpUdpPortToUpdate; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 453 | private String actionsToUpdate; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 454 | |
| 455 | private List<IFlowEntry> flowsToAdd; |
| 456 | private List<IFlowEntry> flowsToRemove; |
| 457 | |
| 458 | public TestFlowPath() { |
| 459 | type = "flow"; |
| 460 | |
| 461 | entries = new ArrayList<IFlowEntry>(); |
| 462 | flowsToAdd = new ArrayList<IFlowEntry>(); |
| 463 | flowsToRemove = new ArrayList<IFlowEntry>(); |
| 464 | |
| 465 | switches = new ArrayList<ISwitchObject>(); |
| 466 | |
| 467 | clear(); |
| 468 | } |
| 469 | |
| 470 | public void commit() { |
| 471 | for(IFlowEntry flow : flowsToAdd) { |
| 472 | entries.add(flow); |
| 473 | } |
| 474 | for(IFlowEntry flow : flowsToRemove) { |
| 475 | entries.remove(flow); |
| 476 | } |
| 477 | if(stateToUpdate != null) { state = stateToUpdate; } |
| 478 | if(typeToUpdate != null) { type = typeToUpdate; } |
| 479 | if(flowIdToUpdate != null) { flowId = flowIdToUpdate; } |
| 480 | if(installerIdToUpdate != null) { installerId = installerIdToUpdate; } |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 481 | if(flowPathTypeToUpdate != null) { flowPathType = flowPathTypeToUpdate; } |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 482 | if(flowPathUserStateToUpdate != null) { flowPathUserState = flowPathUserStateToUpdate; } |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 483 | if(flowPathFlagsToUpdate != null) { flowPathFlags = flowPathFlagsToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 484 | if(srcSwToUpdate != null) { srcSw = srcSwToUpdate; } |
| 485 | if(dstSwToUpdate != null) { dstSw = dstSwToUpdate; } |
| 486 | if(dataPathSummaryToUpdate != null) { dataPathSummary = dataPathSummaryToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 487 | if(srcPortToUpdate != null) { srcPort = srcPortToUpdate; } |
| 488 | if(dstPortToUpdate != null) { dstPort = dstPortToUpdate; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 489 | if(matchSrcMacToUpdate != null) { matchSrcMac = matchSrcMacToUpdate; } |
| 490 | if(matchDstMacToUpdate != null) { matchDstMac = matchDstMacToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 491 | if(matchEthernetFrameTypeToUpdate != null) { matchEthernetFrameType = matchEthernetFrameTypeToUpdate; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 492 | if(matchVlanIdToUpdate != null) { matchVlanId = matchVlanIdToUpdate; } |
| 493 | if(matchVlanPriorityToUpdate != null) { matchVlanPriority = matchVlanPriorityToUpdate; } |
| 494 | if(matchSrcIpaddrToUpdate != null) { matchSrcIpaddr = matchSrcIpaddrToUpdate; } |
| 495 | if(matchDstIpaddrToUpdate != null) { matchDstIpaddr = matchDstIpaddrToUpdate; } |
| 496 | if(matchIpProtoToUpdate != null) { matchIpProto = matchIpProtoToUpdate; } |
| 497 | if(matchIpToSToUpdate != null) { matchIpToS = matchIpToSToUpdate; } |
| 498 | if(matchSrcTcpUdpPortToUpdate != null) { matchSrcTcpUdpPort = matchSrcTcpUdpPortToUpdate; } |
| 499 | if(matchDstTcpUdpPortToUpdate != null) { matchDstTcpUdpPort = matchDstTcpUdpPortToUpdate; } |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 500 | if(actionsToUpdate != null) { actions = actionsToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | public void rollback() { |
| 504 | clear(); |
| 505 | } |
| 506 | |
| 507 | public void clear() { |
| 508 | flowsToAdd.clear(); |
| 509 | flowsToRemove.clear(); |
| 510 | |
| 511 | stateToUpdate = typeToUpdate = flowIdToUpdate = installerIdToUpdate = null; |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 512 | flowPathTypeToUpdate = null; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 513 | flowPathUserStateToUpdate = null; |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 514 | flowPathFlagsToUpdate = null; |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 515 | srcSwToUpdate = dstSwToUpdate = dataPathSummaryToUpdate = null; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 516 | srcPortToUpdate = dstPortToUpdate = null; |
| 517 | matchSrcMacToUpdate = matchDstMacToUpdate = null; |
| 518 | matchEthernetFrameTypeToUpdate = null; |
| 519 | matchVlanIdToUpdate = null; |
| 520 | matchVlanPriorityToUpdate = null; |
| 521 | matchSrcIpaddrToUpdate = matchDstIpaddrToUpdate = null; |
| 522 | matchIpProtoToUpdate = matchIpToSToUpdate = null; |
| 523 | matchSrcTcpUdpPortToUpdate = matchDstTcpUdpPortToUpdate = null; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 524 | actionsToUpdate = null; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | // Setter methods for test |
| 528 | public void setStateForTest(String state) { this.state = state; } |
| 529 | public void setTypeForTest(String type) { this.type = type; } |
| 530 | public void setFlowIdForTest(String flowId) { this.flowId = flowId; } |
| 531 | public void setInstallerIdForTest(String installerId) { this.installerId = installerId; } |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 532 | public void setFlowPathTypeForTest(String flowPathType) { this.flowPathType = flowPathType; } |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 533 | public void setFlowPathUserStateForTest(String flowPathUserState) { this.flowPathUserState = flowPathUserState; } |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 534 | public void setFlowPathFlagsForTest(Long flowPathFlags) { this.flowPathFlags = flowPathFlags; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 535 | public void setSrcSwForTest(String srcSw) { this.srcSw = srcSw; } |
| 536 | public void setDstSwForTest(String dstSw) { this.dstSw = dstSw; } |
| 537 | public void setDataPathSummaryForTest(String dataPathSummary) { this.dataPathSummary = dataPathSummary; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 538 | public void setSrcPortForTest(Short srcPort) { this.srcPort = srcPort; } |
| 539 | public void setDstPortForTest(Short dstPort) { this.dstPort = dstPort; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 540 | public void setMatchSrcMacForTest(String matchSrcMac) { this.matchSrcMac = matchSrcMac; } |
| 541 | public void setMatchDstMacForTest(String matchDstMac) { this.matchDstMac = matchDstMac; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 542 | public void setMatchEthernetFrameTypeForTest(Short matchEthernetFrameType) { this.matchEthernetFrameType = matchEthernetFrameType; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 543 | public void setMatchVlanIdForTest(Short matchVlanId) { this.matchVlanId = matchVlanId; } |
| 544 | public void setMatchVlanPriorityForTest(Byte matchVlanPriority) { this.matchVlanPriority = matchVlanPriority; } |
| 545 | public void setMatchSrcIpaddrForTest(String matchSrcIpaddr) { this.matchSrcIpaddr = matchSrcIpaddr; } |
| 546 | public void setMatchDstIpaddrForTest(String matchDstIpaddr) { this.matchDstIpaddr = matchDstIpaddr; } |
| 547 | public void setMatchIpProtoForTest(Byte matchIpProto) { this.matchIpProto = matchIpProto; } |
| 548 | public void setMatchIpToSForTest(Byte matchIpToS) { this.matchIpToS = matchIpToS; } |
| 549 | public void setMatchSrcTcpUdpPortForTest(Short matchSrcTcpUdpPort) { this.matchSrcTcpUdpPort = matchSrcTcpUdpPort; } |
| 550 | public void setMatchDstTcpUdpPortForTest(Short matchDstTcpUdpPort) { this.matchDstTcpUdpPort = matchDstTcpUdpPort; } |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 551 | public void setActionsForTest(String actions) { this.actions = actions; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 552 | public void addFlowEntryForTest(IFlowEntry entry) { entries.add(entry); } |
| 553 | public void addSwitchForTest(ISwitchObject sw) { switches.add(sw); } |
| 554 | |
| 555 | @Override |
| 556 | public String getState() { return state; } |
| 557 | |
| 558 | @Override |
| 559 | public void setState(String state) { stateToUpdate = state; } |
| 560 | |
| 561 | @Override |
| 562 | public String getType() { return type; } |
| 563 | |
| 564 | @Override |
| 565 | public void setType(String type) { typeToUpdate = type; } |
| 566 | |
| 567 | @Override |
| 568 | public Vertex asVertex() { |
| 569 | // TODO Auto-generated method stub |
| 570 | return null; |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public String getFlowId() { return flowId; } |
| 575 | |
| 576 | @Override |
| 577 | public void setFlowId(String flowId) { flowIdToUpdate = flowId; } |
| 578 | |
| 579 | @Override |
| 580 | public String getInstallerId() { return installerId; } |
| 581 | |
| 582 | @Override |
| 583 | public void setInstallerId(String installerId) { installerIdToUpdate = installerId; } |
| 584 | |
| 585 | @Override |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 586 | public String getFlowPathType() { return flowPathType; } |
| 587 | |
| 588 | @Override |
| 589 | public void setFlowPathType(String flowPathType) { flowPathTypeToUpdate = flowPathType; } |
| 590 | |
| 591 | @Override |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 592 | public String getFlowPathUserState() { return flowPathUserState; } |
| 593 | |
| 594 | @Override |
| 595 | public void setFlowPathUserState(String flowPathUserState) { flowPathUserStateToUpdate = flowPathUserState; } |
| 596 | |
| 597 | @Override |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 598 | public Long getFlowPathFlags() { return flowPathFlags; } |
| 599 | |
| 600 | @Override |
| 601 | public void setFlowPathFlags(Long flowPathFlags) { flowPathFlagsToUpdate = flowPathFlags; } |
| 602 | |
| 603 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 604 | public String getSrcSwitch() { return srcSw; } |
| 605 | |
| 606 | @Override |
| 607 | public void setSrcSwitch(String srcSwitch) { srcSwToUpdate = srcSwitch; } |
| 608 | |
| 609 | @Override |
| 610 | public Short getSrcPort() { return srcPort; } |
| 611 | |
| 612 | @Override |
| 613 | public void setSrcPort(Short srcPort) { srcPortToUpdate = srcPort; } |
| 614 | |
| 615 | @Override |
| 616 | public String getDstSwitch() { return dstSw; } |
| 617 | |
| 618 | @Override |
| 619 | public void setDstSwitch(String dstSwitch) { dstSwToUpdate = dstSwitch; } |
| 620 | |
| 621 | @Override |
| 622 | public Short getDstPort() { return dstPort; } |
| 623 | |
| 624 | @Override |
| 625 | public void setDstPort(Short dstPort) { dstPortToUpdate = dstPort; } |
| 626 | |
| 627 | @Override |
| 628 | public String getDataPathSummary() { return dataPathSummary; } |
| 629 | |
| 630 | @Override |
| 631 | public void setDataPathSummary(String dataPathSummary) { dataPathSummaryToUpdate = dataPathSummary; } |
| 632 | |
| 633 | @Override |
| 634 | public Iterable<IFlowEntry> getFlowEntries() { return entries; } |
| 635 | |
| 636 | @Override |
| 637 | public void addFlowEntry(IFlowEntry flowEntry) { |
| 638 | if(! entries.contains(flowEntry)) { |
| 639 | flowsToAdd.add(flowEntry); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | @Override |
| 644 | public void removeFlowEntry(IFlowEntry flowEntry) { |
| 645 | if(entries.contains(flowEntry)) { |
| 646 | flowsToAdd.add(flowEntry); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 651 | public String getMatchSrcMac() { return matchSrcMac; } |
| 652 | |
| 653 | @Override |
| 654 | public void setMatchSrcMac(String matchSrcMac) { matchSrcMacToUpdate = matchSrcMac; } |
| 655 | |
| 656 | @Override |
| 657 | public String getMatchDstMac() { return matchDstMac; } |
| 658 | |
| 659 | @Override |
| 660 | public void setMatchDstMac(String matchDstMac) { matchDstMacToUpdate = matchDstMac; } |
| 661 | |
| 662 | @Override |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 663 | public Short getMatchEthernetFrameType() { return matchEthernetFrameType; } |
| 664 | |
| 665 | @Override |
| 666 | public void setMatchEthernetFrameType(Short matchEthernetFrameType) { |
| 667 | matchEthernetFrameTypeToUpdate = matchEthernetFrameType; } |
| 668 | |
| 669 | @Override |
| 670 | public Short getMatchVlanId() { return matchVlanId; } |
| 671 | |
| 672 | @Override |
| 673 | public void setMatchVlanId(Short matchVlanId) { |
| 674 | matchVlanIdToUpdate = matchVlanId; } |
| 675 | |
| 676 | @Override |
| 677 | public Byte getMatchVlanPriority() { return matchVlanPriority; } |
| 678 | |
| 679 | @Override |
| 680 | public void setMatchVlanPriority(Byte matchVlanPriority) { |
| 681 | matchVlanPriorityToUpdate = matchVlanPriority; } |
| 682 | |
| 683 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 684 | public String getMatchSrcIPv4Net() { return matchSrcIpaddr; } |
| 685 | |
| 686 | @Override |
| 687 | public void setMatchSrcIPv4Net(String matchSrcIPv4Net) { |
| 688 | matchSrcIpaddrToUpdate = matchSrcIPv4Net; } |
| 689 | |
| 690 | @Override |
| 691 | public String getMatchDstIPv4Net() { return matchDstIpaddr; } |
| 692 | |
| 693 | @Override |
| 694 | public void setMatchDstIPv4Net(String matchDstIPv4Net) { |
| 695 | matchDstIpaddrToUpdate = matchDstIPv4Net; } |
| 696 | |
| 697 | @Override |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 698 | public Byte getMatchIpProto() { return matchIpProto; } |
| 699 | |
| 700 | @Override |
| 701 | public void setMatchIpProto(Byte matchIpProto) { |
| 702 | matchIpProtoToUpdate = matchIpProto; } |
| 703 | |
| 704 | @Override |
| 705 | public Byte getMatchIpToS() { return matchIpToS; } |
| 706 | |
| 707 | @Override |
| 708 | public void setMatchIpToS(Byte matchIpToS) { |
| 709 | matchIpToSToUpdate = matchIpToS; } |
| 710 | |
| 711 | @Override |
| 712 | public Short getMatchSrcTcpUdpPort() { return matchSrcTcpUdpPort; } |
| 713 | |
| 714 | @Override |
| 715 | public void setMatchSrcTcpUdpPort(Short matchSrcTcpUdpPort) { |
| 716 | matchSrcTcpUdpPortToUpdate = matchSrcTcpUdpPort; } |
| 717 | |
| 718 | @Override |
| 719 | public Short getMatchDstTcpUdpPort() { return matchDstTcpUdpPort; } |
| 720 | |
| 721 | @Override |
| 722 | public void setMatchDstTcpUdpPort(Short matchDstTcpUdpPort) { |
| 723 | matchDstTcpUdpPortToUpdate = matchDstTcpUdpPort; } |
| 724 | |
| 725 | @Override |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 726 | public String getActions() { return actions; } |
| 727 | |
| 728 | @Override |
| 729 | public void setActions(String actions) { |
| 730 | actionsToUpdate = actions; } |
| 731 | |
| 732 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 733 | public Iterable<ISwitchObject> getSwitches() { return switches; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | public static class TestFlowEntry implements IFlowEntry { |
| 737 | private String state,type,entryId,dpid,userState,switchState,errorStateType,errorStateCode; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 738 | private Short matchInPort; |
| 739 | private String matchSrcMac,matchDstMac; |
| 740 | private Short matchEtherFrameType; |
| 741 | private Short matchVlanId; |
| 742 | private Byte matchVlanPriority; |
| 743 | private String matchSrcIpaddr,matchDstIpaddr; |
| 744 | private Byte matchIpProto, matchIpToS; |
| 745 | private Short matchSrcTcpUdpPort, matchDstTcpUdpPort; |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 746 | private Short actionOutputPort; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 747 | private String actions; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 748 | |
| 749 | private IFlowPath flowPath; |
| 750 | private ISwitchObject sw; |
| 751 | private IPortObject inport,outport; |
| 752 | |
| 753 | private String stateToUpdate,typeToUpdate,entryIdToUpdate,dpidToUpdate, |
| 754 | userStateToUpdate,switchStateToUpdate,errorStateTypeToUpdate,errorStateCodeToUpdate; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 755 | private Short matchInPortToUpdate; |
| 756 | private String matchSrcMacToUpdate,matchDstMacToUpdate; |
| 757 | private Short matchEtherFrameTypeToUpdate; |
| 758 | private Short matchVlanIdToUpdate; |
| 759 | private Byte matchVlanPriorityToUpdate; |
| 760 | private String matchSrcIpaddrToUpdate,matchDstIpaddrToUpdate; |
| 761 | private Byte matchIpProtoToUpdate, matchIpToSToUpdate; |
| 762 | private Short matchSrcTcpUdpPortToUpdate, matchDstTcpUdpPortToUpdate; |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 763 | private Short actionOutputPortToUpdate; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 764 | private String actionsToUpdate; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 765 | |
| 766 | private IFlowPath flowPathToUpdate; |
| 767 | private ISwitchObject swToUpdate; |
| 768 | private IPortObject inportToUpdate,outportToUpdate; |
| 769 | |
| 770 | public TestFlowEntry() { |
| 771 | type = "flow_entry"; |
| 772 | |
| 773 | clearUncommitedData(); |
| 774 | } |
| 775 | |
| 776 | public void commit() { |
| 777 | if(stateToUpdate != null) { state = stateToUpdate; } |
| 778 | if(typeToUpdate != null) { type = typeToUpdate; } |
| 779 | if(entryIdToUpdate != null) { entryId = entryIdToUpdate; } |
| 780 | if(dpidToUpdate != null) { dpid = dpidToUpdate; } |
| 781 | if(userStateToUpdate != null) { userState = userStateToUpdate; } |
| 782 | if(switchStateToUpdate != null) { switchState = switchStateToUpdate; } |
| 783 | if(errorStateTypeToUpdate != null) { errorStateType = errorStateTypeToUpdate; } |
| 784 | if(errorStateCodeToUpdate != null) { errorStateCode = errorStateCodeToUpdate; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 785 | if(matchInPortToUpdate != null) { matchInPort = matchInPortToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 786 | if(matchSrcMacToUpdate != null) { matchSrcMac = matchSrcMacToUpdate; } |
| 787 | if(matchDstMacToUpdate != null) { matchDstMac = matchDstMacToUpdate; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 788 | if(matchEtherFrameTypeToUpdate != null) { matchEtherFrameType = matchEtherFrameTypeToUpdate; } |
| 789 | if(matchVlanIdToUpdate != null) { matchVlanId = matchVlanIdToUpdate; } |
| 790 | if(matchVlanPriorityToUpdate != null) { matchVlanPriority = matchVlanPriorityToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 791 | if(matchSrcIpaddrToUpdate != null) { matchSrcIpaddr = matchSrcIpaddrToUpdate; } |
| 792 | if(matchDstIpaddrToUpdate != null) { matchDstIpaddr = matchDstIpaddrToUpdate; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 793 | if(matchIpProtoToUpdate != null) { matchIpProto = matchIpProtoToUpdate; } |
| 794 | if(matchIpToSToUpdate != null) { matchIpToS = matchIpToSToUpdate; } |
| 795 | if(matchSrcTcpUdpPortToUpdate != null) { matchSrcTcpUdpPort = matchSrcTcpUdpPortToUpdate; } |
| 796 | if(matchDstTcpUdpPortToUpdate != null) { matchDstTcpUdpPort = matchDstTcpUdpPortToUpdate; } |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 797 | if(actionOutputPortToUpdate != null) { actionOutputPort = actionOutputPortToUpdate; } |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 798 | if(actionsToUpdate != null) { actions = actionsToUpdate; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 799 | |
| 800 | if(flowPathToUpdate != null) { flowPath = flowPathToUpdate; } |
| 801 | if(swToUpdate != null) { sw = swToUpdate; } |
| 802 | if(inportToUpdate != null) { inport = inportToUpdate; } |
| 803 | if(outportToUpdate != null) { outport = outportToUpdate; } |
| 804 | |
| 805 | clearUncommitedData(); |
| 806 | } |
| 807 | |
| 808 | public void rollback() { |
| 809 | clearUncommitedData(); |
| 810 | } |
| 811 | |
| 812 | public void clearUncommitedData() { |
| 813 | stateToUpdate = typeToUpdate = entryIdToUpdate = dpidToUpdate = null; |
| 814 | userStateToUpdate = switchStateToUpdate = errorStateTypeToUpdate = errorStateCodeToUpdate = null; |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 815 | matchInPortToUpdate = null; |
| 816 | matchSrcMacToUpdate = matchDstMacToUpdate = null; |
| 817 | matchEtherFrameTypeToUpdate = null; |
| 818 | matchVlanIdToUpdate = null; |
| 819 | matchVlanPriorityToUpdate = null; |
| 820 | matchSrcIpaddrToUpdate = matchDstIpaddrToUpdate = null; |
| 821 | matchIpProtoToUpdate = matchIpToSToUpdate = null; |
| 822 | matchSrcTcpUdpPortToUpdate = matchDstTcpUdpPortToUpdate = null; |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 823 | actionOutputPortToUpdate = null; |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 824 | actionsToUpdate = null; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 825 | flowPathToUpdate = null; |
| 826 | swToUpdate = null; |
| 827 | inportToUpdate = outportToUpdate = null; |
| 828 | } |
| 829 | |
| 830 | // Setter methods for test |
| 831 | public void setStateForTest(String state) { this.state = state; } |
| 832 | public void setTypeForTest(String type) { this.type = type; } |
| 833 | public void setEntryIdForTest(String entryId) { this.entryId = entryId; } |
| 834 | public void setDpidForTest(String dpid) { this.dpid = dpid; } |
| 835 | public void setUserStateForTest(String userState) { this.userState = userState; } |
| 836 | public void setSwitchStateForTest(String switchState) { this.switchState = switchState; } |
| 837 | public void setErrorStateTypeForTest(String errorStateType) { this.errorStateType = errorStateType; } |
| 838 | public void setErrorStateCodeForTest(String errorStateCode) { this.errorStateCode = errorStateCode; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 839 | public void setMatchInPortForTest(Short matchInPort) { this.matchInPort = matchInPort; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 840 | public void setMatchSrcMacForTest(String matchSrcMac) { this.matchSrcMac = matchSrcMac; } |
| 841 | public void setMatchDstMacForTest(String matchDstMac) { this.matchDstMac = matchDstMac; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 842 | public void setMatchEtherFrameTypeForTest(Short matchEtherFrameType) { this.matchEtherFrameType = matchEtherFrameType; } |
| 843 | public void setMatchVlanIdForTest(Short matchVlanId) { this.matchVlanId = matchVlanId; } |
| 844 | public void setMatchVlanPriorityForTest(Byte matchVlanPriority) { this.matchVlanPriority = matchVlanPriority; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 845 | public void setMatchSrcIpaddrForTest(String matchSrcIpaddr) { this.matchSrcIpaddr = matchSrcIpaddr; } |
| 846 | public void setMatchDstIpaddrForTest(String matchDstIpaddr) { this.matchDstIpaddr = matchDstIpaddr; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 847 | public void setMatchIpProtoForTest(Byte matchIpProto) { this.matchIpProto = matchIpProto; } |
| 848 | public void setMatchIpToSForTest(Byte matchIpToS) { this.matchIpToS = matchIpToS; } |
| 849 | public void setMatchSrcTcpUdpPortForTest(Short matchSrcTcpUdpPort) { this.matchSrcTcpUdpPort = matchSrcTcpUdpPort; } |
| 850 | public void setMatchDstTcpUdpPortForTest(Short matchDstTcpUdpPort) { this.matchDstTcpUdpPort = matchDstTcpUdpPort; } |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 851 | public void setActionOutputPortForTest(Short actionOutputPort) { this.actionOutputPort = actionOutputPort; } |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 852 | public void setActionsForTest(String actions) { this.actions = actions; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 853 | public void setFlowPathForTest(IFlowPath flowPath) { this.flowPath = flowPath; } |
| 854 | public void setSwitchForTest(ISwitchObject sw) { this.sw = sw; } |
| 855 | public void setInportForTest(IPortObject inport) { this.inport = inport; } |
| 856 | public void setOutportForTest(IPortObject outport) { this.outport = outport; } |
| 857 | |
| 858 | @Override |
| 859 | public String getState() { return state; } |
| 860 | |
| 861 | @Override |
| 862 | public void setState(String state) { stateToUpdate = state; } |
| 863 | |
| 864 | @Override |
| 865 | public String getType() { return type; } |
| 866 | |
| 867 | @Override |
| 868 | public void setType(String type) { typeToUpdate = type; } |
| 869 | |
| 870 | @Override |
| 871 | public Vertex asVertex() { |
| 872 | // TODO Auto-generated method stub |
| 873 | return null; |
| 874 | } |
| 875 | |
| 876 | @Override |
| 877 | public String getFlowEntryId() { return entryId; } |
| 878 | |
| 879 | @Override |
| 880 | public void setFlowEntryId(String flowEntryId) { entryIdToUpdate = flowEntryId; } |
| 881 | |
| 882 | @Override |
| 883 | public String getSwitchDpid() { return dpid; } |
| 884 | |
| 885 | @Override |
| 886 | public void setSwitchDpid(String switchDpid) { dpidToUpdate = switchDpid; } |
| 887 | |
| 888 | @Override |
| 889 | public String getUserState() { return userState; } |
| 890 | |
| 891 | @Override |
| 892 | public void setUserState(String userState) { userStateToUpdate = userState; } |
| 893 | |
| 894 | @Override |
| 895 | public String getSwitchState() { return switchState; } |
| 896 | |
| 897 | @Override |
| 898 | public void setSwitchState(String switchState) { switchStateToUpdate = switchState; } |
| 899 | |
| 900 | @Override |
| 901 | public String getErrorStateType() { return errorStateType; } |
| 902 | |
| 903 | @Override |
| 904 | public void setErrorStateType(String errorStateType) { errorStateTypeToUpdate = errorStateType; } |
| 905 | |
| 906 | @Override |
| 907 | public String getErrorStateCode() { return errorStateCode; } |
| 908 | |
| 909 | @Override |
| 910 | public void setErrorStateCode(String errorStateCode) { errorStateCodeToUpdate = errorStateCode; } |
| 911 | |
| 912 | @Override |
| 913 | public Short getMatchInPort() { return matchInPort; } |
| 914 | |
| 915 | @Override |
| 916 | public void setMatchInPort(Short matchInPort) { matchInPortToUpdate = matchInPort; } |
| 917 | |
| 918 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 919 | public String getMatchSrcMac() { return matchSrcMac; } |
| 920 | |
| 921 | @Override |
| 922 | public void setMatchSrcMac(String matchSrcMac) { matchSrcMacToUpdate = matchSrcMac; } |
| 923 | |
| 924 | @Override |
| 925 | public String getMatchDstMac() { return matchDstMac; } |
| 926 | |
| 927 | @Override |
| 928 | public void setMatchDstMac(String matchDstMac) { matchDstMacToUpdate = matchDstMac; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 929 | |
| 930 | @Override |
| 931 | public Short getMatchEthernetFrameType() {return matchEtherFrameType; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 932 | |
| 933 | @Override |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 934 | public void setMatchEthernetFrameType(Short matchEthernetFrameType) { matchEtherFrameTypeToUpdate = matchEthernetFrameType; } |
| 935 | |
| 936 | @Override |
| 937 | public Short getMatchVlanId() {return matchVlanId; } |
| 938 | |
| 939 | @Override |
Yuta HIGUCHI | 5208f1a | 2013-10-14 10:04:16 -0700 | [diff] [blame] | 940 | public void setMatchVlanId(Short matchVlanId) { matchVlanIdToUpdate = matchVlanId; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 941 | |
| 942 | @Override |
| 943 | public Byte getMatchVlanPriority() {return matchVlanPriority; } |
| 944 | |
| 945 | @Override |
Yuta HIGUCHI | 5208f1a | 2013-10-14 10:04:16 -0700 | [diff] [blame] | 946 | public void setMatchVlanPriority(Byte matchVlanPriority) { matchVlanPriorityToUpdate = matchVlanPriority; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 947 | |
| 948 | @Override |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 949 | public String getMatchSrcIPv4Net() { return matchSrcIpaddr; } |
| 950 | |
| 951 | @Override |
| 952 | public void setMatchSrcIPv4Net(String matchSrcIPv4Net) { matchSrcIpaddrToUpdate = matchSrcIPv4Net; } |
| 953 | |
| 954 | @Override |
| 955 | public String getMatchDstIPv4Net() { return matchDstIpaddr; } |
| 956 | |
| 957 | @Override |
| 958 | public void setMatchDstIPv4Net(String matchDstIPv4Net) { matchDstIpaddrToUpdate = matchDstIPv4Net; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 959 | |
| 960 | @Override |
| 961 | public Byte getMatchIpProto() {return matchIpProto; } |
| 962 | |
| 963 | @Override |
Yuta HIGUCHI | 5208f1a | 2013-10-14 10:04:16 -0700 | [diff] [blame] | 964 | public void setMatchIpProto(Byte matchIpProto) { matchIpProtoToUpdate = matchIpProto; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 965 | |
| 966 | @Override |
| 967 | public Byte getMatchIpToS() {return matchIpToS; } |
| 968 | |
| 969 | @Override |
Yuta HIGUCHI | 5208f1a | 2013-10-14 10:04:16 -0700 | [diff] [blame] | 970 | public void setMatchIpToS(Byte matchIpToS) { matchIpToSToUpdate = matchIpToS; } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 971 | |
| 972 | @Override |
| 973 | public Short getMatchSrcTcpUdpPort() {return matchSrcTcpUdpPort; } |
| 974 | |
| 975 | @Override |
| 976 | public void setMatchSrcTcpUdpPort(Short matchSrcTcpUdpPort) { matchSrcTcpUdpPortToUpdate = matchSrcTcpUdpPort; } |
| 977 | |
| 978 | @Override |
| 979 | public Short getMatchDstTcpUdpPort() {return matchDstTcpUdpPort; } |
| 980 | |
| 981 | @Override |
| 982 | public void setMatchDstTcpUdpPort(Short matchDstTcpUdpPort) { matchDstTcpUdpPortToUpdate = matchDstTcpUdpPort; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 983 | |
| 984 | @Override |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 985 | public Short getActionOutputPort() { return actionOutputPort; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 986 | |
| 987 | @Override |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 988 | public void setActionOutputPort(Short actionOutputPort) { actionOutputPortToUpdate = actionOutputPort; } |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 989 | |
| 990 | @Override |
| 991 | public String getActions() { return actions; } |
| 992 | |
| 993 | @Override |
| 994 | public void setActions(String actions) { actionsToUpdate = actions; } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 995 | |
| 996 | @Override |
| 997 | public IFlowPath getFlow() { return flowPath; } |
| 998 | |
| 999 | @Override |
| 1000 | public void setFlow(IFlowPath flow) { flowPathToUpdate = flow; } |
| 1001 | |
| 1002 | @Override |
| 1003 | public ISwitchObject getSwitch() { return sw; } |
| 1004 | |
| 1005 | @Override |
| 1006 | public void setSwitch(ISwitchObject sw) { swToUpdate = sw; } |
| 1007 | |
| 1008 | @Override |
| 1009 | public IPortObject getInPort() { return inport; } |
| 1010 | |
| 1011 | @Override |
| 1012 | public void setInPort(IPortObject port) { inportToUpdate = port; } |
| 1013 | |
| 1014 | @Override |
| 1015 | public IPortObject getOutPort() { return outport; } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void setOutPort(IPortObject port) { outportToUpdate = port; } |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | public TestableGraphDBOperation() { |
| 1023 | super(EasyMock.createNiceMock(GraphDBConnection.class)); |
| 1024 | |
| 1025 | switches = new ArrayList<TestSwitchObject>(); |
| 1026 | ports = new ArrayList<TestPortObject>(); |
| 1027 | devices = new ArrayList<TestDeviceObject>(); |
| 1028 | paths = new ArrayList<TestFlowPath>(); |
| 1029 | entries = new ArrayList<TestFlowEntry>(); |
| 1030 | |
| 1031 | switchesToAdd = new ArrayList<TestSwitchObject>(); |
| 1032 | portsToAdd = new ArrayList<TestPortObject>(); |
| 1033 | devicesToAdd = new ArrayList<TestDeviceObject>(); |
| 1034 | pathsToAdd = new ArrayList<TestFlowPath>(); |
| 1035 | entriesToAdd = new ArrayList<TestFlowEntry>(); |
| 1036 | |
| 1037 | switchesToRemove = new ArrayList<TestSwitchObject>(); |
| 1038 | portsToRemove = new ArrayList<TestPortObject>(); |
| 1039 | devicesToRemove = new ArrayList<TestDeviceObject>(); |
| 1040 | pathsToRemove = new ArrayList<TestFlowPath>(); |
| 1041 | entriesToRemove = new ArrayList<TestFlowEntry>(); |
| 1042 | |
| 1043 | clearUncommitedData(); |
| 1044 | } |
| 1045 | |
| 1046 | private void clearUncommitedData() { |
| 1047 | for(TestFlowEntry flow : entries) { |
| 1048 | flow.clearUncommitedData(); |
| 1049 | } |
| 1050 | for(TestFlowEntry flow : entriesToAdd) { |
| 1051 | flow.clearUncommitedData(); |
| 1052 | } |
| 1053 | |
| 1054 | for(TestDeviceObject dev : devices) { |
| 1055 | dev.clearUncommitedData(); |
| 1056 | } |
| 1057 | for(TestDeviceObject dev : devicesToAdd) { |
| 1058 | dev.clearUncommitedData(); |
| 1059 | } |
| 1060 | |
| 1061 | for(TestSwitchObject sw : switches) { |
| 1062 | sw.clearUncommitedData(); |
| 1063 | } |
| 1064 | for(TestSwitchObject sw : switchesToAdd) { |
| 1065 | sw.clearUncommitedData(); |
| 1066 | } |
| 1067 | |
| 1068 | for(TestPortObject port : ports) { |
| 1069 | port.clearUncommitedData(); |
| 1070 | } |
| 1071 | for(TestPortObject port : portsToAdd) { |
| 1072 | port.clearUncommitedData(); |
| 1073 | } |
| 1074 | |
| 1075 | entriesToAdd.clear(); |
| 1076 | entriesToRemove.clear(); |
| 1077 | devicesToAdd.clear(); |
| 1078 | devicesToRemove.clear(); |
| 1079 | switchesToAdd.clear(); |
| 1080 | switchesToRemove.clear(); |
| 1081 | portsToAdd.clear(); |
| 1082 | portsToRemove.clear(); |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | // this.*ForTest() methods below are supposed to be used for creation of test topology. |
| 1087 | /** |
| 1088 | * Create new empty TestSwitchObject. |
| 1089 | * @return New TestSwitchObject |
| 1090 | */ |
| 1091 | public TestSwitchObject createNewSwitchForTest() { |
| 1092 | TestSwitchObject sw = new TestSwitchObject(); |
| 1093 | switches.add(sw); |
| 1094 | return sw; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * Create new TestSwitchObject with specific DPID. |
| 1099 | * @param dpid DPID to be set |
| 1100 | * @return New TestSwitchObject |
| 1101 | */ |
| 1102 | public TestSwitchObject createNewSwitchForTest(String dpid) { |
| 1103 | for(TestSwitchObject sw_loop : switches) { |
| 1104 | if(sw_loop.getDPID().equals(dpid)) { |
| 1105 | // Already created |
| 1106 | log.error("switch already exists : " + dpid); |
| 1107 | return sw_loop; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | TestSwitchObject sw = new TestSwitchObject(); |
| 1112 | |
| 1113 | sw.setDpidForTest(dpid); |
| 1114 | switches.add(sw); |
| 1115 | |
| 1116 | return sw; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * Create new empty TestPortObject. |
| 1121 | * @return New TestPortObject |
| 1122 | */ |
| 1123 | public TestPortObject createNewPortForTest() { |
| 1124 | TestPortObject port = new TestPortObject(); |
| 1125 | ports.add(port); |
| 1126 | return port; |
| 1127 | } |
| 1128 | |
| 1129 | /** |
| 1130 | * Create new TestPortObject with specific DPID and port number. |
| 1131 | * @param dpid DPID to be set |
| 1132 | * @param number Port number to be set |
| 1133 | * @return New TestPortObject |
| 1134 | */ |
| 1135 | public TestPortObject createNewPortForTest(String dpid, Short number) { |
| 1136 | TestSwitchObject sw = null; |
| 1137 | |
| 1138 | for(TestSwitchObject sw_loop : switches) { |
| 1139 | if(sw_loop.getDPID().equals(dpid)) { |
| 1140 | sw = sw_loop; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | if(sw != null) { |
| 1145 | TestPortObject port = new TestPortObject(); |
| 1146 | port.setNumberForTest(number); |
| 1147 | port.setSwitchForTest(sw); |
| 1148 | sw.addPortForTest(port); |
| 1149 | |
| 1150 | ports.add(port); |
| 1151 | |
| 1152 | return port; |
| 1153 | } else { |
| 1154 | return null; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * Link a TestPortObject to other TestPortObject. |
| 1160 | * @param src TestPortObjecgt of source port. |
| 1161 | * @param dst TestPortObjecgt of destination port. |
| 1162 | */ |
| 1163 | public void setLinkBetweenPortsForTest(TestPortObject src, TestPortObject dst) { |
| 1164 | src.addLinkedPortForTest(dst); |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Create new empty TestDeviceObject. |
| 1169 | * @return New TestDeviceObject |
| 1170 | */ |
| 1171 | public TestDeviceObject createNewDeviceForTest() { |
| 1172 | TestDeviceObject dev = new TestDeviceObject(); |
| 1173 | |
| 1174 | return dev; |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * Create new empty TestFlowPathObject. |
| 1179 | * @return New TestFlowPathObject |
| 1180 | */ |
| 1181 | public TestFlowPath createNewFlowPathForTest() { |
| 1182 | TestFlowPath path = new TestFlowPath(); |
| 1183 | paths.add(path); |
| 1184 | return path; |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Create new empty TestFlowEntryObject. |
| 1189 | * @return New TestFlowEntryObject |
| 1190 | */ |
| 1191 | public TestFlowEntry createNewFlowEntryForTest() { |
| 1192 | TestFlowEntry entry = new TestFlowEntry(); |
| 1193 | entries.add(entry); |
| 1194 | return entry; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | public boolean hasLinkBetween(String srcSw_str, Short srcNumber, String dstSw_str, Short dstNumber) { |
| 1199 | IPortObject srcPort = null, dstPort = null; |
| 1200 | long srcSw = HexString.toLong(srcSw_str); |
| 1201 | long dstSw = HexString.toLong(dstSw_str); |
| 1202 | |
| 1203 | for(TestSwitchObject sw : switches) { |
| 1204 | long swLong = HexString.toLong(sw.getDPID()); |
| 1205 | if(swLong == srcSw) { |
| 1206 | for(IPortObject port : sw.getPorts()) { |
| 1207 | if(port.getNumber().equals(srcNumber)) { |
| 1208 | srcPort = port; |
| 1209 | } |
| 1210 | } |
| 1211 | } else if(swLong == dstSw) { |
| 1212 | for(IPortObject port : sw.getPorts()) { |
| 1213 | if(port.getNumber().equals(dstNumber)) { |
| 1214 | dstPort = port; |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | if(srcPort != null && dstPort != null) { |
| 1221 | for(IPortObject port : srcPort.getLinkedPorts()) { |
| 1222 | if(port.equals(dstPort)) { |
| 1223 | return true; |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
| 1231 | // Overriding methods below are to mock GraphDBOperation class. |
| 1232 | @Override |
| 1233 | public ISwitchObject newSwitch(String dpid) { |
| 1234 | TestSwitchObject sw = new TestSwitchObject(); |
| 1235 | sw.setDPID(dpid); |
| 1236 | switchesToAdd.add(sw); |
| 1237 | |
| 1238 | return sw; |
| 1239 | } |
| 1240 | |
| 1241 | @Override |
| 1242 | public ISwitchObject searchSwitch(String dpid_str) { |
| 1243 | Long dpid = HexString.toLong(dpid_str); |
| 1244 | |
| 1245 | for(ISwitchObject sw : switches) { |
| 1246 | if(HexString.toLong(sw.getDPID()) == dpid) { |
| 1247 | return sw; |
| 1248 | } |
| 1249 | } |
| 1250 | return null; |
| 1251 | } |
| 1252 | |
| 1253 | @Override |
| 1254 | public ISwitchObject searchActiveSwitch(String dpid_str) { |
| 1255 | Long dpid = HexString.toLong(dpid_str); |
| 1256 | |
| 1257 | for(ISwitchObject sw : switches) { |
| 1258 | if(HexString.toLong(sw.getDPID()) == dpid && sw.getState().equals("ACTIVE")) { |
| 1259 | return sw; |
| 1260 | } |
| 1261 | } |
| 1262 | return null; |
| 1263 | } |
| 1264 | |
| 1265 | @Override |
| 1266 | public Iterable<ISwitchObject> getActiveSwitches() { |
| 1267 | List<ISwitchObject> list = new ArrayList<ISwitchObject>(); |
| 1268 | |
| 1269 | for(ISwitchObject sw : switches) { |
| 1270 | if(sw.getState() != null && sw.getState().equals("ACTIVE")) { |
| 1271 | list.add(sw); |
| 1272 | } |
| 1273 | } |
| 1274 | return list.isEmpty() ? null : list; |
| 1275 | } |
| 1276 | |
| 1277 | @Override |
| 1278 | public Iterable<ISwitchObject> getAllSwitches() { |
| 1279 | List<ISwitchObject> list = new ArrayList<ISwitchObject>(); |
| 1280 | |
| 1281 | for(ISwitchObject sw : switches) { |
| 1282 | list.add(sw); |
| 1283 | } |
| 1284 | |
| 1285 | return list.isEmpty() ? null : list; |
| 1286 | } |
| 1287 | |
| 1288 | @Override |
| 1289 | public Iterable<ISwitchObject> getInactiveSwitches() { |
| 1290 | List<ISwitchObject> list = new ArrayList<ISwitchObject>(); |
| 1291 | |
| 1292 | for(ISwitchObject sw : switches) { |
| 1293 | if(! sw.getState().equals("ACTIVE")) { |
| 1294 | list.add(sw); |
| 1295 | } |
| 1296 | } |
| 1297 | return list.isEmpty() ? null : list; |
| 1298 | } |
| 1299 | |
| 1300 | @Override |
| 1301 | public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() { |
| 1302 | List<IFlowEntry> list = new ArrayList<IFlowEntry>(); |
| 1303 | |
| 1304 | for(TestFlowEntry entry : entries) { |
| 1305 | if(entry.getSwitchState().equals("FE_SWITCH_NOT_UPDATED")) { |
| 1306 | list.add(entry); |
| 1307 | } |
| 1308 | } |
| 1309 | return list; |
| 1310 | } |
| 1311 | |
| 1312 | @Override |
| 1313 | public void removeSwitch(ISwitchObject sw) { |
| 1314 | if(switches.contains(sw)) { |
| 1315 | switchesToRemove.add((TestSwitchObject)sw); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | @Override |
| 1320 | public IPortObject newPort(Short portNumber) { |
| 1321 | TestPortObject port = new TestPortObject(); |
| 1322 | port.setNumber(portNumber); |
| 1323 | |
| 1324 | return port; |
| 1325 | } |
| 1326 | |
| 1327 | public IPortObject newPort(Long dpid, Short portNumber) { |
| 1328 | TestPortObject port = null; |
| 1329 | TestSwitchObject sw = (TestSwitchObject)searchSwitch(HexString.toHexString(dpid)); |
| 1330 | |
| 1331 | if(sw != null) { |
| 1332 | port = (TestPortObject)newPort(portNumber); |
| 1333 | portsToAdd.add(port); |
| 1334 | sw.addPort(port); |
| 1335 | } |
| 1336 | |
| 1337 | return port; |
| 1338 | } |
| 1339 | |
| 1340 | @Override |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 1341 | public IPortObject searchPort(String dpid_str, Short number) { |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 1342 | long dpid = HexString.toLong(dpid_str); |
| 1343 | |
| 1344 | for(TestSwitchObject sw : switches) { |
| 1345 | if(HexString.toLong(sw.getDPID()) == dpid) { |
| 1346 | for(IPortObject port : sw.getPorts()) { |
| 1347 | if(port.getNumber().equals(number)) { |
| 1348 | return port; |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | return null; |
| 1354 | } |
| 1355 | |
| 1356 | @Override |
| 1357 | public void removePort(IPortObject port) { |
| 1358 | for(TestSwitchObject sw : switches) { |
| 1359 | for(IPortObject pt : sw.getPorts()) { |
| 1360 | if(pt.equals(port)) { |
| 1361 | sw.removePort(port); |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | portsToRemove.add((TestPortObject)port); |
| 1366 | } |
| 1367 | |
| 1368 | @Override |
| 1369 | public IDeviceObject newDevice() { |
| 1370 | TestDeviceObject dev = new TestDeviceObject(); |
| 1371 | devicesToAdd.add(dev); |
| 1372 | |
| 1373 | return dev; |
| 1374 | } |
| 1375 | |
| 1376 | @Override |
| 1377 | public IDeviceObject searchDevice(String macAddr) { |
| 1378 | for(IDeviceObject dev : devices) { |
| 1379 | if(dev.getMACAddress().equals(macAddr)) { |
| 1380 | return dev; |
| 1381 | } |
| 1382 | } |
| 1383 | return null; |
| 1384 | } |
| 1385 | |
| 1386 | @Override |
| 1387 | public Iterable<IDeviceObject> getDevices() { |
| 1388 | List<IDeviceObject> list = new ArrayList<IDeviceObject>(); |
| 1389 | |
| 1390 | for(TestDeviceObject dev : devices) { |
| 1391 | list.add(dev); |
| 1392 | } |
| 1393 | |
| 1394 | return list; |
| 1395 | } |
| 1396 | |
| 1397 | @Override |
| 1398 | public void removeDevice(IDeviceObject dev) { |
| 1399 | if(devices.contains((TestDeviceObject)dev)) { |
| 1400 | devicesToRemove.add((TestDeviceObject)dev); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | @Override |
| 1405 | public IFlowPath newFlowPath() { |
| 1406 | TestFlowPath path = new TestFlowPath(); |
| 1407 | pathsToAdd.add(path); |
| 1408 | |
| 1409 | return path; |
| 1410 | } |
| 1411 | |
| 1412 | @Override |
| 1413 | public IFlowPath searchFlowPath(FlowId flowId) { |
| 1414 | for(IFlowPath path : paths) { |
| 1415 | if(path.getFlowId().equals(flowId)) { |
| 1416 | return path; |
| 1417 | } |
| 1418 | } |
| 1419 | return null; |
| 1420 | } |
| 1421 | |
| 1422 | @Override |
| 1423 | public IFlowPath getFlowPathByFlowEntry(IFlowEntry flowEntry) { |
| 1424 | for(IFlowPath path : paths) { |
| 1425 | for(IFlowEntry entry : path.getFlowEntries()) { |
| 1426 | if(entry.equals(flowEntry)) { |
| 1427 | return path; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | } |
| 1432 | return null; |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | public Iterable<IFlowPath> getAllFlowPaths() { |
| 1437 | List<IFlowPath> list = new ArrayList<IFlowPath>(); |
| 1438 | |
| 1439 | for(IFlowPath path : paths) { |
| 1440 | list.add(path); |
| 1441 | } |
| 1442 | |
| 1443 | return list; |
| 1444 | } |
| 1445 | |
| 1446 | @Override |
| 1447 | public void removeFlowPath(IFlowPath flowPath) { |
| 1448 | if(paths.contains((TestFlowPath)flowPath)) { |
| 1449 | pathsToRemove.add((TestFlowPath)flowPath); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | @Override |
| 1454 | public IFlowEntry newFlowEntry() { |
| 1455 | TestFlowEntry entry = new TestFlowEntry(); |
| 1456 | entriesToAdd.add(entry); |
| 1457 | return entry; |
| 1458 | } |
| 1459 | |
| 1460 | @Override |
| 1461 | public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) { |
| 1462 | for(TestFlowEntry entry : entries) { |
| 1463 | // TODO check if this matching works |
| 1464 | if(entry.getFlowEntryId().equals(flowEntryId)) { |
| 1465 | return entry; |
| 1466 | } |
| 1467 | } |
| 1468 | return null; |
| 1469 | } |
| 1470 | |
| 1471 | @Override |
| 1472 | public Iterable<IFlowEntry> getAllFlowEntries() { |
| 1473 | List<IFlowEntry> list = new ArrayList<IFlowEntry>(); |
| 1474 | |
| 1475 | for(TestFlowEntry entry : entries) { |
| 1476 | list.add(entry); |
| 1477 | } |
| 1478 | |
| 1479 | return list; |
| 1480 | } |
| 1481 | |
| 1482 | @Override |
| 1483 | public void removeFlowEntry(IFlowEntry flowEntry) { |
| 1484 | if(entries.contains((TestFlowEntry)flowEntry)) { |
| 1485 | entriesToRemove.add((TestFlowEntry)flowEntry); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | @Override |
| 1490 | public IDBConnection getDBConnection() { |
| 1491 | return super.getDBConnection(); |
| 1492 | } |
| 1493 | |
| 1494 | @Override |
| 1495 | public void commit() { |
| 1496 | for(TestSwitchObject sw : switchesToAdd) { |
| 1497 | switches.add(sw); |
| 1498 | } |
| 1499 | for(TestSwitchObject sw : switchesToRemove) { |
| 1500 | sw.commit(); |
| 1501 | switches.remove(sw); |
| 1502 | } |
| 1503 | for(TestSwitchObject sw : switches) { |
| 1504 | sw.commit(); |
| 1505 | } |
| 1506 | |
| 1507 | for(TestPortObject port : portsToAdd) { |
| 1508 | ports.add(port); |
| 1509 | } |
| 1510 | for(TestPortObject port : portsToRemove) { |
| 1511 | port.commit(); |
| 1512 | ports.remove(port); |
| 1513 | } |
| 1514 | for(TestPortObject port : ports) { |
| 1515 | port.commit(); |
| 1516 | } |
| 1517 | |
| 1518 | for(TestDeviceObject dev : devicesToAdd) { |
| 1519 | devices.add(dev); |
| 1520 | } |
| 1521 | for(TestDeviceObject dev : devicesToRemove) { |
| 1522 | dev.commit(); |
| 1523 | devices.remove(dev); |
| 1524 | } |
| 1525 | for(TestDeviceObject dev : devices) { |
| 1526 | dev.commit(); |
| 1527 | } |
| 1528 | |
| 1529 | clearUncommitedData(); |
| 1530 | } |
| 1531 | |
| 1532 | @Override |
| 1533 | public void rollback() { |
| 1534 | clearUncommitedData(); |
| 1535 | } |
| 1536 | |
| 1537 | @Override |
| 1538 | public void close() { |
| 1539 | // TODO Auto-generated method stub |
| 1540 | |
| 1541 | } |
| 1542 | } |