Fixing IntentPushTestCommand
Change-Id: Ia6cc2f4be2e8087a903e660067626c5225f20216
Showing
1 changed file
with
30 additions
and
65 deletions
... | @@ -15,14 +15,13 @@ | ... | @@ -15,14 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cli.net; | 16 | package org.onosproject.cli.net; |
17 | 17 | ||
18 | -import com.google.common.collect.ArrayListMultimap; | 18 | +import com.google.common.collect.Lists; |
19 | - | ||
20 | import org.apache.karaf.shell.commands.Argument; | 19 | import org.apache.karaf.shell.commands.Argument; |
21 | import org.apache.karaf.shell.commands.Command; | 20 | import org.apache.karaf.shell.commands.Command; |
22 | import org.apache.karaf.shell.commands.Option; | 21 | import org.apache.karaf.shell.commands.Option; |
22 | +import org.onlab.packet.Ethernet; | ||
23 | +import org.onlab.packet.MacAddress; | ||
23 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
24 | -import org.onosproject.core.ApplicationId; | ||
25 | -import org.onosproject.core.CoreService; | ||
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
27 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
28 | import org.onosproject.net.PortNumber; | 27 | import org.onosproject.net.PortNumber; |
... | @@ -35,13 +34,12 @@ import org.onosproject.net.intent.IntentEvent; | ... | @@ -35,13 +34,12 @@ import org.onosproject.net.intent.IntentEvent; |
35 | import org.onosproject.net.intent.IntentEvent.Type; | 34 | import org.onosproject.net.intent.IntentEvent.Type; |
36 | import org.onosproject.net.intent.IntentListener; | 35 | import org.onosproject.net.intent.IntentListener; |
37 | import org.onosproject.net.intent.IntentService; | 36 | import org.onosproject.net.intent.IntentService; |
37 | +import org.onosproject.net.intent.Key; | ||
38 | import org.onosproject.net.intent.PointToPointIntent; | 38 | import org.onosproject.net.intent.PointToPointIntent; |
39 | -import org.onlab.packet.Ethernet; | ||
40 | -import org.onlab.packet.MacAddress; | ||
41 | 39 | ||
40 | +import java.util.Collections; | ||
42 | import java.util.EnumSet; | 41 | import java.util.EnumSet; |
43 | -import java.util.HashSet; | 42 | +import java.util.List; |
44 | -import java.util.Set; | ||
45 | import java.util.concurrent.CountDownLatch; | 43 | import java.util.concurrent.CountDownLatch; |
46 | import java.util.concurrent.TimeUnit; | 44 | import java.util.concurrent.TimeUnit; |
47 | 45 | ||
... | @@ -66,21 +64,15 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -66,21 +64,15 @@ public class IntentPushTestCommand extends AbstractShellCommand |
66 | required = true, multiValued = false) | 64 | required = true, multiValued = false) |
67 | String egressDeviceString = null; | 65 | String egressDeviceString = null; |
68 | 66 | ||
69 | - | 67 | + @Argument(index = 2, name = "numberOfIntents", |
70 | - @Argument(index = 2, name = "IntentsPerAppId", | 68 | + description = "Number of intents to install/withdraw", |
71 | - description = "Number of intents per appId", | ||
72 | required = true, multiValued = false) | 69 | required = true, multiValued = false) |
73 | - String intentsPerAppId = null; | 70 | + String numberOfIntents = null; |
74 | 71 | ||
75 | - @Argument(index = 3, name = "apps", | 72 | + @Argument(index = 3, name = "keyOffset", |
76 | - description = "Number of appIds", | 73 | + description = "Starting point for first key (default: 1)", |
77 | required = false, multiValued = false) | 74 | required = false, multiValued = false) |
78 | - String appIds = null; | 75 | + String keyOffsetStr = null; |
79 | - | ||
80 | - @Argument(index = 4, name = "appIdBase", | ||
81 | - description = "Base Value for Application IDs", | ||
82 | - required = false, multiValued = false) | ||
83 | - String appIdBaseStr = null; | ||
84 | 76 | ||
85 | @Option(name = "-i", aliases = "--install", | 77 | @Option(name = "-i", aliases = "--install", |
86 | description = "Install intents", | 78 | description = "Install intents", |
... | @@ -95,12 +87,9 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -95,12 +87,9 @@ public class IntentPushTestCommand extends AbstractShellCommand |
95 | private IntentService service; | 87 | private IntentService service; |
96 | private CountDownLatch latch; | 88 | private CountDownLatch latch; |
97 | private volatile long start, end; | 89 | private volatile long start, end; |
98 | - private int apps; | ||
99 | - private int intentsPerApp; | ||
100 | - private int appIdBase; | ||
101 | private int count; | 90 | private int count; |
91 | + private int keyOffset; | ||
102 | private boolean add; | 92 | private boolean add; |
103 | - private final Set<ApplicationId> myAppIds = new HashSet<>(); | ||
104 | 93 | ||
105 | @Override | 94 | @Override |
106 | protected void execute() { | 95 | protected void execute() { |
... | @@ -115,66 +104,57 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -115,66 +104,57 @@ public class IntentPushTestCommand extends AbstractShellCommand |
115 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); | 104 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
116 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 105 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
117 | 106 | ||
118 | - apps = appIds != null ? Integer.parseInt(appIds) : 1; | 107 | + count = Integer.parseInt(numberOfIntents); |
119 | - intentsPerApp = Integer.parseInt(intentsPerAppId); | 108 | + keyOffset = (keyOffsetStr != null) ? Integer.parseInt(keyOffsetStr) : 1; |
120 | - appIdBase = appIdBaseStr != null ? Integer.parseInt(appIdBaseStr) : 1; | ||
121 | - | ||
122 | - count = intentsPerApp * apps; | ||
123 | 109 | ||
124 | service.addListener(this); | 110 | service.addListener(this); |
125 | 111 | ||
126 | - ArrayListMultimap<Integer, Intent> operations = generateIntents(ingress, egress); | 112 | + List<Intent> operations = generateIntents(ingress, egress); |
127 | 113 | ||
128 | boolean both = !(installOnly ^ withdrawOnly); | 114 | boolean both = !(installOnly ^ withdrawOnly); |
129 | 115 | ||
130 | if (installOnly || both) { | 116 | if (installOnly || both) { |
131 | add = true; | 117 | add = true; |
132 | - latch = new CountDownLatch(count); | ||
133 | submitIntents(operations); | 118 | submitIntents(operations); |
134 | } | 119 | } |
135 | 120 | ||
136 | if (withdrawOnly || both) { | 121 | if (withdrawOnly || both) { |
137 | - if (withdrawOnly && !both) { | ||
138 | - print("This should fail for now..."); | ||
139 | - } | ||
140 | add = false; | 122 | add = false; |
141 | - latch = new CountDownLatch(count); | ||
142 | submitIntents(operations); | 123 | submitIntents(operations); |
143 | } | 124 | } |
144 | 125 | ||
145 | service.removeListener(this); | 126 | service.removeListener(this); |
146 | } | 127 | } |
147 | 128 | ||
148 | - private ArrayListMultimap<Integer, Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) { | 129 | + private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) { |
149 | - TrafficSelector.Builder selector = DefaultTrafficSelector.builder() | 130 | + TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder() |
150 | .matchEthType(Ethernet.TYPE_IPV4); | 131 | .matchEthType(Ethernet.TYPE_IPV4); |
151 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 132 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
152 | 133 | ||
153 | - ArrayListMultimap<Integer, Intent> intents = ArrayListMultimap.create(); | 134 | + List<Intent> intents = Lists.newArrayList(); |
154 | - for (int app = 0; app < apps; app++) { | 135 | + for (int i = 0; i < count; i++) { |
155 | - for (int i = 1; i <= intentsPerApp; i++) { | 136 | + TrafficSelector selector = selectorBldr |
156 | - TrafficSelector s = selector | 137 | + .matchEthSrc(MacAddress.valueOf(i + keyOffset)) |
157 | - .matchEthSrc(MacAddress.valueOf(i + (app + appIdBase) * intentsPerApp)) | ||
158 | .build(); | 138 | .build(); |
159 | - intents.put(app, new PointToPointIntent(appId(app), s, treatment, | 139 | + intents.add(new PointToPointIntent(appId(), Key.of(i + keyOffset, appId()), |
160 | - ingress, egress)); | 140 | + selector, treatment, |
141 | + ingress, egress, | ||
142 | + Collections.emptyList())); | ||
161 | 143 | ||
162 | } | 144 | } |
163 | - } | ||
164 | return intents; | 145 | return intents; |
165 | } | 146 | } |
166 | 147 | ||
167 | - private void submitIntents(ArrayListMultimap<Integer, Intent> intents) { | 148 | + private void submitIntents(List<Intent> intents) { |
149 | + latch = new CountDownLatch(count); | ||
168 | start = System.currentTimeMillis(); | 150 | start = System.currentTimeMillis(); |
169 | - for (Integer app : intents.keySet()) { | 151 | + for (Intent intent : intents) { |
170 | - for (Intent intent : intents.get(app)) { | ||
171 | if (add) { | 152 | if (add) { |
172 | service.submit(intent); | 153 | service.submit(intent); |
173 | } else { | 154 | } else { |
174 | service.withdraw(intent); | 155 | service.withdraw(intent); |
175 | } | 156 | } |
176 | } | 157 | } |
177 | - } | ||
178 | 158 | ||
179 | try { | 159 | try { |
180 | if (latch.await(100 + count * 200, TimeUnit.MILLISECONDS)) { | 160 | if (latch.await(100 + count * 200, TimeUnit.MILLISECONDS)) { |
... | @@ -193,21 +173,6 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -193,21 +173,6 @@ public class IntentPushTestCommand extends AbstractShellCommand |
193 | print("Time to %s %d intents: %d ms", text, count, delta); | 173 | print("Time to %s %d intents: %d ms", text, count, delta); |
194 | } | 174 | } |
195 | 175 | ||
196 | - | ||
197 | - /** | ||
198 | - * Returns application ID for the CLI. | ||
199 | - * | ||
200 | - * @param id application id | ||
201 | - * @return command-line application identifier | ||
202 | - */ | ||
203 | - protected ApplicationId appId(Integer id) { | ||
204 | - ApplicationId appId = get(CoreService.class) | ||
205 | - .registerApplication("org.onosproject.cli-" | ||
206 | - + (id + appIdBase)); | ||
207 | - myAppIds.add(appId); | ||
208 | - return appId; | ||
209 | - } | ||
210 | - | ||
211 | /** | 176 | /** |
212 | * Extracts the port number portion of the ConnectPoint. | 177 | * Extracts the port number portion of the ConnectPoint. |
213 | * | 178 | * |
... | @@ -240,7 +205,7 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -240,7 +205,7 @@ public class IntentPushTestCommand extends AbstractShellCommand |
240 | = EnumSet.of(Type.INSTALL_REQ, Type.WITHDRAW_REQ); | 205 | = EnumSet.of(Type.INSTALL_REQ, Type.WITHDRAW_REQ); |
241 | @Override | 206 | @Override |
242 | public synchronized void event(IntentEvent event) { | 207 | public synchronized void event(IntentEvent event) { |
243 | - if (!myAppIds.contains(event.subject().appId())) { | 208 | + if (!appId().equals(event.subject().appId())) { |
244 | // not my event, ignore | 209 | // not my event, ignore |
245 | return; | 210 | return; |
246 | } | 211 | } | ... | ... |
-
Please register or login to post a comment