blob: d01de210853a2cb491eb7958f5916501d67f3819 [file] [log] [blame]
Pankaj Berdeda809572013-02-22 15:31:20 -08001package net.onrc.onos.util;
2
3import com.thinkaurelius.titan.core.TitanGraph;
Pankaj Berdeda809572013-02-22 15:31:20 -08004import com.tinkerpop.blueprints.Vertex;
5import com.tinkerpop.frames.FramedGraph;
6import com.tinkerpop.frames.FramedVertexIterable;
7import com.tinkerpop.gremlin.java.GremlinPipeline;
8
9import net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject;
10import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
11import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
Pankaj Berdeda809572013-02-22 15:31:20 -080012
13public 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 Berdeac1a8c32013-02-26 17:45:57 -080057 @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 Berdeda809572013-02-22 15:31:20 -080063}