Added output of appId to the flow list command. Fixed defect in CoreManager - we…
… forgot to put registered ids in our map.
Showing
5 changed files
with
43 additions
and
32 deletions
1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
2 | 2 | ||
3 | -import static com.google.common.collect.Lists.newArrayList; | 3 | +import com.google.common.collect.Maps; |
4 | -import static org.onlab.onos.cli.net.DevicesListCommand.getSortedDevices; | ||
5 | - | ||
6 | -import java.util.Collections; | ||
7 | -import java.util.List; | ||
8 | -import java.util.Map; | ||
9 | - | ||
10 | import org.apache.karaf.shell.commands.Argument; | 4 | import org.apache.karaf.shell.commands.Argument; |
11 | import org.apache.karaf.shell.commands.Command; | 5 | import org.apache.karaf.shell.commands.Command; |
6 | +import org.onlab.onos.CoreService; | ||
12 | import org.onlab.onos.cli.AbstractShellCommand; | 7 | import org.onlab.onos.cli.AbstractShellCommand; |
13 | import org.onlab.onos.cli.Comparators; | 8 | import org.onlab.onos.cli.Comparators; |
14 | import org.onlab.onos.net.Device; | 9 | import org.onlab.onos.net.Device; |
... | @@ -18,19 +13,24 @@ import org.onlab.onos.net.flow.FlowEntry; | ... | @@ -18,19 +13,24 @@ import org.onlab.onos.net.flow.FlowEntry; |
18 | import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; | 13 | import org.onlab.onos.net.flow.FlowEntry.FlowEntryState; |
19 | import org.onlab.onos.net.flow.FlowRuleService; | 14 | import org.onlab.onos.net.flow.FlowRuleService; |
20 | 15 | ||
21 | -import com.google.common.collect.Maps; | 16 | +import java.util.Collections; |
17 | +import java.util.List; | ||
18 | +import java.util.Map; | ||
19 | + | ||
20 | +import static com.google.common.collect.Lists.newArrayList; | ||
21 | +import static org.onlab.onos.cli.net.DevicesListCommand.getSortedDevices; | ||
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Lists all currently-known hosts. | 24 | * Lists all currently-known hosts. |
25 | */ | 25 | */ |
26 | @Command(scope = "onos", name = "flows", | 26 | @Command(scope = "onos", name = "flows", |
27 | -description = "Lists all currently-known flows.") | 27 | + description = "Lists all currently-known flows.") |
28 | public class FlowsListCommand extends AbstractShellCommand { | 28 | public class FlowsListCommand extends AbstractShellCommand { |
29 | 29 | ||
30 | public static final String ANY = "any"; | 30 | public static final String ANY = "any"; |
31 | 31 | ||
32 | private static final String FMT = | 32 | private static final String FMT = |
33 | - " id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s"; | 33 | + " id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s, appId=%s"; |
34 | private static final String TFMT = " treatment=%s"; | 34 | private static final String TFMT = " treatment=%s"; |
35 | private static final String SFMT = " selector=%s"; | 35 | private static final String SFMT = " selector=%s"; |
36 | 36 | ||
... | @@ -44,11 +44,12 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -44,11 +44,12 @@ public class FlowsListCommand extends AbstractShellCommand { |
44 | 44 | ||
45 | @Override | 45 | @Override |
46 | protected void execute() { | 46 | protected void execute() { |
47 | + CoreService coreService = get(CoreService.class); | ||
47 | DeviceService deviceService = get(DeviceService.class); | 48 | DeviceService deviceService = get(DeviceService.class); |
48 | FlowRuleService service = get(FlowRuleService.class); | 49 | FlowRuleService service = get(FlowRuleService.class); |
49 | Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); | 50 | Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); |
50 | for (Device d : getSortedDevices(deviceService)) { | 51 | for (Device d : getSortedDevices(deviceService)) { |
51 | - printFlows(d, flows.get(d)); | 52 | + printFlows(d, flows.get(d), coreService); |
52 | } | 53 | } |
53 | } | 54 | } |
54 | 55 | ||
... | @@ -87,16 +88,19 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -87,16 +88,19 @@ public class FlowsListCommand extends AbstractShellCommand { |
87 | 88 | ||
88 | /** | 89 | /** |
89 | * Prints flows. | 90 | * Prints flows. |
91 | + * | ||
90 | * @param d the device | 92 | * @param d the device |
91 | * @param flows the set of flows for that device. | 93 | * @param flows the set of flows for that device. |
92 | */ | 94 | */ |
93 | - protected void printFlows(Device d, List<FlowEntry> flows) { | 95 | + protected void printFlows(Device d, List<FlowEntry> flows, |
96 | + CoreService coreService) { | ||
94 | boolean empty = flows == null || flows.isEmpty(); | 97 | boolean empty = flows == null || flows.isEmpty(); |
95 | print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size()); | 98 | print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size()); |
96 | if (!empty) { | 99 | if (!empty) { |
97 | for (FlowEntry f : flows) { | 100 | for (FlowEntry f : flows) { |
98 | - print(FMT, Long.toHexString(f.id().value()), f.state(), f.bytes(), | 101 | + print(FMT, Long.toHexString(f.id().value()), f.state(), |
99 | - f.packets(), f.life(), f.priority()); | 102 | + f.bytes(), f.packets(), f.life(), f.priority(), |
103 | + coreService.getAppId(f.appId()).name()); | ||
100 | print(SFMT, f.selector().criteria()); | 104 | print(SFMT, f.selector().criteria()); |
101 | print(TFMT, f.treatment().instructions()); | 105 | print(TFMT, f.treatment().instructions()); |
102 | } | 106 | } | ... | ... |
1 | package org.onlab.onos.impl; | 1 | package org.onlab.onos.impl; |
2 | 2 | ||
3 | -import java.io.File; | ||
4 | -import java.util.List; | ||
5 | -import java.util.Map; | ||
6 | -import java.util.concurrent.ConcurrentHashMap; | ||
7 | -import java.util.concurrent.atomic.AtomicInteger; | ||
8 | - | ||
9 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
10 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
11 | import org.apache.felix.scr.annotations.Service; | 5 | import org.apache.felix.scr.annotations.Service; |
... | @@ -14,6 +8,11 @@ import org.onlab.onos.CoreService; | ... | @@ -14,6 +8,11 @@ import org.onlab.onos.CoreService; |
14 | import org.onlab.onos.Version; | 8 | import org.onlab.onos.Version; |
15 | import org.onlab.util.Tools; | 9 | import org.onlab.util.Tools; |
16 | 10 | ||
11 | +import java.io.File; | ||
12 | +import java.util.List; | ||
13 | +import java.util.Map; | ||
14 | +import java.util.concurrent.ConcurrentHashMap; | ||
15 | +import java.util.concurrent.atomic.AtomicInteger; | ||
17 | 16 | ||
18 | /** | 17 | /** |
19 | * Core service implementation. | 18 | * Core service implementation. |
... | @@ -23,10 +22,11 @@ import org.onlab.util.Tools; | ... | @@ -23,10 +22,11 @@ import org.onlab.util.Tools; |
23 | public class CoreManager implements CoreService { | 22 | public class CoreManager implements CoreService { |
24 | 23 | ||
25 | private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1); | 24 | private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1); |
25 | + | ||
26 | private static final File VERSION_FILE = new File("../VERSION"); | 26 | private static final File VERSION_FILE = new File("../VERSION"); |
27 | private static Version version = Version.version("1.0.0-SNAPSHOT"); | 27 | private static Version version = Version.version("1.0.0-SNAPSHOT"); |
28 | 28 | ||
29 | - private final Map<Short, DefaultApplicationId> ids = new ConcurrentHashMap<>(); | 29 | + private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); |
30 | 30 | ||
31 | // TODO: work in progress | 31 | // TODO: work in progress |
32 | 32 | ||
... | @@ -45,12 +45,15 @@ public class CoreManager implements CoreService { | ... | @@ -45,12 +45,15 @@ public class CoreManager implements CoreService { |
45 | 45 | ||
46 | @Override | 46 | @Override |
47 | public ApplicationId getAppId(Short id) { | 47 | public ApplicationId getAppId(Short id) { |
48 | - return ids.get(id); | 48 | + return appIds.get(id); |
49 | } | 49 | } |
50 | 50 | ||
51 | @Override | 51 | @Override |
52 | public ApplicationId registerApplication(String name) { | 52 | public ApplicationId registerApplication(String name) { |
53 | - return new DefaultApplicationId((short) ID_DISPENSER.getAndIncrement(), name); | 53 | + short id = (short) ID_DISPENSER.getAndIncrement(); |
54 | + DefaultApplicationId appId = new DefaultApplicationId(id, name); | ||
55 | + appIds.put(id, appId); | ||
56 | + return appId; | ||
54 | } | 57 | } |
55 | 58 | ||
56 | } | 59 | } | ... | ... |
1 | package org.onlab.onos.impl; | 1 | package org.onlab.onos.impl; |
2 | 2 | ||
3 | +import org.onlab.onos.ApplicationId; | ||
4 | + | ||
3 | import java.util.Objects; | 5 | import java.util.Objects; |
4 | 6 | ||
5 | -import org.onlab.onos.ApplicationId; | 7 | +import static com.google.common.base.MoreObjects.toStringHelper; |
6 | 8 | ||
7 | /** | 9 | /** |
8 | * Application id generator class. | 10 | * Application id generator class. |
9 | */ | 11 | */ |
10 | public class DefaultApplicationId implements ApplicationId { | 12 | public class DefaultApplicationId implements ApplicationId { |
11 | 13 | ||
12 | - | ||
13 | private final short id; | 14 | private final short id; |
14 | private final String name; | 15 | private final String name; |
15 | 16 | ||
16 | - | ||
17 | // Ban public construction | 17 | // Ban public construction |
18 | protected DefaultApplicationId(Short id, String identifier) { | 18 | protected DefaultApplicationId(Short id, String identifier) { |
19 | this.id = id; | 19 | this.id = id; |
... | @@ -40,13 +40,16 @@ public class DefaultApplicationId implements ApplicationId { | ... | @@ -40,13 +40,16 @@ public class DefaultApplicationId implements ApplicationId { |
40 | if (this == obj) { | 40 | if (this == obj) { |
41 | return true; | 41 | return true; |
42 | } | 42 | } |
43 | - if (obj == null) { | 43 | + if (obj instanceof DefaultApplicationId) { |
44 | - return false; | 44 | + DefaultApplicationId other = (DefaultApplicationId) obj; |
45 | + return Objects.equals(this.id, other.id); | ||
45 | } | 46 | } |
46 | - if (!(obj instanceof DefaultApplicationId)) { | ||
47 | return false; | 47 | return false; |
48 | } | 48 | } |
49 | - DefaultApplicationId other = (DefaultApplicationId) obj; | 49 | + |
50 | - return Objects.equals(this.id, other.id); | 50 | + @Override |
51 | + public String toString() { | ||
52 | + return toStringHelper(this).add("id", id).add("name", name).toString(); | ||
51 | } | 53 | } |
54 | + | ||
52 | } | 55 | } | ... | ... |
... | @@ -33,6 +33,7 @@ alias obs='onos-build-selective' | ... | @@ -33,6 +33,7 @@ alias obs='onos-build-selective' |
33 | alias op='onos-package' | 33 | alias op='onos-package' |
34 | alias ot='onos-test' | 34 | alias ot='onos-test' |
35 | alias ol='onos-log' | 35 | alias ol='onos-log' |
36 | +alias ow='onos-watch' | ||
36 | alias go='ob && ot && onos -w' | 37 | alias go='ob && ot && onos -w' |
37 | alias pub='onos-push-update-bundle' | 38 | alias pub='onos-push-update-bundle' |
38 | 39 | ... | ... |
... | @@ -11,7 +11,7 @@ node=${1:-$OCI} | ... | @@ -11,7 +11,7 @@ node=${1:-$OCI} |
11 | commands="${2:-summary,intents,flows,hosts}" | 11 | commands="${2:-summary,intents,flows,hosts}" |
12 | 12 | ||
13 | aux=/tmp/onos-watch.$$ | 13 | aux=/tmp/onos-watch.$$ |
14 | -trap "rm -f $aux'" EXIT | 14 | +trap "rm -f $aux" EXIT |
15 | 15 | ||
16 | echo "$commands" | tr ',' '\n' > $aux | 16 | echo "$commands" | tr ',' '\n' > $aux |
17 | watch $3 "onos $node -b <$aux 2>/dev/null" | 17 | watch $3 "onos $node -b <$aux 2>/dev/null" | ... | ... |
-
Please register or login to post a comment