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 { |
yoshitomo | b292c62 | 2013-11-23 14:35:58 -0800 | [diff] [blame] | 25 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 26 | @Override |
| 27 | public IFlowPath searchFlowPath(FlowId flowId) { |
| 28 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 29 | return searchFlowPath(flowId, fg); |
| 30 | } |
| 31 | |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 32 | @Override |
| 33 | public Iterable<IFlowPath> getAllFlowPaths() { |
| 34 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 35 | return getAllFlowPaths(fg); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public void removeFlowPath(IFlowPath flowPath) { |
| 40 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 41 | fg.removeVertex(flowPath.asVertex()); |
| 42 | } |
| 43 | |
| 44 | @Override |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 45 | public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) { |
| 46 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 47 | |
| 48 | return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() |
| 49 | ? fg.getVertices("flow_entry_id", flowEntryId.toString(), |
| 50 | IFlowEntry.class).iterator().next() : null; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Iterable<IFlowEntry> getAllFlowEntries() { |
| 55 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 56 | |
| 57 | return fg.getVertices("type", "flow_entry", IFlowEntry.class); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void removeFlowEntry(IFlowEntry flowEntry) { |
| 62 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 63 | fg.removeVertex(flowEntry.asVertex()); |
| 64 | } |
| 65 | |
| 66 | @Override |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 67 | public void commit() { |
| 68 | conn.commit(); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void rollback() { |
| 73 | conn.rollback(); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void close() { |
| 78 | conn.close(); |
| 79 | } |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 80 | } |