alshabib

small fix to flowid

Change-Id: I7ba950cf3fe874a094ddd3f93a8d72df0cba89c0
1 +package org.onlab.onos.cli.net;
2 +
3 +import static com.google.common.collect.Lists.newArrayList;
4 +
5 +import java.util.Collections;
6 +import java.util.Comparator;
7 +import java.util.List;
8 +import java.util.Map;
9 +
10 +import org.apache.karaf.shell.commands.Command;
11 +import org.onlab.onos.cli.AbstractShellCommand;
12 +import org.onlab.onos.net.Device;
13 +import org.onlab.onos.net.device.DeviceService;
14 +import org.onlab.onos.net.flow.FlowRule;
15 +import org.onlab.onos.net.flow.FlowRuleService;
16 +
17 +import com.google.common.collect.Maps;
18 +
19 +/**
20 + * Lists all currently-known hosts.
21 + */
22 +@Command(scope = "onos", name = "flows",
23 +description = "Lists all currently-known flows.")
24 +public class FlowsListCommand extends AbstractShellCommand {
25 +
26 + private static final String FMT =
27 + " id=%s, selector=%s, treatment=%s, state=%s";
28 +
29 + protected static final Comparator<FlowRule> ID_COMPARATOR = new Comparator<FlowRule>() {
30 + @Override
31 + public int compare(FlowRule f1, FlowRule f2) {
32 + return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
33 + }
34 + };
35 +
36 + @Override
37 + protected Object doExecute() throws Exception {
38 + DeviceService deviceService = getService(DeviceService.class);
39 + FlowRuleService service = getService(FlowRuleService.class);
40 + Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service);
41 + for (Device d : deviceService.getDevices()) {
42 + printFlows(d, flows.get(d));
43 + }
44 + return null;
45 + }
46 +
47 +
48 + /**
49 + * Returns the list of devices sorted using the device ID URIs.
50 + *
51 + * @param service device service
52 + * @return sorted device list
53 + */
54 + protected Map<Device, List<FlowRule>> getSortedFlows(DeviceService deviceService, FlowRuleService service) {
55 + Map<Device, List<FlowRule>> flows = Maps.newHashMap();
56 + List<FlowRule> rules;
57 + for (Device d : deviceService.getDevices()) {
58 + rules = newArrayList(service.getFlowEntries(d.id()));
59 + Collections.sort(rules, ID_COMPARATOR);
60 + flows.put(d, rules);
61 + }
62 + return flows;
63 + }
64 +
65 + /**
66 + * Prints flows.
67 + * @param d the device
68 + * @param flows the set of flows for that device.
69 + */
70 + protected void printFlows(Device d, List<FlowRule> flows) {
71 + print("Device: " + d.id());
72 + for (FlowRule f : flows) {
73 + print(FMT, f.id().value(), f.selector(), f.treatment(), f.state());
74 + }
75 +
76 + }
77 +
78 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -37,7 +37,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -37,7 +37,7 @@ public class DefaultFlowRule implements FlowRule {
37 37
38 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 38 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
39 TrafficTreatment treatment, int priority, FlowRuleState state, 39 TrafficTreatment treatment, int priority, FlowRuleState state,
40 - long life, long packets, long bytes, Integer flowId) { 40 + long life, long packets, long bytes, long flowId) {
41 this.deviceId = deviceId; 41 this.deviceId = deviceId;
42 this.priority = priority; 42 this.priority = priority;
43 this.selector = selector; 43 this.selector = selector;
......
...@@ -13,7 +13,7 @@ public final class FlowId { ...@@ -13,7 +13,7 @@ public final class FlowId {
13 this.flowid = id; 13 this.flowid = id;
14 } 14 }
15 15
16 - public static FlowId valueOf(int id) { 16 + public static FlowId valueOf(long id) {
17 return new FlowId(id); 17 return new FlowId(id);
18 } 18 }
19 19
......