Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 1 | package net.onrc.onos.util; |
| 2 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
Toshio Koide | b29b9b3 | 2013-06-13 14:37:46 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject; |
| 7 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 8 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 11 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
| 12 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 13 | import net.onrc.onos.ofcontroller.util.FlowId; |
| 14 | |
Pankaj Berde | 8f03611 | 2013-03-28 22:58:47 -0700 | [diff] [blame] | 15 | import com.thinkaurelius.titan.core.TitanGraph; |
| 16 | import com.tinkerpop.blueprints.Vertex; |
Pankaj Berde | 8f03611 | 2013-03-28 22:58:47 -0700 | [diff] [blame] | 17 | import com.tinkerpop.frames.FramedGraph; |
Pankaj Berde | 5d50641 | 2013-04-23 15:03:02 -0700 | [diff] [blame] | 18 | import com.tinkerpop.frames.structures.FramedVertexIterable; |
Pankaj Berde | 8f03611 | 2013-03-28 22:58:47 -0700 | [diff] [blame] | 19 | import com.tinkerpop.gremlin.java.GremlinPipeline; |
| 20 | |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 21 | public class GraphDBOperation implements IDBOperation { |
| 22 | private GraphDBConnection conn; |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 23 | |
| 24 | /** |
| 25 | * Create a GraphDBOperation instance from specified GraphDBConnection's instance. |
| 26 | * @param dbConnection an instance of GraphDBConnection |
| 27 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 28 | public GraphDBOperation(GraphDBConnection dbConnection) { |
| 29 | this.conn = dbConnection; |
| 30 | } |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 31 | |
| 32 | /** |
| 33 | * Create a GraphDBOperation instance from database configuration path. |
| 34 | * @param dbConfPath a path for database configuration file. |
| 35 | */ |
Toshio Koide | bfe9b92 | 2013-06-18 10:56:05 -0700 | [diff] [blame] | 36 | public GraphDBOperation(final String dbConfPath) { |
| 37 | this.conn = GraphDBConnection.getInstance(dbConfPath); |
| 38 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 39 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 40 | /** |
| 41 | * Create a new switch and return the created switch object. |
| 42 | * @param dpid DPID of the switch |
| 43 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 44 | public ISwitchObject newSwitch(String dpid) { |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 45 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 46 | ISwitchObject obj = fg.addVertex(null,ISwitchObject.class); |
Toshio Koide | 12004e6 | 2013-06-12 18:17:53 -0700 | [diff] [blame] | 47 | if (obj != null) { |
| 48 | obj.setType("switch"); |
| 49 | obj.setDPID(dpid); |
| 50 | } |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 51 | return obj; |
| 52 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 53 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 54 | /** |
| 55 | * Search and get a switch object with DPID. |
| 56 | * @param dpid DPID of the switch |
| 57 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 58 | public ISwitchObject searchSwitch(String dpid) { |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 59 | // TODO Auto-generated method stub |
| 60 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 61 | |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 62 | return (fg != null && fg.getVertices("dpid",dpid).iterator().hasNext()) ? |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 63 | fg.getVertices("dpid",dpid,ISwitchObject.class).iterator().next() : null; |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 64 | |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 67 | /** |
| 68 | * Search and get an active switch object with DPID. |
| 69 | * @param dpid DPID of the switch |
| 70 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 71 | public ISwitchObject searchActiveSwitch(String dpid) { |
| 72 | |
| 73 | ISwitchObject sw = searchSwitch(dpid); |
| 74 | if ((sw != null) && |
| 75 | sw.getState().equals(SwitchState.ACTIVE.toString())) { |
| 76 | return sw; |
| 77 | } |
| 78 | return null; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 81 | /** |
| 82 | * Get all switch objects. |
| 83 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 84 | public Iterable<ISwitchObject> getAllSwitches() { |
| 85 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 86 | Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class); |
| 87 | return switches; |
| 88 | } |
| 89 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 90 | /** |
| 91 | * Get all active switch objects. |
| 92 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 93 | public Iterable<ISwitchObject> getActiveSwitches() { |
| 94 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 95 | Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class); |
| 96 | List<ISwitchObject> activeSwitches = new ArrayList<ISwitchObject>(); |
| 97 | |
| 98 | for (ISwitchObject sw: switches) { |
| 99 | if(sw.getState().equals(SwitchState.ACTIVE.toString())) { |
| 100 | activeSwitches.add(sw); |
Pankaj Berde | c165a52 | 2013-06-10 21:28:11 -0700 | [diff] [blame] | 101 | } |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 102 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 103 | return activeSwitches; |
| 104 | } |
| 105 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 106 | /** |
| 107 | * Get all inactive switch objects. |
| 108 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 109 | public Iterable<ISwitchObject> getInactiveSwitches() { |
| 110 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 111 | Iterable<ISwitchObject> switches = fg.getVertices("type","switch",ISwitchObject.class); |
| 112 | List<ISwitchObject> inactiveSwitches = new ArrayList<ISwitchObject>(); |
| 113 | |
| 114 | for (ISwitchObject sw: switches) { |
| 115 | if(sw.getState().equals(SwitchState.INACTIVE.toString())) { |
| 116 | inactiveSwitches.add(sw); |
| 117 | } |
| 118 | } |
| 119 | return inactiveSwitches; |
| 120 | } |
| 121 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 122 | /** |
| 123 | * Get all flow entries' objects where their switches are not updated. |
| 124 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 125 | public Iterable<IFlowEntry> getAllSwitchNotUpdatedFlowEntries() { |
| 126 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 127 | //TODO: Should use an enum for flow_switch_state |
| 128 | return fg.getVertices("switch_state", "FE_SWITCH_NOT_UPDATED", IFlowEntry.class); |
| 129 | } |
| 130 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 131 | /** |
| 132 | * Remove specified switch. |
| 133 | * @param sw switch object to remove |
| 134 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 135 | public void removeSwitch(ISwitchObject sw) { |
| 136 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 137 | fg.removeVertex(sw.asVertex()); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 140 | /** |
| 141 | * Create a port having specified port number. |
| 142 | * @param portNumber port number |
| 143 | */ |
Toshio Koide | 12004e6 | 2013-06-12 18:17:53 -0700 | [diff] [blame] | 144 | public IPortObject newPort(Short portNumber) { |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 145 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 146 | IPortObject obj = fg.addVertex(null,IPortObject.class); |
Toshio Koide | 12004e6 | 2013-06-12 18:17:53 -0700 | [diff] [blame] | 147 | if (obj != null) { |
| 148 | obj.setType("port"); |
| 149 | obj.setNumber(portNumber); |
| 150 | } |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 151 | return obj; |
| 152 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 153 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 154 | /** |
| 155 | * Search and get a port object of specified switch and port number. |
| 156 | * @param dpid DPID of a switch |
| 157 | * @param number port number of the switch's port |
| 158 | */ |
| 159 | public IPortObject searchPort(String dpid, short number) { |
| 160 | ISwitchObject sw = searchSwitch(dpid); |
| 161 | if (sw != null) { |
| 162 | |
| 163 | IPortObject port = null; |
| 164 | |
| 165 | // Requires Frames 2.3.0 |
| 166 | |
| 167 | try { |
| 168 | port = sw.getPort(number); |
| 169 | } catch (Exception e) { |
| 170 | // TODO Auto-generated catch block |
| 171 | e.printStackTrace(); |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 174 | return port; |
| 175 | } |
| 176 | |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 177 | // if (sw != null) { |
| 178 | // GremlinPipeline<Vertex, IPortObject> pipe = new GremlinPipeline<Vertex, IPortObject>(); |
| 179 | // pipe.start(sw.asVertex()); |
| 180 | // pipe.out("on").has("number", number); |
| 181 | // FramedVertexIterable<IPortObject> r = new FramedVertexIterable<IPortObject>(conn.getFramedGraph(), (Iterable) pipe, IPortObject.class); |
| 182 | // return r != null && r.iterator().hasNext() ? r.iterator().next() : null; |
| 183 | // } |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 184 | return null; |
| 185 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 186 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 187 | /** |
| 188 | * Remove the specified switch port. |
| 189 | * @param port switch port object to remove |
| 190 | */ |
| 191 | public void removePort(IPortObject port) { |
| 192 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 193 | // EventGraph<TitanGraph> eg = conn.getEventGraph(); |
| 194 | if (fg != null) fg.removeVertex(port.asVertex()); |
| 195 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 196 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 197 | /** |
| 198 | * Create and return a device object. |
| 199 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 200 | public IDeviceObject newDevice() { |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 201 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 202 | IDeviceObject obj = fg.addVertex(null,IDeviceObject.class); |
Toshio Koide | d7b7e10 | 2013-06-12 17:13:25 -0700 | [diff] [blame] | 203 | if (obj != null) obj.setType("device"); |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 204 | return obj; |
| 205 | } |
| 206 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 207 | /** |
| 208 | * Search and get a device object having specified MAC address. |
| 209 | * @param macAddr MAC address to search and get |
| 210 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 211 | public IDeviceObject searchDevice(String macAddr) { |
| 212 | // TODO Auto-generated method stub |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 213 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Toshio Koide | 1326010 | 2013-06-17 13:44:27 -0700 | [diff] [blame] | 214 | return (fg != null && fg.getVertices("dl_addr",macAddr).iterator().hasNext()) ? |
| 215 | fg.getVertices("dl_addr",macAddr, IDeviceObject.class).iterator().next() : null; |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 218 | /** |
| 219 | * Get all devices. |
| 220 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 221 | public Iterable<IDeviceObject> getDevices() { |
Pankaj Berde | ac1a8c3 | 2013-02-26 17:45:57 -0800 | [diff] [blame] | 222 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Pankaj Berde | 6201614 | 2013-04-09 15:35:50 -0700 | [diff] [blame] | 223 | return fg != null ? fg.getVertices("type","device",IDeviceObject.class) : null; |
Pankaj Berde | ac1a8c3 | 2013-02-26 17:45:57 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 226 | /** |
| 227 | * Remove the specified device. |
| 228 | * @param dev a device object to remove |
| 229 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 230 | public void removeDevice(IDeviceObject dev) { |
| 231 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 232 | if (fg != null) fg.removeVertex(dev.asVertex()); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 235 | /** |
| 236 | * Create and return a flow path object. |
| 237 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 238 | public IFlowPath newFlowPath() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 239 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 240 | IFlowPath flowPath = fg.addVertex(null, IFlowPath.class); |
Toshio Koide | d7b7e10 | 2013-06-12 17:13:25 -0700 | [diff] [blame] | 241 | if (flowPath != null) flowPath.setType("flow"); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 242 | return flowPath; |
| 243 | } |
| 244 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 245 | /** |
| 246 | * Search and get a flow path object with specified flow ID. |
| 247 | * @param flowId flow ID to search |
| 248 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 249 | public IFlowPath searchFlowPath(FlowId flowId) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 250 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 251 | |
| 252 | return fg.getVertices("flow_id", flowId.toString()).iterator().hasNext() ? |
| 253 | fg.getVertices("flow_id", flowId.toString(), |
| 254 | IFlowPath.class).iterator().next() : null; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 257 | /** |
| 258 | * Get a flow path object with a flow entry. |
| 259 | * @param flowEntry flow entry object |
| 260 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 261 | public IFlowPath getFlowPathByFlowEntry(IFlowEntry flowEntry) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 262 | GremlinPipeline<Vertex, IFlowPath> pipe = new GremlinPipeline<Vertex, IFlowPath>(); |
| 263 | pipe.start(flowEntry.asVertex()); |
| 264 | pipe.out("flow"); |
Pankaj Berde | 8f03611 | 2013-03-28 22:58:47 -0700 | [diff] [blame] | 265 | FramedVertexIterable<IFlowPath> r = new FramedVertexIterable(conn.getFramedGraph(), (Iterable) pipe, IFlowPath.class); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 266 | return r.iterator().hasNext() ? r.iterator().next() : null; |
| 267 | } |
| 268 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 269 | /** |
| 270 | * Get all flow path objects. |
| 271 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 272 | public Iterable<IFlowPath> getAllFlowPaths() { |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 273 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Jonathan Hart | f5315fb | 2013-04-05 11:41:56 -0700 | [diff] [blame] | 274 | Iterable<IFlowPath> flowPaths = fg.getVertices("type", "flow", IFlowPath.class); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 275 | |
Jonathan Hart | f5315fb | 2013-04-05 11:41:56 -0700 | [diff] [blame] | 276 | List<IFlowPath> nonNullFlows = new ArrayList<IFlowPath>(); |
| 277 | |
| 278 | for (IFlowPath fp: flowPaths) { |
| 279 | if (fp.getFlowId() != null) { |
| 280 | nonNullFlows.add(fp); |
| 281 | } |
| 282 | } |
| 283 | return nonNullFlows; |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 286 | /** |
| 287 | * Remove the specified flow path. |
| 288 | * @param flowPath flow path object to remove |
| 289 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 290 | public void removeFlowPath(IFlowPath flowPath) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 291 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 292 | fg.removeVertex(flowPath.asVertex()); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 295 | /** |
| 296 | * Create and return a flow entry object. |
| 297 | */ |
Toshio Koide | eb88ff6 | 2013-06-12 16:46:40 -0700 | [diff] [blame] | 298 | public IFlowEntry newFlowEntry() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 299 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 300 | IFlowEntry flowEntry = fg.addVertex(null, IFlowEntry.class); |
Toshio Koide | d7b7e10 | 2013-06-12 17:13:25 -0700 | [diff] [blame] | 301 | if (flowEntry != null) flowEntry.setType("flow_entry"); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 302 | return flowEntry; |
| 303 | } |
| 304 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 305 | /** |
| 306 | * Search and get a flow entry object with flow entry ID. |
| 307 | * @param flowEntryId flow entry ID to search |
| 308 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 309 | public IFlowEntry searchFlowEntry(FlowEntryId flowEntryId) { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 310 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 311 | |
| 312 | return fg.getVertices("flow_entry_id", flowEntryId.toString()).iterator().hasNext() ? |
| 313 | fg.getVertices("flow_entry_id", flowEntryId.toString(), |
| 314 | IFlowEntry.class).iterator().next() : null; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 317 | /** |
| 318 | * Get all flow entry objects. |
| 319 | */ |
| 320 | public Iterable<IFlowEntry> getAllFlowEntries() { |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 321 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
| 322 | |
| 323 | return fg.getVertices("type", "flow_entry", IFlowEntry.class); |
| 324 | } |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 325 | |
Toshio Koide | 1d1a856 | 2013-06-18 17:19:51 -0700 | [diff] [blame^] | 326 | /** |
| 327 | * Remove the specified flow entry. |
| 328 | * @param flowEntry flow entry object to remove |
| 329 | */ |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 330 | public void removeFlowEntry(IFlowEntry flowEntry) { |
Pankaj Berde | d1c3859 | 2013-04-10 22:46:40 -0700 | [diff] [blame] | 331 | FramedGraph<TitanGraph> fg = conn.getFramedGraph(); |
Toshio Koide | 5340380 | 2013-06-13 10:08:06 -0700 | [diff] [blame] | 332 | fg.removeVertex(flowEntry.asVertex()); |
Pankaj Berde | 2239f0d | 2013-04-04 09:42:43 -0700 | [diff] [blame] | 333 | } |
Toshio Koide | a41950a | 2013-06-13 13:09:19 -0700 | [diff] [blame] | 334 | |
| 335 | public IDBConnection getDBConnection() { |
| 336 | return conn; |
| 337 | } |
| 338 | |
| 339 | public void commit() { |
Toshio Koide | dc94944 | 2013-06-18 10:35:51 -0700 | [diff] [blame] | 340 | conn.commit(); |
Toshio Koide | a41950a | 2013-06-13 13:09:19 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | public void rollback() { |
Toshio Koide | dc94944 | 2013-06-18 10:35:51 -0700 | [diff] [blame] | 344 | conn.rollback(); |
Toshio Koide | a41950a | 2013-06-13 13:09:19 -0700 | [diff] [blame] | 345 | } |
Toshio Koide | f20a507 | 2013-06-13 13:18:22 -0700 | [diff] [blame] | 346 | |
| 347 | public void close() { |
| 348 | conn.close(); |
| 349 | } |
Pankaj Berde | da80957 | 2013-02-22 15:31:20 -0800 | [diff] [blame] | 350 | } |