blob: 235e38a517e5fd05c5b92a1686e8756ff9e266f5 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.core.flowmanager;
2
3import java.util.Collection;
Toshio Koidea03915e2014-07-01 18:39:52 -07004
Toshio Koidea03915e2014-07-01 18:39:52 -07005import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
Toshio Koideb8cea262014-08-12 18:45:46 -07006import net.onrc.onos.api.flowmanager.Flow;
Toshio Koidefc5acc72014-08-12 18:45:46 -07007import net.onrc.onos.api.flowmanager.FlowBatchHandle;
Toshio Koide4ea84192014-07-31 12:10:12 -07008import net.onrc.onos.api.flowmanager.FlowBatchOperation;
Toshio Koide025a9152014-07-21 11:00:34 -07009import net.onrc.onos.api.flowmanager.FlowId;
Toshio Koideb8cea262014-08-12 18:45:46 -070010import net.onrc.onos.api.flowmanager.FlowManagerListener;
Toshio Koidefad1cd52014-08-07 17:10:07 -070011import net.onrc.onos.api.flowmanager.FlowManagerService;
Toshio Koidea03915e2014-07-01 18:39:52 -070012
13/**
Toshio Koide7894ca02014-08-15 14:30:13 -070014 * Manages a set of Flow objects, computes and maintains a set of Match-Action
15 * entries based on the Flow objects, and executes Match-Action plans.
Toshio Koidea03915e2014-07-01 18:39:52 -070016 * <p>
17 * TODO: Make all methods thread-safe
18 */
Toshio Koidefad1cd52014-08-07 17:10:07 -070019public class FlowManagerModule implements FlowManagerService {
Toshio Koided46b66d2014-07-21 10:27:27 -070020 private ConflictDetectionPolicy conflictDetectionPolicy;
Toshio Koidefc5acc72014-08-12 18:45:46 -070021 private FlowOperationMap flowOperationMap;
Toshio Koided46b66d2014-07-21 10:27:27 -070022
23 /**
24 * Constructor.
25 */
26 public FlowManagerModule() {
27 this.conflictDetectionPolicy = ConflictDetectionPolicy.FREE;
Toshio Koidefc5acc72014-08-12 18:45:46 -070028 this.flowOperationMap = new FlowOperationMap();
Toshio Koided46b66d2014-07-21 10:27:27 -070029 }
30
Toshio Koidea03915e2014-07-01 18:39:52 -070031 @Override
Toshio Koidefc5acc72014-08-12 18:45:46 -070032 public FlowBatchHandle addFlow(Flow flow) {
Toshio Koide4ea84192014-07-31 12:10:12 -070033 FlowBatchOperation ops = new FlowBatchOperation();
34 ops.addAddFlowOperation(flow);
Toshio Koidea03915e2014-07-01 18:39:52 -070035 return executeBatch(ops);
36 }
37
38 @Override
Toshio Koidefc5acc72014-08-12 18:45:46 -070039 public FlowBatchHandle removeFlow(FlowId id) {
Toshio Koide4ea84192014-07-31 12:10:12 -070040 FlowBatchOperation ops = new FlowBatchOperation();
41 ops.addRemoveFlowOperation(id);
Toshio Koidea03915e2014-07-01 18:39:52 -070042 return executeBatch(ops);
43 }
44
45 @Override
Toshio Koidefad1cd52014-08-07 17:10:07 -070046 public Flow getFlow(FlowId id) {
Toshio Koidea03915e2014-07-01 18:39:52 -070047 // TODO Auto-generated method stub
48 return null;
49 }
50
51 @Override
Toshio Koidefad1cd52014-08-07 17:10:07 -070052 public Collection<Flow> getFlows() {
Toshio Koidea03915e2014-07-01 18:39:52 -070053 // TODO Auto-generated method stub
54 return null;
55 }
56
57 @Override
Toshio Koidefc5acc72014-08-12 18:45:46 -070058 public FlowBatchHandle executeBatch(FlowBatchOperation ops) {
59 // This method just put the batch-operation object to the global
60 // flow operation map with unique ID. The leader process will get
61 // the appended operation with events notified from the map.
62 FlowBatchHandle handler = flowOperationMap.putOperation(ops);
63
64 // Then it will return a handler to obtain the result of this operation,
65 // control the executing process, etc.
66 return handler;
Toshio Koidea03915e2014-07-01 18:39:52 -070067 }
68
69 @Override
70 public void setConflictDetectionPolicy(ConflictDetectionPolicy policy) {
Toshio Koided46b66d2014-07-21 10:27:27 -070071 if (policy == ConflictDetectionPolicy.FREE) {
72 conflictDetectionPolicy = policy;
73 } else {
74 throw new UnsupportedOperationException(
75 policy.toString() + " is not supported.");
76 }
Toshio Koidea03915e2014-07-01 18:39:52 -070077 }
78
79 @Override
80 public ConflictDetectionPolicy getConflictDetectionPolicy() {
Toshio Koided46b66d2014-07-21 10:27:27 -070081 return conflictDetectionPolicy;
Toshio Koidea03915e2014-07-01 18:39:52 -070082 }
83
84 @Override
Toshio Koideb8cea262014-08-12 18:45:46 -070085 public void addListener(FlowManagerListener listener) {
Toshio Koidea03915e2014-07-01 18:39:52 -070086 // TODO Auto-generated method stub
87
88 }
89
90 @Override
Toshio Koideb8cea262014-08-12 18:45:46 -070091 public void removeListener(FlowManagerListener listener) {
Toshio Koidea03915e2014-07-01 18:39:52 -070092 // TODO Auto-generated method stub
93
94 }
95}