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