func CreateIcmpFlow() NetflowPayload {
	payload := new(NetflowPayload)
	payload.SrcIP = IPtoUint32("172.16.50.10")
	payload.DstIP = IPtoUint32("132.12.130.10")
	payload.NextHopIP = IPtoUint32("132.12.130.1")
	payload.SrcPort = 0
	payload.DstPort = 0
	FillCommonFields(payload, PAYLOAD_AVG_SM, 1, rand.Intn(32))
	return *payload
}
Initialize netflow record with random data
package main
import (
	"bytes"
	"encoding/binary"
	"math/rand"
	"net"
	"time"
)
var StartTime = time.Now().UnixNano()
var sysUptime uint32 = 0
var flowSequence uint32 = 0
const (
	FTP_PORT        = 21
	SSH_PORT        = 22
	DNS_PORT        = 53
	HTTP_PORT       = 80
	HTTPS_PORT      = 443
	NTP_PORT        = 123
	SNMP_PORT       = 161
	IMAPS_PORT      = 993
	MYSQL_PORT      = 3306
	HTTPS_ALT_PORT  = 8080
	P2P_PORT        = 6681
	BITTORRENT_PORT = 6682
	UINT16_MAX      = 65535
	PAYLOAD_AVG_MD  = 1024
	PAYLOAD_AVG_SM  = 256
)
type NetflowHeader struct {
	Version        uint16
	FlowCount      uint16
	SysUptime      uint32
	UnixSec        uint32
	UnixMsec       uint32
	FlowSequence   uint32
	EngineType     uint8
	EngineId       uint8
	SampleInterval uint16
}
type NetflowPayload struct {
	SrcIP          uint32
	DstIP          uint32
	NextHopIP      uint32
	SnmpInIndex    uint16
	SnmpOutIndex   uint16
	NumPackets     uint32
	NumOctets      uint32
	SysUptimeStart uint32
	SysUptimeEnd   uint32
	SrcPort        uint16
	DstPort        uint16
	Padding1       uint8
	TcpFlags       uint8
	IpProtocol     uint8
	IpTos          uint8
	SrcAsNumber    uint16
	DstAsNumber    uint16
	SrcPrefixMask  uint8
	DstPrefixMask  uint8
	Padding2       uint16
}
type Netflow struct {
	Header  NetflowHeader
	Records []NetflowPayload
}
func BuildNFlowPayload(data Netflow) bytes.Buffer {
	buffer := new(bytes.Buffer)
	err := binary.Write(buffer, binary.BigEndian, &data.Header)
	if err != nil {
		log.Println("Writing netflow header failed:", err)
	}
	for _, record := range data.Records {
		err := binary.Write(buffer, binary.BigEndian, &record)
		if err != nil {
			log.Println("Writing netflow record failed:", err)
		}
	}
	return *buffer
}
func GenerateNetflow(recordCount int) Netflow {
	data := new(Netflow)
	header := CreateNFlowHeader(recordCount)
	records := []NetflowPayload{}
	if recordCount == 8 {
		records = CreateVariablePayload(recordCount)
	} else {
		records = CreateNFlowPayload(recordCount)
	}
	data.Header = header
	data.Records = records
	return *data
}
func CreateNFlowHeader(recordCount int) NetflowHeader {
	t := time.Now().UnixNano()
	sec := t / int64(time.Second)
	nsec := t - sec*int64(time.Second)
	sysUptime = uint32((t-StartTime) / int64(time.Millisecond))+1000
	flowSequence++
	h := new(NetflowHeader)
	h.Version = 5
	h.FlowCount = uint16(recordCount)
	h.SysUptime = sysUptime
	h.UnixSec = uint32(sec)
	h.UnixMsec = uint32(nsec)
	h.FlowSequence = flowSequence
	h.EngineType = 1
	h.EngineId = 0
	h.SampleInterval = 0
	return *h
}
func CreateVariablePayload(recordCount int) []NetflowPayload {
	payload := make([]NetflowPayload, recordCount)
	for i := 0; i < recordCount; i++ {
		payload[0] = CreateHttpFlow()
		payload[1] = CreateHttpsFlow()
		payload[2] = CreateHttpAltFlow()
		payload[3] = CreateDnsFlow()
		payload[5] = CreateNtpFlow()
		payload[6] = CreateImapsFlow()
		payload[7] = CreateMySqlFlow()
	}
	return payload
}
func CreateNFlowPayload(recordCount int) []NetflowPayload {
	payload := make([]NetflowPayload, recordCount)
	for i := 0; i < recordCount; i++ {
		payload[0] = CreateHttpFlow()
		payload[1] = CreateHttpsFlow()
		payload[2] = CreateHttpAltFlow()
		payload[3] = CreateDnsFlow()
		payload[4] = CreateIcmpFlow()
		payload[5] = CreateNtpFlow()
		payload[6] = CreateImapsFlow()
		payload[7] = CreateMySqlFlow()
		payload[8] = CreateRandomFlow()
		payload[9] = CreateSshFlow()
		payload[10] = CreateP2pFlow()
		payload[11] = CreateBitorrentFlow()
		payload[12] = CreateFTPFlow()
		payload[13] = CreateSnmpFlow()
		payload[14] = CreateIcmpFlow()
		payload[15] = CreateRandomFlow()
	}
	return payload
}