yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package net.onrc.onos.graph; |
| 6 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 7 | import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph; |
| 8 | import com.tinkerpop.frames.FramedGraph; |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject; |
| 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 12 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 13 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 14 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 15 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 16 | import net.onrc.onos.ofcontroller.util.FlowId; |
| 17 | import org.apache.commons.configuration.Configuration; |
| 18 | |
| 19 | /** |
| 20 | * |
| 21 | * @author nickkaranatsios |
| 22 | */ |
| 23 | public class RamCloudDBOperation extends DBOperation { |
| 24 | |
| 25 | public RamCloudDBOperation() { |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 29 | public Iterable<ISwitchObject> getAllSwitches() { |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 30 | return getAllSwitches(conn.getFramedGraph()); |
| 31 | } |
| 32 | |
| 33 | @Override |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 34 | public void removePort(INetMapTopologyObjects.IPortObject port) { |
| 35 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 36 | if (fg != null) { |
| 37 | fg.removeVertex(port.asVertex()); |
| 38 | } |
| 39 | } |
| 40 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 41 | @Override |
| 42 | public IDeviceObject searchDevice(String macAddr) { |
| 43 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 44 | return searchDevice(macAddr, fg); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public Iterable<IDeviceObject> getDevices() { |
| 49 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 50 | return fg != null ? fg.getVertices("type", "device", IDeviceObject.class) : null; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void removeDevice(IDeviceObject dev) { |
| 55 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 56 | if (fg != null) { |
| 57 | fg.removeVertex(dev.asVertex()); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 63 | public IFlowPath searchFlowPath(FlowId flowId) { |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 64 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 65 | return searchFlowPath(flowId, fg); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public Iterable<IFlowPath> getAllFlowPaths() { |
| 70 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 71 | return getAllFlowPaths(fg); |
| 72 | } |
| 73 | |
| 74 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 75 | public void removeFlowPath(IFlowPath flowPath) { |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 76 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 77 | fg.removeVertex(flowPath.asVertex()); |
| 78 | } |
| 79 | |
| 80 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 81 | public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) { |
| 82 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 83 | |
| 84 | return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() |
| 85 | ? fg.getVertices("flow_entry_id", flowEntryId.toString(), |
| 86 | IFlowEntry.class).iterator().next() : null; |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 90 | public Iterable<IFlowEntry> getAllFlowEntries() { |
| 91 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 92 | |
| 93 | return fg.getVertices("type", "flow_entry", IFlowEntry.class); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 97 | public void removeFlowEntry(IFlowEntry flowEntry) { |
| 98 | FramedGraph<RamCloudGraph> fg = conn.getFramedGraph(); |
| 99 | fg.removeVertex(flowEntry.asVertex()); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 103 | public void commit() { |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 104 | conn.commit(); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void rollback() { |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 109 | conn.rollback(); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void close() { |
yoshi | e665e82 | 2013-11-26 19:51:16 -0800 | [diff] [blame] | 114 | conn.close(); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 115 | } |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 116 | } |