public void testInjectTestJPacketHandler() throws SigarException {
start = ts = System.currentTimeMillis();
Sigar sig = new Sigar();
long pid = sig.getPid();
ProcMem pm = new ProcMem();
long base = 0;
final JBuffer buf =
new JBuffer(FormatUtils.toByteArray(""
+ "0007e914 78a20010 7b812445 080045c0"
+ "00280005 0000ff11 70e7c0a8 62dec0a8"
+ "65e906a5 06a50014 e04ac802 000c0002"
+ "00000002 00060000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
//
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
//
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
//
//
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
// + "00000002 00060000 00000000 00000000"
));
final PcapHeader header = new PcapHeader(buf.size(), buf.size());
PcapPacket packet = new PcapPacket(header, buf);
System.out.printf("injected packet size=%d bytes\n", buf.size());
for (int i = 0; i < COUNT; i++) {
PcapUtils.injectLoop(10000, JProtocol.ETHERNET_ID,
new PcapPacketHandler<String>() {
public void nextPacket(PcapPacket packet, String user) {
assertNotNull(packet);
count++;
b += packet.size();
h += packet.getState().getHeaderCount();
}
}, "", packet);
/*
* Skip 1 iteration to allow all the files to be opened and any allocated
* resources to end up as a memory base.
*/
if (i == 0) {
base = pm.getSize();
}
if (i % (COUNT / 10) == 0 && i != 0) {
te = System.currentTimeMillis();
total += count;
bytes += b;
headers += h;
double delta = ((double) te - (double) ts) / 1000.;
pm.gather(sig, pid);
System.out.printf(
"tot=%.1f packets=%d pps=%.0f bytes=%.0fKb/s hdr=%.0f/s "
+ "hdr=%.0fus rm=%dKb pm=%.1fb vm=%dKb\n",
((double) total) / 1024 / 1024, count, ((double) count / delta),
((double) b / delta / 1024.), ((double) h / delta),
1000000. / ((double) h / delta), pm.getResident() / (1024),
((double) pm.getResident() - base) / count, pm.getSize() / (1024));
System.out.flush();
ts = te;
count = 0;
b = 0;