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