use of loghub.netflow.NetflowDecoder in project LogHub by fbacchella.
the class PacketsTest method testDecode.
@SuppressWarnings("unchecked")
@Test
public void testDecode() {
Decoder nfd = new NetflowDecoder();
IpConnectionContext dummyctx = new IpConnectionContext(new InetSocketAddress(0), new InetSocketAddress(0), null);
Arrays.stream(captures).map(i -> {
logger.debug(i + ": ");
return i;
}).map(i -> "/netflow/packets/" + i).map(i -> getClass().getResourceAsStream(i)).filter(i -> i != null).map(i -> {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8 * 1024];
for (int length; (length = i.read(buffer)) != -1; ) {
out.write(buffer, 0, length);
}
return out;
} catch (Exception e) {
Assert.fail(e.getMessage());
return null;
}
}).filter(i -> i != null).map(i -> Unpooled.wrappedBuffer(i.toByteArray())).forEach(i -> {
try {
while (i.isReadable()) {
Map<String, Object> content = nfd.decode(dummyctx, i);
Assert.assertTrue(content.containsKey("version"));
Assert.assertTrue(content.containsKey("sequenceNumber"));
Assert.assertTrue(content.containsKey("records"));
((List<Map<String, Object>>) content.get("records")).forEach(j -> Assert.assertTrue(j.containsKey("_type")));
if (((Integer) content.get("version")) < 10) {
Assert.assertTrue(content.containsKey("SysUptime"));
}
logger.debug(content);
}
} catch (Exception e) {
Assert.fail(e.getMessage());
}
});
}
Aggregations