Mercurial > stress-tester
changeset 1067:2f85c6a344c5
DpdkUnidirectionalRawPacketEmitter
author | Devel 2 |
---|---|
date | Mon, 27 Apr 2020 13:39:46 +0200 |
parents | bea08c5fe560 |
children | 4cc986525893 |
files | stress-tester/pom.xml stress-tester/src/main/java/com/passus/st/emitter/raw/DpdkUnidirectionalRawPacketEmitter.java stress-tester/src/main/java/com/passus/st/emitter/raw/DpdkUnidirectionalRawPacketWorker.java |
diffstat | 3 files changed, 89 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/pom.xml Mon Apr 27 12:36:42 2020 +0200 +++ b/stress-tester/pom.xml Mon Apr 27 13:39:46 2020 +0200 @@ -105,6 +105,12 @@ </dependency> <dependency> + <groupId>com.passus</groupId> + <artifactId>passus-dpdk</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + + <dependency> <groupId>it.unimi.dsi</groupId> <artifactId>fastutil</artifactId> <version>8.2.2</version>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/emitter/raw/DpdkUnidirectionalRawPacketEmitter.java Mon Apr 27 13:39:46 2020 +0200 @@ -0,0 +1,16 @@ +package com.passus.st.emitter.raw; + +import com.passus.dpdk.DpdkAO; + +public class DpdkUnidirectionalRawPacketEmitter extends UnidirectionalRawPacketEmitter<DpdkAO> { + + @Override + protected UnidirectionalRawPacketWorker<DpdkAO>[] createWorkersArray(int workersNum) { + return new DpdkUnidirectionalRawPacketWorker[workersNum]; + } + + @Override + protected UnidirectionalRawPacketWorker<DpdkAO> createWorker() { + return new DpdkUnidirectionalRawPacketWorker(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/emitter/raw/DpdkUnidirectionalRawPacketWorker.java Mon Apr 27 13:39:46 2020 +0200 @@ -0,0 +1,67 @@ +package com.passus.st.emitter.raw; + +import com.passus.dpdk.DpdkAO; + +import java.io.IOException; +import java.net.NetworkInterface; +import java.util.Queue; + +public class DpdkUnidirectionalRawPacketWorker extends UnidirectionalRawPacketWorker<DpdkAO> { + + private DpdkAO dpdkAO; + + private int dpdkInitCalls = 0; + + @Override + protected String resolveDevice(NetworkInterface networkInterface) throws IOException { + return null; + } + + @Override + protected DpdkAO doInitEngine(UnidirectionalRawPacketChannelContext<DpdkAO> channelContext, String device) throws IOException { + synchronized (DpdkAO.class) { + if (dpdkAO == null) { + String memPoolLib = "/root/MoonGen/libmoon/deps/dpdk/x86_64-native-linuxapp-gcc/lib/librte_mempool_ring.so"; + String[] ealArgs = {"-l", "1,2", "-n", "4", "--proc-type=auto", "-d", memPoolLib}; + String[] appArgs = {"--", "-p", "1", "--num-queues=2", "--proc-id=0"}; + + DpdkAO.initEal(ealArgs); + DpdkAO.initApp(appArgs); + dpdkAO = new DpdkAO(); + } + + dpdkInitCalls++; + } + + return dpdkAO; + } + + @Override + protected int doWrite0(UnidirectionalRawPacketChannelContext<DpdkAO> channelContext) throws IOException { + Queue<byte[]> queue = channelContext.getDataQueue(); + int written = 0; + while (!queue.isEmpty()) { + byte[] buf = queue.poll(); + int res = DpdkAO.sendPacket(buf.length, buf); + if (res >= 0) { + written += res; + } else { + throw new IOException("Unable to send packet. DPDK error."); + } + } + + return written; + } + + @Override + protected void doClose0(UnidirectionalRawPacketChannelContext<DpdkAO> channelContext) { + synchronized (DpdkAO.class) { + if (dpdkInitCalls > 0) { + dpdkInitCalls--; + if (dpdkInitCalls == 0) { + DpdkAO.cleanApp(); + } + } + } + } +} \ No newline at end of file