Showing
2 changed files
with
147 additions
and
0 deletions
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import java.util.concurrent.CountDownLatch; | ||
4 | +import java.util.concurrent.TimeUnit; | ||
5 | + | ||
6 | +import org.apache.karaf.shell.commands.Argument; | ||
7 | +import org.apache.karaf.shell.commands.Command; | ||
8 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
9 | +import org.onlab.onos.net.ConnectPoint; | ||
10 | +import org.onlab.onos.net.DeviceId; | ||
11 | +import org.onlab.onos.net.PortNumber; | ||
12 | +import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
13 | +import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ||
14 | +import org.onlab.onos.net.flow.TrafficSelector; | ||
15 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
16 | +import org.onlab.onos.net.intent.Intent; | ||
17 | +import org.onlab.onos.net.intent.IntentEvent; | ||
18 | +import org.onlab.onos.net.intent.IntentEvent.Type; | ||
19 | +import org.onlab.onos.net.intent.IntentId; | ||
20 | +import org.onlab.onos.net.intent.IntentListener; | ||
21 | +import org.onlab.onos.net.intent.IntentService; | ||
22 | +import org.onlab.onos.net.intent.PointToPointIntent; | ||
23 | +import org.onlab.packet.Ethernet; | ||
24 | +import org.onlab.packet.MacAddress; | ||
25 | + | ||
26 | +/** | ||
27 | + * Installs point-to-point connectivity intents. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "push-test-intents", | ||
30 | + description = "Installs random intents to test throughput") | ||
31 | +public class IntentPushTestCommand extends AbstractShellCommand | ||
32 | + implements IntentListener { | ||
33 | + | ||
34 | + @Argument(index = 0, name = "ingressDevice", | ||
35 | + description = "Ingress Device/Port Description", | ||
36 | + required = true, multiValued = false) | ||
37 | + String ingressDeviceString = null; | ||
38 | + | ||
39 | + @Argument(index = 1, name = "egressDevice", | ||
40 | + description = "Egress Device/Port Description", | ||
41 | + required = true, multiValued = false) | ||
42 | + String egressDeviceString = null; | ||
43 | + | ||
44 | + @Argument(index = 2, name = "count", | ||
45 | + description = "Number of intents to push", | ||
46 | + required = true, multiValued = false) | ||
47 | + String countString = null; | ||
48 | + | ||
49 | + | ||
50 | + private static long id = 0x7870001; | ||
51 | + | ||
52 | + private IntentService service; | ||
53 | + private CountDownLatch latch; | ||
54 | + private long start, end; | ||
55 | + | ||
56 | + @Override | ||
57 | + protected void execute() { | ||
58 | + service = get(IntentService.class); | ||
59 | + | ||
60 | + DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); | ||
61 | + PortNumber ingressPortNumber = | ||
62 | + PortNumber.portNumber(getPortNumber(ingressDeviceString)); | ||
63 | + ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); | ||
64 | + | ||
65 | + DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); | ||
66 | + PortNumber egressPortNumber = | ||
67 | + PortNumber.portNumber(getPortNumber(egressDeviceString)); | ||
68 | + ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | ||
69 | + | ||
70 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder() | ||
71 | + .matchEthType(Ethernet.TYPE_IPV4); | ||
72 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
73 | + | ||
74 | + int count = Integer.parseInt(countString); | ||
75 | + | ||
76 | + service.addListener(this); | ||
77 | + start = System.currentTimeMillis(); | ||
78 | + for (int i = 0; i < count; i++) { | ||
79 | + TrafficSelector s = selector | ||
80 | + .matchEthSrc(MacAddress.valueOf(i)) | ||
81 | + .build(); | ||
82 | + Intent intent = | ||
83 | + new PointToPointIntent(new IntentId(id++), | ||
84 | + s, | ||
85 | + treatment, | ||
86 | + ingress, | ||
87 | + egress); | ||
88 | + service.submit(intent); | ||
89 | + } | ||
90 | + latch = new CountDownLatch(count); | ||
91 | + try { | ||
92 | + latch.await(3, TimeUnit.SECONDS); | ||
93 | + printResults(count); | ||
94 | + } catch (InterruptedException e) { | ||
95 | + print(e.toString()); | ||
96 | + } | ||
97 | + service.removeListener(this); | ||
98 | + } | ||
99 | + | ||
100 | + private void printResults(int count) { | ||
101 | + long delta = end - start; | ||
102 | + print("Time to install %d intents: %d ms", count, delta); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Extracts the port number portion of the ConnectPoint. | ||
107 | + * | ||
108 | + * @param deviceString string representing the device/port | ||
109 | + * @return port number as a string, empty string if the port is not found | ||
110 | + */ | ||
111 | + private String getPortNumber(String deviceString) { | ||
112 | + int slash = deviceString.indexOf('/'); | ||
113 | + if (slash <= 0) { | ||
114 | + return ""; | ||
115 | + } | ||
116 | + return deviceString.substring(slash + 1, deviceString.length()); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * Extracts the device ID portion of the ConnectPoint. | ||
121 | + * | ||
122 | + * @param deviceString string representing the device/port | ||
123 | + * @return device ID string | ||
124 | + */ | ||
125 | + private String getDeviceId(String deviceString) { | ||
126 | + int slash = deviceString.indexOf('/'); | ||
127 | + if (slash <= 0) { | ||
128 | + return ""; | ||
129 | + } | ||
130 | + return deviceString.substring(0, slash); | ||
131 | + } | ||
132 | + | ||
133 | + @Override | ||
134 | + public void event(IntentEvent event) { | ||
135 | + if (event.type() == Type.INSTALLED) { | ||
136 | + end = event.time(); | ||
137 | + latch.countDown(); | ||
138 | + } | ||
139 | + } | ||
140 | +} |
... | @@ -82,6 +82,13 @@ | ... | @@ -82,6 +82,13 @@ |
82 | <ref component-id="connectPointCompleter"/> | 82 | <ref component-id="connectPointCompleter"/> |
83 | </completers> | 83 | </completers> |
84 | </command> | 84 | </command> |
85 | + <command> | ||
86 | + <action class="org.onlab.onos.cli.net.IntentPushTestCommand"/> | ||
87 | + <completers> | ||
88 | + <ref component-id="connectPointCompleter"/> | ||
89 | + <ref component-id="connectPointCompleter"/> | ||
90 | + </completers> | ||
91 | + </command> | ||
85 | 92 | ||
86 | <command> | 93 | <command> |
87 | <action class="org.onlab.onos.cli.net.ClustersListCommand"/> | 94 | <action class="org.onlab.onos.cli.net.ClustersListCommand"/> | ... | ... |
-
Please register or login to post a comment