diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2018-05-25 08:21:20 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-05-26 06:03:12 +0000 |
commit | fb10579575c4cdc9c4de330c955cc470a8ca8892 (patch) | |
tree | 0197f9209baf53fd6c971be40611ec946e9ecc1d /it/jvpp-benchmark | |
parent | 223b2a315c5976efa040307f85d7cef7662fbb8f (diff) |
jvpp-benchmark: add option to select interface mode
Changes:
- use loopback interface instead of local0,
- if L3 (default) mode is selected, assing IP to the loop0 interface,
- if L2 mode is selected, create bridge domain and assing loop0 the BD.
To test interface in L2 mode, use:
sudo java -jar ./target/jvpp-benchmark-exec.jar -p mode=L2
Change-Id: I8450d42fe0d164c6dbedf1dacf1444a25d9932b8
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
(cherry picked from commit 6e5446c9d64df7f2cbde857d276e8685c9175089)
Diffstat (limited to 'it/jvpp-benchmark')
4 files changed, 82 insertions, 11 deletions
diff --git a/it/jvpp-benchmark/asciidoc/Readme.adoc b/it/jvpp-benchmark/asciidoc/Readme.adoc index 604abf9b3..8c787d4ac 100644 --- a/it/jvpp-benchmark/asciidoc/Readme.adoc +++ b/it/jvpp-benchmark/asciidoc/Readme.adoc @@ -5,7 +5,7 @@ Provides JMH based benchmarks JVpp (Java API for VPP). == AclUpdateBenchmark Creates ACL of size aclSize using acl_add_replace, -then assigns it to local0 using acl_interface_set_acl_list. +then assigns it to loopback interface using acl_interface_set_acl_list. Then ACL is updated synchronously using acl_add_replace. By default 20x2s warmup and 100x2s measurment iterations @@ -42,6 +42,12 @@ To specify aclSetSize (default=100), use: sudo java -jar ./target/jvpp-benchmark-exec.jar -p aclSetSize=1000 --- +To test interface in bridged (L2) / routed (L3) mode (default=L3), use: +[source,shell] +--- +sudo java -jar ./target/jvpp-benchmark-exec.jar -p mode=L2 +--- + To see more options, use [source,shell] --- diff --git a/it/jvpp-benchmark/pom.xml b/it/jvpp-benchmark/pom.xml index 84cf730a5..bccf54fee 100644 --- a/it/jvpp-benchmark/pom.xml +++ b/it/jvpp-benchmark/pom.xml @@ -65,6 +65,11 @@ </dependency> <dependency> <groupId>io.fd.vpp</groupId> + <artifactId>jvpp-core</artifactId> + <version>${jvpp.version}</version> + </dependency> + <dependency> + <groupId>io.fd.vpp</groupId> <artifactId>jvpp-acl</artifactId> <version>${jvpp.version}</version> </dependency> diff --git a/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclProviderImpl.java b/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclProviderImpl.java index fea9055ea..98894fe1d 100644 --- a/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclProviderImpl.java +++ b/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclProviderImpl.java @@ -88,7 +88,7 @@ class AclProviderImpl implements AclProvider { } private static final class IpProvider { - private long ip = 0x01000000; // 1.0.0.0 + private long ip = 0x01000001; // 1.0.0.1 private static byte[] getIp(final int i) { int b1 = (i >> 24) & 0xff; diff --git a/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclUpdateBenchmark.java b/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclUpdateBenchmark.java index ef314b8e5..3ec7be953 100644 --- a/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclUpdateBenchmark.java +++ b/it/jvpp-benchmark/src/main/java/io/fd/hc2vpp/it/jvpp/benchmark/AclUpdateBenchmark.java @@ -16,15 +16,28 @@ package io.fd.hc2vpp.it.jvpp.benchmark; +import static io.fd.hc2vpp.it.jvpp.benchmark.AclUpdateBenchmark.InterfaceMode.L2; +import static io.fd.hc2vpp.it.jvpp.benchmark.AclUpdateBenchmark.InterfaceMode.L3; + import com.google.common.io.CharStreams; import io.fd.vpp.jvpp.JVppRegistryImpl; import io.fd.vpp.jvpp.acl.JVppAclImpl; import io.fd.vpp.jvpp.acl.dto.AclInterfaceSetAclList; import io.fd.vpp.jvpp.acl.future.FutureJVppAclFacade; +import io.fd.vpp.jvpp.core.JVppCoreImpl; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; +import io.fd.vpp.jvpp.core.dto.CreateLoopback; +import io.fd.vpp.jvpp.core.dto.CreateLoopbackReply; +import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; +import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlags; +import io.fd.vpp.jvpp.core.dto.SwInterfaceSetL2Bridge; +import io.fd.vpp.jvpp.core.future.FutureJVppCoreFacade; +import io.fd.vpp.jvpp.dto.JVppReply; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; @@ -63,13 +76,17 @@ public class AclUpdateBenchmark { @Param( {"100"}) private int aclSetSize; + @Param( {"L3"}) + private InterfaceMode mode; + private AclProvider aclProvider; private JVppRegistryImpl registry; - private FutureJVppAclFacade jvpp; + private FutureJVppAclFacade jvppAcl; + private FutureJVppCoreFacade jvppCore; @Benchmark public void testMethod() throws Exception { - jvpp.aclAddReplace(aclProvider.next()).toCompletableFuture().get(); + jvppAcl.aclAddReplace(aclProvider.next()).toCompletableFuture().get(); } @Setup(Level.Iteration) @@ -122,34 +139,77 @@ public class AclUpdateBenchmark { private void connect() throws IOException { LOG.info("Connecting to JVPP ..."); registry = new JVppRegistryImpl("ACLUpdateBenchmark"); - jvpp = new FutureJVppAclFacade(registry, new JVppAclImpl()); + jvppCore = new FutureJVppCoreFacade(registry, new JVppCoreImpl()); + jvppAcl = new FutureJVppAclFacade(registry, new JVppAclImpl()); LOG.info("Successfully connected to JVPP"); } private void disconnect() throws Exception { LOG.info("Disconnecting ..."); - jvpp.close(); + jvppAcl.close(); + jvppCore.close(); registry.close(); LOG.info("Successfully disconnected ..."); } /** - * Creates ACL and assigns it to local0 interface. + * Initializes loopback interface, creates ACL and assigns it to loop0. */ private void initAcl() throws ExecutionException, InterruptedException { + // Create loopback interface + final CreateLoopbackReply loop0 = invoke(jvppCore.createLoopback(new CreateLoopback())); + + // Enable loop0 + final SwInterfaceSetFlags flags = new SwInterfaceSetFlags(); + flags.adminUpDown = 1; + flags.swIfIndex = loop0.swIfIndex; + invoke(jvppCore.swInterfaceSetFlags(flags)); + + if (L3.equals(mode)) { + // Assign IP to loop0 + final SwInterfaceAddDelAddress address = new SwInterfaceAddDelAddress(); + address.address = new byte[]{1,0,0,0}; + address.addressLength = 8; + address.isAdd = 1; + address.swIfIndex = loop0.swIfIndex; + invoke(jvppCore.swInterfaceAddDelAddress(address)); + } else if (L2.equals(mode)) { + // Create bridge domain 1 + final BridgeDomainAddDel bd = new BridgeDomainAddDel(); + bd.bdId = 1; + bd.isAdd = 1; + invoke(jvppCore.bridgeDomainAddDel(bd)); + + // Assign loop0 to BD1: + final SwInterfaceSetL2Bridge loop0Bridge = new SwInterfaceSetL2Bridge(); + loop0Bridge.bdId = bd.bdId; + loop0Bridge.rxSwIfIndex = loop0.swIfIndex; + loop0Bridge.enable = 1; // set L2 mode + invoke(jvppCore.swInterfaceSetL2Bridge(loop0Bridge)); + } + // Create ACL - final int aclId = jvpp.aclAddReplace(aclProvider.next()).toCompletableFuture().get().aclIndex; + final int aclId = invoke(jvppAcl.aclAddReplace(aclProvider.next())).aclIndex; - // Assign the ACL to local0 interface + // Assign the ACL to loop0 interface final AclInterfaceSetAclList aclList = new AclInterfaceSetAclList(); - aclList.swIfIndex = 0; + aclList.swIfIndex = loop0.swIfIndex; aclList.count = 1; aclList.nInput = 1; aclList.acls = new int[] {aclId}; - jvpp.aclInterfaceSetAclList(aclList).toCompletableFuture().get(); + invoke(jvppAcl.aclInterfaceSetAclList(aclList)); // Use ACL index in subsequent executions of aclProvider.next() method aclProvider.setAclIndex(aclId); } + + public enum InterfaceMode { + L2, L3 + } + + private static <R extends JVppReply<?>> R invoke(final CompletionStage<R> completionStage) + throws ExecutionException, InterruptedException { + return completionStage.toCompletableFuture().get(); + } } |