Mark
Committed by Gerrit Code Review

[Goldeneye] add command line switch to supress core flows

Change-Id: Ide8439ff967394b3b3a2f94243e5d5b2251a1384
...@@ -40,9 +40,11 @@ import java.util.Map; ...@@ -40,9 +40,11 @@ import java.util.Map;
40 import java.util.SortedMap; 40 import java.util.SortedMap;
41 import java.util.TreeMap; 41 import java.util.TreeMap;
42 import java.util.function.Predicate; 42 import java.util.function.Predicate;
43 +import java.util.stream.Collectors;
43 44
44 import static com.google.common.collect.Lists.newArrayList; 45 import static com.google.common.collect.Lists.newArrayList;
45 46
47 +
46 /** 48 /**
47 * Lists all currently-known flows. 49 * Lists all currently-known flows.
48 */ 50 */
...@@ -78,6 +80,11 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -78,6 +80,11 @@ public class FlowsListCommand extends AbstractShellCommand {
78 required = false, multiValued = false) 80 required = false, multiValued = false)
79 private boolean shortOutput = false; 81 private boolean shortOutput = false;
80 82
83 + @Option(name = "-n", aliases = "--no-core-flows",
84 + description = "Suppress core flows from output",
85 + required = false, multiValued = false)
86 + private boolean suppressCoreOutput = false;
87 +
81 @Option(name = "-c", aliases = "--count", 88 @Option(name = "-c", aliases = "--count",
82 description = "Print flow count only", 89 description = "Print flow count only",
83 required = false, multiValued = false) 90 required = false, multiValued = false)
...@@ -93,7 +100,7 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -93,7 +100,7 @@ public class FlowsListCommand extends AbstractShellCommand {
93 100
94 compilePredicate(); 101 compilePredicate();
95 102
96 - SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); 103 + SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service, coreService);
97 104
98 if (outputJson()) { 105 if (outputJson()) {
99 print("%s", json(flows.keySet(), flows)); 106 print("%s", json(flows.keySet(), flows));
...@@ -157,7 +164,7 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -157,7 +164,7 @@ public class FlowsListCommand extends AbstractShellCommand {
157 * @return sorted device list 164 * @return sorted device list
158 */ 165 */
159 protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, 166 protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService,
160 - FlowRuleService service) { 167 + FlowRuleService service, CoreService coreService) {
161 SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR); 168 SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR);
162 List<FlowEntry> rules; 169 List<FlowEntry> rules;
163 170
...@@ -182,6 +189,13 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -182,6 +189,13 @@ public class FlowsListCommand extends AbstractShellCommand {
182 } 189 }
183 } 190 }
184 rules.sort(Comparators.FLOW_RULE_COMPARATOR); 191 rules.sort(Comparators.FLOW_RULE_COMPARATOR);
192 +
193 + if (suppressCoreOutput) {
194 + short coreAppId = coreService.getAppId("org.onosproject.core").id();
195 + rules = rules.stream()
196 + .filter(f -> f.appId() != coreAppId)
197 + .collect(Collectors.toList());
198 + }
185 flows.put(d, rules); 199 flows.put(d, rules);
186 } 200 }
187 return flows; 201 return flows;
......