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 | |
| 7 | import com.thinkaurelius.titan.core.TitanGraph; |
| 8 | import com.tinkerpop.blueprints.Vertex; |
| 9 | import com.tinkerpop.frames.FramedGraph; |
| 10 | import com.tinkerpop.frames.structures.FramedVertexIterable; |
| 11 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 12 | import java.util.ArrayList; |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 13 | import java.util.Iterator; |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 14 | import java.util.List; |
| 15 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.*; |
| 16 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
| 17 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 18 | import net.onrc.onos.ofcontroller.util.FlowId; |
| 19 | |
| 20 | /** |
| 21 | * |
| 22 | * @author nickkaranatsios |
| 23 | */ |
| 24 | public class TitanDBOperation extends DBOperation { |
| 25 | |
| 26 | /** |
| 27 | * Search and get a switch object with DPID. |
| 28 | * |
| 29 | * @param dpid DPID of the switch |
| 30 | */ |
| 31 | @Override |
| 32 | public ISwitchObject searchSwitch(String dpid) { |
| 33 | final FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 34 | |
| 35 | return searchSwitch(dpid, fg); |
| 36 | } |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 37 | |
| 38 | @Override |
| 39 | public Iterable<ISwitchObject> getActiveSwitches() { |
| 40 | final FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 41 | |
| 42 | return getActiveSwitches(fg); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public IPortObject searchPort(String dpid, Short number) { |
| 47 | final FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 48 | return searchPort(dpid, number, fg); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | @Override |
| 53 | public void removePort(IPortObject port) { |
| 54 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 55 | if (fg != null) { |
| 56 | fg.removeVertex(port.asVertex()); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | @Override |
| 62 | public IDeviceObject searchDevice(String macAddr) { |
| 63 | // TODO Auto-generated method stub |
| 64 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 65 | return searchDevice(macAddr, fg); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public Iterable<IDeviceObject> getDevices() { |
| 70 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 71 | return fg != null ? fg.getVertices("type", "device", IDeviceObject.class) : null; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void removeDevice(IDeviceObject dev) { |
| 76 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 77 | if (fg != null) { |
| 78 | fg.removeVertex(dev.asVertex()); |
| 79 | } |
| 80 | } |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 81 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 82 | @Override |
| 83 | public IFlowPath searchFlowPath(FlowId flowId) { |
| 84 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 85 | return searchFlowPath(flowId, fg); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | @Override |
| 90 | public Iterable<IFlowPath> getAllFlowPaths() { |
| 91 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 92 | return getAllFlowPaths(fg); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void removeFlowPath(IFlowPath flowPath) { |
| 97 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 98 | fg.removeVertex(flowPath.asVertex()); |
| 99 | } |
| 100 | |
| 101 | @Override |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 102 | public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) { |
| 103 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 104 | |
| 105 | return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() |
| 106 | ? fg.getVertices("flow_entry_id", flowEntryId.toString(), |
| 107 | IFlowEntry.class).iterator().next() : null; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public Iterable<IFlowEntry> getAllFlowEntries() { |
| 112 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 113 | |
| 114 | return fg.getVertices("type", "flow_entry", IFlowEntry.class); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void removeFlowEntry(IFlowEntry flowEntry) { |
| 119 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 120 | fg.removeVertex(flowEntry.asVertex()); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public IDBConnection getDBConnection() { |
yoshi | a0839b5 | 2013-11-25 16:42:10 -0800 | [diff] [blame] | 125 | System.out.println("TitangetDBConnection"); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 126 | return conn; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void commit() { |
| 131 | conn.commit(); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void rollback() { |
| 136 | conn.rollback(); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void close() { |
| 141 | conn.close(); |
| 142 | } |
yoshi | 5280699 | 2013-11-27 02:15:47 -0800 | [diff] [blame] | 143 | |
| 144 | @Override |
yoshi | 0bc0721 | 2013-11-27 02:23:51 -0800 | [diff] [blame^] | 145 | public ISwitchObject newSwitch(final String dpid) { |
| 146 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 147 | return super.newSwitch(dpid, fg); |
| 148 | } |
| 149 | |
| 150 | @Override |
yoshi | 5280699 | 2013-11-27 02:15:47 -0800 | [diff] [blame] | 151 | public IDeviceObject newDevice() { |
| 152 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 153 | return super.newDevice(fg); |
| 154 | } |
yoshi | 0bc0721 | 2013-11-27 02:23:51 -0800 | [diff] [blame^] | 155 | |
| 156 | @Override |
| 157 | public IPortObject newPort(String dpid, Short portNum) { |
| 158 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 159 | return super.newPort(dpid, portNum, fg); |
| 160 | } |
yoshi | 5280699 | 2013-11-27 02:15:47 -0800 | [diff] [blame] | 161 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 162 | } |