blob: c2152cc708768276d3ae0bff5ac5a89edd7ebd37 [file] [log] [blame]
yoshi0451f282013-11-22 15:48:55 -08001/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package net.onrc.onos.graph;
6
7import com.thinkaurelius.titan.core.TitanGraph;
8import com.tinkerpop.blueprints.Vertex;
9import com.tinkerpop.frames.FramedGraph;
10import com.tinkerpop.frames.structures.FramedVertexIterable;
11import com.tinkerpop.gremlin.java.GremlinPipeline;
12import java.util.ArrayList;
yoshitomob292c622013-11-23 14:35:58 -080013import java.util.Iterator;
yoshi0451f282013-11-22 15:48:55 -080014import java.util.List;
15import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.*;
16import net.onrc.onos.ofcontroller.core.ISwitchStorage;
17import net.onrc.onos.ofcontroller.util.FlowEntryId;
18import net.onrc.onos.ofcontroller.util.FlowId;
19
20/**
21 *
22 * @author nickkaranatsios
23 */
24public 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 }
yoshi0451f282013-11-22 15:48:55 -080037
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 }
yoshitomob292c622013-11-23 14:35:58 -080081
yoshi0451f282013-11-22 15:48:55 -080082 @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
yoshi0451f282013-11-22 15:48:55 -0800102 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() {
yoshia0839b52013-11-25 16:42:10 -0800125 System.out.println("TitangetDBConnection");
yoshi0451f282013-11-22 15:48:55 -0800126 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 }
yoshi52806992013-11-27 02:15:47 -0800143
144 @Override
yoshi0bc07212013-11-27 02:23:51 -0800145 public ISwitchObject newSwitch(final String dpid) {
146 FramedGraph<TitanGraph> fg = conn.getFramedGraph();
147 return super.newSwitch(dpid, fg);
148 }
149
150 @Override
yoshi52806992013-11-27 02:15:47 -0800151 public IDeviceObject newDevice() {
152 FramedGraph<TitanGraph> fg = conn.getFramedGraph();
153 return super.newDevice(fg);
154 }
yoshi0bc07212013-11-27 02:23:51 -0800155
156 @Override
157 public IPortObject newPort(String dpid, Short portNum) {
158 FramedGraph<TitanGraph> fg = conn.getFramedGraph();
159 return super.newPort(dpid, portNum, fg);
160 }
yoshi52806992013-11-27 02:15:47 -0800161
yoshi0451f282013-11-22 15:48:55 -0800162}