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