Committed by
Pavlin Radoslavov
changing intent push test to also remove intents
Change-Id: Iaf90c8822d76f7bc1cb24c25613ba8e9a7934176
Showing
1 changed file
with
36 additions
and
14 deletions
| ... | @@ -67,6 +67,8 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -67,6 +67,8 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 67 | private IntentService service; | 67 | private IntentService service; |
| 68 | private CountDownLatch latch; | 68 | private CountDownLatch latch; |
| 69 | private long start, end; | 69 | private long start, end; |
| 70 | + private int count; | ||
| 71 | + private boolean add; | ||
| 70 | 72 | ||
| 71 | @Override | 73 | @Override |
| 72 | protected void execute() { | 74 | protected void execute() { |
| ... | @@ -80,14 +82,27 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -80,14 +82,27 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 80 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); | 82 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 81 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 83 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 82 | 84 | ||
| 83 | - TrafficSelector.Builder selector = DefaultTrafficSelector.builder() | 85 | + count = Integer.parseInt(countString); |
| 84 | - .matchEthType(Ethernet.TYPE_IPV4); | ||
| 85 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
| 86 | - | ||
| 87 | - int count = Integer.parseInt(countString); | ||
| 88 | 86 | ||
| 89 | service.addListener(this); | 87 | service.addListener(this); |
| 88 | + | ||
| 89 | + add = true; | ||
| 90 | latch = new CountDownLatch(count); | 90 | latch = new CountDownLatch(count); |
| 91 | + IntentOperations operations = generateIntents(ingress, egress); | ||
| 92 | + submitIntents(operations); | ||
| 93 | + | ||
| 94 | + add = false; | ||
| 95 | + latch = new CountDownLatch(count); | ||
| 96 | + operations = generateIntents(ingress, egress); | ||
| 97 | + submitIntents(operations); | ||
| 98 | + | ||
| 99 | + service.removeListener(this); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + private IntentOperations generateIntents(ConnectPoint ingress, ConnectPoint egress) { | ||
| 103 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder() | ||
| 104 | + .matchEthType(Ethernet.TYPE_IPV4); | ||
| 105 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
| 91 | 106 | ||
| 92 | IntentOperations.Builder ops = IntentOperations.builder(); | 107 | IntentOperations.Builder ops = IntentOperations.builder(); |
| 93 | for (int i = 1; i <= count; i++) { | 108 | for (int i = 1; i <= count; i++) { |
| ... | @@ -96,27 +111,33 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -96,27 +111,33 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 96 | .build(); | 111 | .build(); |
| 97 | Intent intent = new PointToPointIntent(appId(), s, treatment, | 112 | Intent intent = new PointToPointIntent(appId(), s, treatment, |
| 98 | ingress, egress); | 113 | ingress, egress); |
| 99 | - ops.addSubmitOperation(intent); | 114 | + if (add) { |
| 115 | + ops.addSubmitOperation(intent); | ||
| 116 | + } else { | ||
| 117 | + ops.addWithdrawOperation(intent.id()); | ||
| 118 | + } | ||
| 100 | } | 119 | } |
| 101 | - IntentOperations operations = ops.build(); | 120 | + return ops.build(); |
| 121 | + } | ||
| 122 | + | ||
| 123 | + private void submitIntents(IntentOperations ops) { | ||
| 102 | start = System.currentTimeMillis(); | 124 | start = System.currentTimeMillis(); |
| 103 | - service.execute(operations); | 125 | + service.execute(ops); |
| 104 | try { | 126 | try { |
| 105 | if (latch.await(10, TimeUnit.SECONDS)) { | 127 | if (latch.await(10, TimeUnit.SECONDS)) { |
| 106 | printResults(count); | 128 | printResults(count); |
| 107 | } else { | 129 | } else { |
| 108 | - print("I FAIL MISERABLY -> %d", latch.getCount()); | 130 | + print("Failure: %d intents not installed", latch.getCount()); |
| 109 | } | 131 | } |
| 110 | } catch (InterruptedException e) { | 132 | } catch (InterruptedException e) { |
| 111 | print(e.toString()); | 133 | print(e.toString()); |
| 112 | } | 134 | } |
| 113 | - | ||
| 114 | - service.removeListener(this); | ||
| 115 | } | 135 | } |
| 116 | 136 | ||
| 117 | private void printResults(int count) { | 137 | private void printResults(int count) { |
| 118 | long delta = end - start; | 138 | long delta = end - start; |
| 119 | - print("Time to install %d intents: %d ms", count, delta); | 139 | + String text = add ? "install" : "withdraw"; |
| 140 | + print("Time to %s %d intents: %d ms", text, count, delta); | ||
| 120 | } | 141 | } |
| 121 | 142 | ||
| 122 | /** | 143 | /** |
| ... | @@ -149,7 +170,8 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -149,7 +170,8 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 149 | 170 | ||
| 150 | @Override | 171 | @Override |
| 151 | public void event(IntentEvent event) { | 172 | public void event(IntentEvent event) { |
| 152 | - if (event.type() == Type.INSTALLED) { | 173 | + Type expected = add ? Type.INSTALLED : Type.WITHDRAWN; |
| 174 | + if (event.type() == expected) { | ||
| 153 | end = event.time(); | 175 | end = event.time(); |
| 154 | if (latch != null) { | 176 | if (latch != null) { |
| 155 | latch.countDown(); | 177 | latch.countDown(); |
| ... | @@ -157,7 +179,7 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -157,7 +179,7 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 157 | log.warn("install event latch is null"); | 179 | log.warn("install event latch is null"); |
| 158 | } | 180 | } |
| 159 | } else { | 181 | } else { |
| 160 | - log.info("I FAIL -> {}", event); | 182 | + log.info("Unexpected intent event: {}", event); |
| 161 | } | 183 | } |
| 162 | } | 184 | } |
| 163 | } | 185 | } | ... | ... |
-
Please register or login to post a comment