Madan Jampani

FlowRuleManager is now fully batch based

...@@ -50,6 +50,7 @@ import org.onlab.onos.net.provider.AbstractProviderService; ...@@ -50,6 +50,7 @@ import org.onlab.onos.net.provider.AbstractProviderService;
50 import org.slf4j.Logger; 50 import org.slf4j.Logger;
51 51
52 import com.google.common.collect.ArrayListMultimap; 52 import com.google.common.collect.ArrayListMultimap;
53 +import com.google.common.collect.Iterables;
53 import com.google.common.collect.Lists; 54 import com.google.common.collect.Lists;
54 import com.google.common.collect.Maps; 55 import com.google.common.collect.Maps;
55 import com.google.common.collect.Multimap; 56 import com.google.common.collect.Multimap;
...@@ -116,71 +117,38 @@ public class FlowRuleManager ...@@ -116,71 +117,38 @@ public class FlowRuleManager
116 117
117 @Override 118 @Override
118 public void applyFlowRules(FlowRule... flowRules) { 119 public void applyFlowRules(FlowRule... flowRules) {
120 + Set<FlowRuleBatchEntry> toAddBatchEntries = Sets.newHashSet();
119 for (int i = 0; i < flowRules.length; i++) { 121 for (int i = 0; i < flowRules.length; i++) {
120 - FlowRule f = flowRules[i]; 122 + toAddBatchEntries.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, flowRules[i]));
121 - store.storeFlowRule(f);
122 - }
123 - }
124 -
125 - private void applyFlowRulesToProviders(FlowRule... flowRules) {
126 - DeviceId did = null;
127 - FlowRuleProvider frp = null;
128 - for (FlowRule f : flowRules) {
129 - if (!f.deviceId().equals(did)) {
130 - did = f.deviceId();
131 - final Device device = deviceService.getDevice(did);
132 - frp = getProvider(device.providerId());
133 - }
134 - if (frp != null) {
135 - frp.applyFlowRule(f);
136 - }
137 } 123 }
124 + applyBatch(new FlowRuleBatchOperation(toAddBatchEntries));
138 } 125 }
139 126
140 @Override 127 @Override
141 public void removeFlowRules(FlowRule... flowRules) { 128 public void removeFlowRules(FlowRule... flowRules) {
142 - FlowRule f; 129 + Set<FlowRuleBatchEntry> toRemoveBatchEntries = Sets.newHashSet();
143 for (int i = 0; i < flowRules.length; i++) { 130 for (int i = 0; i < flowRules.length; i++) {
144 - f = flowRules[i]; 131 + toRemoveBatchEntries.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, flowRules[i]));
145 - store.deleteFlowRule(f);
146 - }
147 - }
148 -
149 - private void removeFlowRulesFromProviders(FlowRule... flowRules) {
150 - DeviceId did = null;
151 - FlowRuleProvider frp = null;
152 - for (FlowRule f : flowRules) {
153 - if (!f.deviceId().equals(did)) {
154 - did = f.deviceId();
155 - final Device device = deviceService.getDevice(did);
156 - frp = getProvider(device.providerId());
157 - }
158 - if (frp != null) {
159 - frp.removeFlowRule(f);
160 - }
161 } 132 }
133 + applyBatch(new FlowRuleBatchOperation(toRemoveBatchEntries));
162 } 134 }
163 135
164 @Override 136 @Override
165 public void removeFlowRulesById(ApplicationId id) { 137 public void removeFlowRulesById(ApplicationId id) {
166 - Iterable<FlowRule> rules = getFlowRulesById(id); 138 + removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class));
167 - FlowRuleProvider frp;
168 - Device device;
169 -
170 - for (FlowRule f : rules) {
171 - store.deleteFlowRule(f);
172 - // FIXME: only accept request and push to provider on internal event
173 - device = deviceService.getDevice(f.deviceId());
174 - frp = getProvider(device.providerId());
175 - // FIXME: flows removed from store and flows removed from might diverge
176 - // get rid of #removeRulesById?
177 - frp.removeRulesById(id, f);
178 - }
179 } 139 }
180 140
181 @Override 141 @Override
182 public Iterable<FlowRule> getFlowRulesById(ApplicationId id) { 142 public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
183 - return store.getFlowRulesByAppId(id); 143 + Set<FlowRule> flowEntries = Sets.newHashSet();
144 + for (Device d : deviceService.getDevices()) {
145 + for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
146 + if (flowEntry.appId() == id.id()) {
147 + flowEntries.add(flowEntry);
148 + }
149 + }
150 + }
151 + return flowEntries;
184 } 152 }
185 153
186 @Override 154 @Override
......
...@@ -12,6 +12,7 @@ import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED; ...@@ -12,6 +12,7 @@ import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
12 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED; 12 import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
13 13
14 import java.util.ArrayList; 14 import java.util.ArrayList;
15 +import java.util.Arrays;
15 import java.util.Collections; 16 import java.util.Collections;
16 import java.util.HashMap; 17 import java.util.HashMap;
17 import java.util.List; 18 import java.util.List;
...@@ -461,12 +462,12 @@ public class FlowRuleManagerTest { ...@@ -461,12 +462,12 @@ public class FlowRuleManagerTest {
461 462
462 @Override 463 @Override
463 public int getDeviceCount() { 464 public int getDeviceCount() {
464 - return 0; 465 + return 1;
465 } 466 }
466 467
467 @Override 468 @Override
468 public Iterable<Device> getDevices() { 469 public Iterable<Device> getDevices() {
469 - return null; 470 + return Arrays.asList(DEV);
470 } 471 }
471 472
472 @Override 473 @Override
......