Brian O'Connor
Committed by Gerrit Code Review

Updates to push-intent and leaders command.

Change-Id: Id3fd7932002bf90f79a89f796ce44bab8ea74aab
...@@ -19,6 +19,7 @@ import com.google.common.collect.ArrayListMultimap; ...@@ -19,6 +19,7 @@ import com.google.common.collect.ArrayListMultimap;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import org.apache.karaf.shell.commands.Argument; 20 import org.apache.karaf.shell.commands.Argument;
21 import org.apache.karaf.shell.commands.Command; 21 import org.apache.karaf.shell.commands.Command;
22 +import org.apache.karaf.shell.commands.Option;
22 import org.onlab.onos.cli.AbstractShellCommand; 23 import org.onlab.onos.cli.AbstractShellCommand;
23 import org.onlab.onos.core.ApplicationId; 24 import org.onlab.onos.core.ApplicationId;
24 import org.onlab.onos.core.CoreService; 25 import org.onlab.onos.core.CoreService;
...@@ -75,16 +76,30 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -75,16 +76,30 @@ public class IntentPushTestCommand extends AbstractShellCommand
75 required = false, multiValued = false) 76 required = false, multiValued = false)
76 String appIds = null; 77 String appIds = null;
77 78
79 + @Argument(index = 4, name = "appIdBase",
80 + description = "Base Value for Application IDs",
81 + required = false, multiValued = false)
82 + String appIdBaseStr = null;
83 +
84 + @Option(name = "-i", aliases = "--install",
85 + description = "Install intents",
86 + required = false, multiValued = false)
87 + private boolean installOnly = false;
88 +
89 + @Option(name = "-w", aliases = "--withdraw",
90 + description = "Withdraw intents",
91 + required = false, multiValued = false)
92 + private boolean withdrawOnly = false;
78 93
79 private IntentService service; 94 private IntentService service;
80 private CountDownLatch latch; 95 private CountDownLatch latch;
81 private long start, end; 96 private long start, end;
82 private int apps; 97 private int apps;
83 private int intentsPerApp; 98 private int intentsPerApp;
99 + private int appIdBase;
84 private int count; 100 private int count;
85 private boolean add; 101 private boolean add;
86 102
87 -
88 @Override 103 @Override
89 protected void execute() { 104 protected void execute() {
90 service = get(IntentService.class); 105 service = get(IntentService.class);
...@@ -100,21 +115,30 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -100,21 +115,30 @@ public class IntentPushTestCommand extends AbstractShellCommand
100 115
101 apps = appIds != null ? Integer.parseInt(appIds) : 1; 116 apps = appIds != null ? Integer.parseInt(appIds) : 1;
102 intentsPerApp = Integer.parseInt(intentsPerAppId); 117 intentsPerApp = Integer.parseInt(intentsPerAppId);
118 + appIdBase = appIdBaseStr != null ? Integer.parseInt(appIdBaseStr) : 1;
103 119
104 count = intentsPerApp * apps; 120 count = intentsPerApp * apps;
105 121
106 -
107 service.addListener(this); 122 service.addListener(this);
108 123
109 ArrayListMultimap<Integer, Intent> operations = generateIntents(ingress, egress); 124 ArrayListMultimap<Integer, Intent> operations = generateIntents(ingress, egress);
110 125
126 + boolean both = !(installOnly ^ withdrawOnly);
127 +
128 + if (installOnly || both) {
111 add = true; 129 add = true;
112 latch = new CountDownLatch(count); 130 latch = new CountDownLatch(count);
113 submitIntents(operations); 131 submitIntents(operations);
132 + }
114 133
134 + if (withdrawOnly || both) {
135 + if (withdrawOnly && !both) {
136 + print("This should fail for now...");
137 + }
115 add = false; 138 add = false;
116 latch = new CountDownLatch(count); 139 latch = new CountDownLatch(count);
117 submitIntents(operations); 140 submitIntents(operations);
141 + }
118 142
119 service.removeListener(this); 143 service.removeListener(this);
120 } 144 }
...@@ -125,12 +149,12 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -125,12 +149,12 @@ public class IntentPushTestCommand extends AbstractShellCommand
125 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); 149 TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
126 150
127 ArrayListMultimap<Integer, Intent> intents = ArrayListMultimap.create(); 151 ArrayListMultimap<Integer, Intent> intents = ArrayListMultimap.create();
128 - for (int app = 1; app <= apps; app++) { 152 + for (int app = 0; app < apps; app++) {
129 for (int i = 1; i <= intentsPerApp; i++) { 153 for (int i = 1; i <= intentsPerApp; i++) {
130 TrafficSelector s = selector 154 TrafficSelector s = selector
131 .matchEthSrc(MacAddress.valueOf(i)) 155 .matchEthSrc(MacAddress.valueOf(i))
132 .build(); 156 .build();
133 - intents.put(app, new PointToPointIntent(appId(), s, treatment, 157 + intents.put(app, new PointToPointIntent(appId(app), s, treatment,
134 ingress, egress)); 158 ingress, egress));
135 159
136 } 160 }
...@@ -178,7 +202,8 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -178,7 +202,8 @@ public class IntentPushTestCommand extends AbstractShellCommand
178 * @return command-line application identifier 202 * @return command-line application identifier
179 */ 203 */
180 protected ApplicationId appId(Integer id) { 204 protected ApplicationId appId(Integer id) {
181 - return get(CoreService.class).registerApplication("org.onlab.onos.cli-" + id); 205 + return get(CoreService.class).registerApplication("org.onlab.onos.cli-"
206 + + (id + appIdBase));
182 } 207 }
183 208
184 /** 209 /**
......
...@@ -29,13 +29,15 @@ import java.util.Map; ...@@ -29,13 +29,15 @@ import java.util.Map;
29 description = "Finds the leader for particular topic.") 29 description = "Finds the leader for particular topic.")
30 public class LeaderCommand extends AbstractShellCommand { 30 public class LeaderCommand extends AbstractShellCommand {
31 31
32 + private static final String FMT = "%-20s: %15s";
33 +
32 @Override 34 @Override
33 protected void execute() { 35 protected void execute() {
34 LeadershipService leaderService = get(LeadershipService.class); 36 LeadershipService leaderService = get(LeadershipService.class);
35 Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard(); 37 Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard();
36 - print("Topic:\t\tLeader"); 38 + print(FMT, "Topic", "Leader");
37 for (String topic : leaderBoard.keySet()) { 39 for (String topic : leaderBoard.keySet()) {
38 - print("%s:\t%s", topic, leaderBoard.get(topic).leader().id()); 40 + print(FMT, topic, leaderBoard.get(topic).leader().id());
39 } 41 }
40 } 42 }
41 43
......