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