Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 1 | package net.onrc.onos.util; |
| 2 | |
| 3 | import com.thinkaurelius.titan.core.TitanGraph; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 4 | import com.tinkerpop.blueprints.Vertex; |
| 5 | import com.tinkerpop.frames.FramedGraph; |
| 6 | import com.tinkerpop.frames.FramedVertexIterable; |
| 7 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 8 | |
| 9 | import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject; |
| 10 | import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject; |
| 11 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 12 | |
| 13 | public class GraphDBUtils implements IDBUtils { |
| 14 | |
| 15 | @Override |
| 16 | public ISwitchObject searchSwitch(GraphDBConnection conn, String dpid) { |
| 17 | // TODO Auto-generated method stub |
| 18 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 19 | |
| 20 | return fg.getVertices("dpid",dpid).iterator().hasNext() ? |
| 21 | fg.getVertices("dpid",dpid,ISwitchObject.class).iterator().next() : null; |
| 22 | |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public IDeviceObject searchDevice(GraphDBConnection conn, String macAddr) { |
| 27 | // TODO Auto-generated method stub |
| 28 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 29 | return fg.getVertices("dl_address",macAddr).iterator().hasNext() ? fg.getVertices("dl_address",macAddr, |
| 30 | IDeviceObject.class).iterator().next() : null; |
| 31 | |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public IPortObject searchPort(GraphDBConnection conn, String dpid, short number) { |
| 36 | ISwitchObject sw = searchSwitch(conn, dpid); |
| 37 | GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>(); |
| 38 | pipe.start(sw.asVertex()); |
| 39 | pipe.out("on").has("number", number); |
| 40 | FramedVertexIterable<IPortObject> r = new FramedVertexIterable(conn.getFramedGraph(), pipe, IPortObject.class); |
| 41 | return r.iterator().hasNext() ? r.iterator().next() : null; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public IDeviceObject newDevice(GraphDBConnection conn) { |
| 46 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 47 | IDeviceObject obj = fg.addVertex(null,IDeviceObject.class); |
| 48 | return obj; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void removeDevice(GraphDBConnection conn, IDeviceObject dev) { |
| 53 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 54 | fg.removeVertex(dev.asVertex()); |
| 55 | } |
| 56 | |
Pankaj Berde | ac1a8c3 | 2013-02-26 17:45:57 -0800 | [diff] [blame] | 57 | @Override |
| 58 | public Iterable<IDeviceObject> getDevices(GraphDBConnection conn) { |
| 59 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 60 | return fg.getVertices("type","device",IDeviceObject.class); |
| 61 | } |
| 62 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 63 | } |