blob: 68226d1816e75a5636b0b9f1123ceeffaac8d67e [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
yoshi0451f282013-11-22 15:48:55 -08007import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph;
8import com.tinkerpop.frames.FramedGraph;
yoshi0451f282013-11-22 15:48:55 -08009import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
11import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
13import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
yoshie665e822013-11-26 19:51:16 -080014import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
yoshi0451f282013-11-22 15:48:55 -080015import net.onrc.onos.ofcontroller.util.FlowEntryId;
16import net.onrc.onos.ofcontroller.util.FlowId;
17import org.apache.commons.configuration.Configuration;
18
19/**
20 *
21 * @author nickkaranatsios
22 */
23public class RamCloudDBOperation extends DBOperation {
24
25 public RamCloudDBOperation() {
yoshi0451f282013-11-22 15:48:55 -080026 }
27
28 @Override
yoshie665e822013-11-26 19:51:16 -080029 public Iterable<ISwitchObject> getAllSwitches() {
yoshi0451f282013-11-22 15:48:55 -080030 return getAllSwitches(conn.getFramedGraph());
31 }
32
33 @Override
yoshi0451f282013-11-22 15:48:55 -080034 public void removePort(INetMapTopologyObjects.IPortObject port) {
35 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
36 if (fg != null) {
37 fg.removeVertex(port.asVertex());
38 }
39 }
40
yoshi0451f282013-11-22 15:48:55 -080041 @Override
42 public IDeviceObject searchDevice(String macAddr) {
43 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
44 return searchDevice(macAddr, fg);
45 }
46
47 @Override
48 public Iterable<IDeviceObject> getDevices() {
49 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
50 return fg != null ? fg.getVertices("type", "device", IDeviceObject.class) : null;
51 }
52
53 @Override
54 public void removeDevice(IDeviceObject dev) {
55 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
56 if (fg != null) {
57 fg.removeVertex(dev.asVertex());
58 }
59 }
60
61
62 @Override
yoshie665e822013-11-26 19:51:16 -080063 public IFlowPath searchFlowPath(FlowId flowId) {
yoshi0451f282013-11-22 15:48:55 -080064 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
65 return searchFlowPath(flowId, fg);
66 }
67
68 @Override
69 public Iterable<IFlowPath> getAllFlowPaths() {
70 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
71 return getAllFlowPaths(fg);
72 }
73
74 @Override
yoshie665e822013-11-26 19:51:16 -080075 public void removeFlowPath(IFlowPath flowPath) {
yoshi0451f282013-11-22 15:48:55 -080076 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
77 fg.removeVertex(flowPath.asVertex());
78 }
79
80 @Override
yoshie665e822013-11-26 19:51:16 -080081 public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) {
82 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
83
84 return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext()
85 ? fg.getVertices("flow_entry_id", flowEntryId.toString(),
86 IFlowEntry.class).iterator().next() : null;
yoshi0451f282013-11-22 15:48:55 -080087 }
88
89 @Override
yoshie665e822013-11-26 19:51:16 -080090 public Iterable<IFlowEntry> getAllFlowEntries() {
91 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
92
93 return fg.getVertices("type", "flow_entry", IFlowEntry.class);
yoshi0451f282013-11-22 15:48:55 -080094 }
95
96 @Override
yoshie665e822013-11-26 19:51:16 -080097 public void removeFlowEntry(IFlowEntry flowEntry) {
98 FramedGraph<RamCloudGraph> fg = conn.getFramedGraph();
99 fg.removeVertex(flowEntry.asVertex());
yoshi0451f282013-11-22 15:48:55 -0800100 }
101
102 @Override
yoshi0451f282013-11-22 15:48:55 -0800103 public void commit() {
yoshie665e822013-11-26 19:51:16 -0800104 conn.commit();
yoshi0451f282013-11-22 15:48:55 -0800105 }
106
107 @Override
108 public void rollback() {
yoshie665e822013-11-26 19:51:16 -0800109 conn.rollback();
yoshi0451f282013-11-22 15:48:55 -0800110 }
111
112 @Override
113 public void close() {
yoshie665e822013-11-26 19:51:16 -0800114 conn.close();
yoshi0451f282013-11-22 15:48:55 -0800115 }
yoshi0451f282013-11-22 15:48:55 -0800116}