Enhanced flow list command to be more parsable and to use sorted devices list.
Fixed NPE.
Showing
2 changed files
with
14 additions
and
15 deletions
| ... | @@ -47,7 +47,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -47,7 +47,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 47 | DeviceService deviceService = get(DeviceService.class); | 47 | DeviceService deviceService = get(DeviceService.class); |
| 48 | FlowRuleService service = get(FlowRuleService.class); | 48 | FlowRuleService service = get(FlowRuleService.class); |
| 49 | Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); | 49 | Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); |
| 50 | - for (Device d : flows.keySet()) { | 50 | + for (Device d : getSortedDevices(deviceService)) { |
| 51 | printFlows(d, flows.get(d)); | 51 | printFlows(d, flows.get(d)); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| ... | @@ -58,14 +58,15 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -58,14 +58,15 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 58 | * @param service device service | 58 | * @param service device service |
| 59 | * @return sorted device list | 59 | * @return sorted device list |
| 60 | */ | 60 | */ |
| 61 | - protected Map<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, FlowRuleService service) { | 61 | + protected Map<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, |
| 62 | + FlowRuleService service) { | ||
| 62 | Map<Device, List<FlowEntry>> flows = Maps.newHashMap(); | 63 | Map<Device, List<FlowEntry>> flows = Maps.newHashMap(); |
| 63 | List<FlowEntry> rules; | 64 | List<FlowEntry> rules; |
| 64 | FlowEntryState s = null; | 65 | FlowEntryState s = null; |
| 65 | if (state != null && !state.equals("any")) { | 66 | if (state != null && !state.equals("any")) { |
| 66 | s = FlowEntryState.valueOf(state.toUpperCase()); | 67 | s = FlowEntryState.valueOf(state.toUpperCase()); |
| 67 | } | 68 | } |
| 68 | - Iterable<Device> devices = uri == null ? getSortedDevices(deviceService) : | 69 | + Iterable<Device> devices = uri == null ? deviceService.getDevices() : |
| 69 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); | 70 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); |
| 70 | for (Device d : devices) { | 71 | for (Device d : devices) { |
| 71 | if (s == null) { | 72 | if (s == null) { |
| ... | @@ -90,18 +91,16 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -90,18 +91,16 @@ public class FlowsListCommand extends AbstractShellCommand { |
| 90 | * @param flows the set of flows for that device. | 91 | * @param flows the set of flows for that device. |
| 91 | */ | 92 | */ |
| 92 | protected void printFlows(Device d, List<FlowEntry> flows) { | 93 | protected void printFlows(Device d, List<FlowEntry> flows) { |
| 93 | - print("Device: " + d.id()); | 94 | + boolean empty = flows == null || flows.isEmpty(); |
| 94 | - if (flows == null | flows.isEmpty()) { | 95 | + print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size()); |
| 95 | - print(" %s", "No flows."); | 96 | + if (!empty) { |
| 96 | - return; | 97 | + for (FlowEntry f : flows) { |
| 97 | - } | 98 | + print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(), |
| 98 | - for (FlowEntry f : flows) { | 99 | + f.packets(), f.life(), f.priority()); |
| 99 | - print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(), | 100 | + print(SFMT, f.selector().criteria()); |
| 100 | - f.packets(), f.life(), f.priority()); | 101 | + print(TFMT, f.treatment().instructions()); |
| 101 | - print(SFMT, f.selector().criteria()); | 102 | + } |
| 102 | - print(TFMT, f.treatment().instructions()); | ||
| 103 | } | 103 | } |
| 104 | - | ||
| 105 | } | 104 | } |
| 106 | 105 | ||
| 107 | } | 106 | } | ... | ... |
| ... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
| 113 | @Override | 113 | @Override |
| 114 | public void run() { | 114 | public void run() { |
| 115 | if (event.reasons() == null) { | 115 | if (event.reasons() == null) { |
| 116 | - delegate.triggerCompile(null, true); | 116 | + delegate.triggerCompile(new HashSet<IntentId>(), true); |
| 117 | 117 | ||
| 118 | } else { | 118 | } else { |
| 119 | Set<IntentId> toBeRecompiled = new HashSet<>(); | 119 | Set<IntentId> toBeRecompiled = new HashSet<>(); | ... | ... |
-
Please register or login to post a comment