org.graylog.plugins.netflow.v9.RawNetFlowV9Packet Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog.plugins.netflow.v9;
import com.google.auto.value.AutoValue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
@AutoValue
public abstract class RawNetFlowV9Packet {
public abstract NetFlowV9Header header();
public abstract int dataLength();
public abstract Map templates();
@Nullable
public abstract Map.Entry optionTemplate();
public abstract Set usedTemplates();
public static RawNetFlowV9Packet create(NetFlowV9Header header, int dataLength, Map templates, @Nullable Map.Entry optTemplate, Set usedTemplates) {
return new AutoValue_RawNetFlowV9Packet(header, dataLength, templates, optTemplate, usedTemplates);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("\n");
sb.append(header().prettyHexDump()).append("\n");
sb.append("\nTemplates:\n");
templates().forEach((integer, byteBuf) -> {
sb.append("\n").append(integer).append(":\n").append(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(byteBuf)));
});
final Map.Entry optionTemplate = optionTemplate();
if (optionTemplate != null) {
sb.append("\nOption Template:\n").append(ByteBufUtil.prettyHexDump(Unpooled.wrappedBuffer(optionTemplate.getValue())));
}
sb.append("\nData flows using these templates:\n");
usedTemplates().forEach(templateId -> sb.append(templateId).append(" "));
return sb.toString();
}
}