Skip to content

Commit 9ad57bb

Browse files
committed
init manflow
1 parent b7cd119 commit 9ad57bb

21 files changed

+1684
-722
lines changed

.github/workflows/image-build.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ _testmain.go
3232

3333
# Project binary
3434
nflow-generator
35+
manflow

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ WORKDIR /src
44
RUN go build -v .
55

66
FROM alpine:latest
7-
MAINTAINER Brent Salisbury <[email protected]>
87

9-
COPY --from=build /src/nflow-generator /usr/local/bin/
10-
ENTRYPOINT ["/usr/local/bin/nflow-generator"]
8+
WORKDIR /app
9+
10+
COPY --from=build /src/manflow /usr/local/bin/
11+
ENTRYPOINT ["/usr/local/bin/manflow"]

README.md

Lines changed: 34 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,45 @@
1-
# Usage - nflow-generator
1+
# manflow
22

3-
[![nflow-generator image CI](https://github.com/nerdalert/nflow-generator/actions/workflows/image-build.yml/badge.svg)](https://github.com/nerdalert/nflow-generator/actions/workflows/image-build.yml)
3+
Netflow generator
44

5-
This program generates mock netflow (v5) data that can be used to test netflow collector programs.
6-
The program simulates a router that is exporting flow records to the collector.
7-
It is useful for determining whether the netflow collector is operating and/or receiving netflow datagrams.
5+
Documentation: https://aviatrix.atlassian.net/wiki/spaces/copconf/pages/1913815177/manflow+netflow+generator
86

9-
nflow-generator generates several netflow datagrams per second, each with 8 or 16 records for varying kinds of traffic (HTTP, SSH, SNMP, DNS, MySQL, and many others.)
7+
## Usage
108

11-
### Docker Image Run (Easiest)
9+
Using following `flowConfig.json` file:
1210

13-
Simply run in a container and pass any arguments at runtime. Below is an example passing the `--help` flag:
14-
15-
```
16-
docker run -it --rm networkstatic/nflow-generator --help
17-
# or podman/quay repos
18-
podman run -it --rm /quay.io/networkstatic/nflow-generator --help
19-
```
20-
21-
To generate mock flow data simply add the target IP and port:
22-
23-
```
24-
docker run -it --rm networkstatic/nflow-generator -t <ip> -p <port>
25-
# or podman/quay repos
26-
podman run -it --rm /quay.io/networkstatic/nflow-generator -t <ip> -p <port>
11+
```json
12+
{
13+
"seed": 1,
14+
"flow_timeout": 10,
15+
"collector_ip": "10.0.0.11",
16+
"collector_port": 31283,
17+
"hosts": [
18+
{
19+
"ip": "10.0.0.103",
20+
"name": "gw1"
21+
}
22+
],
23+
"flows": [
24+
{
25+
"src_addr": "10.14.0.0",
26+
"dst_addr": "10.0.1.0",
27+
"dst_port": "80",
28+
"hops": ["gw1"],
29+
"count": 1
30+
}
31+
]
32+
}
2733
```
2834

29-
### Download the binary
30-
31-
You can download the Linux binary here [nflow-generator-x86_64-linux](https://github.com/nerdalert/nflow-generator/blob/master/binaries/nflow-generator-x86_64-linux).
32-
### Build
33-
34-
Install [Go](http://golang.org/doc/install), then:
35+
Run following commands
3536

36-
git clone https://github.com/nerdalert/nflow-generator.git
37-
cd nflow-generator
38-
go build
39-
40-
Go build will leave a binary in the root directory that can be run.
41-
42-
### RUN
43-
44-
Feed it the target collector and port, and optional "false-index" flag:
45-
46-
./nflow-generator -t <ip> -p <port> [ -f | --false-index ]
47-
48-
### Run a Test Collection
49-
50-
You can run a simple test collection using nfcapd from the nfdump package with the following.
51-
52-
- Start a netflow collector
53-
54-
```
55-
sudo apt-get install nfdump
56-
mkdir /tmp/nfcap-test
57-
nfcapd -E -p 9001 -l /tmp/nfcap-test
37+
```bash
38+
go build # one time
39+
./manflow -i gw1
5840
```
5941

60-
In a seperate console, run the netflow-generator pointing at an IP on the host the collector is running on (in this case the VM has an IP of 192.168.1.113).
61-
62-
```
63-
sudo docker run -it --rm networkstatic/nflow-generator -t 192.168.1.113 -p 9001
64-
```
65-
66-
- You should start seeing records displayed to the output of the screen running nfcapd like the following.
67-
68-
```
69-
$> nfcapd -E -p 9001 -l /tmp/nfcap-test
70-
Add extension: 2 byte input/output interface index
71-
Add extension: 4 byte input/output interface index
72-
Add extension: 2 byte src/dst AS number
73-
Add extension: 4 byte src/dst AS number
74-
Bound to IPv4 host/IP: any, Port: 9001
75-
Startup.
76-
Init IPFIX: Max number of IPFIX tags: 62
77-
78-
Flow Record:
79-
Flags = 0x00 FLOW, Unsampled
80-
export sysid = 1
81-
size = 56
82-
first = 1552592037 [2019-03-14 15:33:57]
83-
last = 1552592038 [2019-03-14 15:33:58]
84-
msec_first = 973
85-
msec_last = 414
86-
src addr = 112.10.20.10
87-
dst addr = 172.30.190.10
88-
src port = 40
89-
dst port = 80
90-
fwd status = 0
91-
tcp flags = 0x00 ......
92-
proto = 6 TCP
93-
(src)tos = 0
94-
(in)packets = 792
95-
(in)bytes = 23
96-
input = 0
97-
output = 0
98-
src as = 48730
99-
dst as = 15401
100-
101-
102-
Flow Record:
103-
Flags = 0x00 FLOW, Unsampled
104-
export sysid = 1
105-
size = 56
106-
first = 1552592038 [2019-03-14 15:33:58]
107-
last = 1552592038 [2019-03-14 15:33:58]
108-
msec_first = 229
109-
msec_last = 379
110-
src addr = 192.168.20.10
111-
dst addr = 202.12.190.10
112-
src port = 40
113-
dst port = 443
114-
fwd status = 0
115-
tcp flags = 0x00 ......
116-
proto = 6 TCP
117-
(src)tos = 0
118-
(in)packets = 599
119-
(in)bytes = 602
120-
input = 0
121-
output = 0
122-
src as = 1115
123-
dst as = 50617
124-
125-
```
126-
127-
### Notes
128-
129-
The original mock netflow generator placed random values in several fields which confused
130-
certain netflow collectors that complained about inaccurate time stamps,
131-
and were confused by the random values sent in the input and output interface fields.
132-
133-
Changes:
134-
135-
* Sets the `SysUptime`, `unix_secs`, and `unix_nsecs` fields of the Netflow datagrams to sensible (UTC) values
136-
* Generates a unique `flow_sequence` value for each netflow datagram
137-
* Creates reasonable start/stop times for flows, so the First is set to (now-X) and Last to (now-Y), where X & Y are random times, and X > Y.
138-
* If the --false-index (-f) flag is set on the command line,
139-
use this algorithm to set the interface indexes to 1 or 2:
140-
If the source address > dest address, input interface is set to 1, and set to 2 otherwise,
141-
and the output interface is set to the opposite value.
142-
If the -f is missing, both snmp interface indexes will be set to 0. [Default]
42+
Command-line arguments:
14343

144-
To learn more about Netflow version 5 datagram formats, see the [Cisco Netflow documentation](http://www.cisco.com/c/en/us/td/docs/net_mgmt/netflow_collection_engine/3-6/user/guide/format.html)
44+
- `-i` - host name of one of the hosts in `flowConfig.json` file
45+
- `-l` - disable flow-level logging

binaries/nflow-generator-x86_64-linux

-4 MB
Binary file not shown.

config_args.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/jessevdk/go-flags"
8+
)
9+
10+
var opts struct {
11+
Help bool `short:"h" long:"help" description:"show nflow-generator help"`
12+
HostName string `short:"i" long:"host-name" description:"provide host name to use with config file"`
13+
ConfigFile string `short:"e" long:"config-file" description:"provide config file to describe complex flow generation behavior"`
14+
GenGraphFile string `short:"g" long:"gen-graph-file" description:"generate graph file"`
15+
DisableLogging bool `short:"l" long:"disable-logging" description:"disable logging"`
16+
Simulate bool `short:"m" long:"simulate" description:"simulate only, do not send to collector"`
17+
StatsOutFile string `short:"o" long:"stats-out-file" description:"write stats to file"`
18+
GenComposeFile string `short:"q" long:"gen-compose-file" description:"generate compose file"`
19+
GenTargetsFile string `short:"r" long:"gen-targets-file" description:"generate prometheus targets file"`
20+
}
21+
22+
type ConfigArgs struct {
23+
ConfigFile string
24+
HostName string
25+
}
26+
27+
func ParseConfigArgs() (ConfigArgs, error) {
28+
_, err := flags.Parse(&opts)
29+
30+
if err != nil {
31+
return ConfigArgs{}, fmt.Errorf("failed to parse config args: %v", err)
32+
}
33+
34+
inputConfigFile := "flowConfig.json"
35+
if opts.ConfigFile != "" {
36+
inputConfigFile = opts.ConfigFile
37+
} else if os.Getenv("CONFIG_FILE") != "" {
38+
inputConfigFile = os.Getenv("CONFIG_FILE")
39+
}
40+
41+
inputHostName := ""
42+
if opts.HostName != "" {
43+
inputHostName = opts.HostName
44+
} else if os.Getenv("HOST_NAME") != "" {
45+
inputHostName = os.Getenv("HOST_NAME")
46+
}
47+
48+
return ConfigArgs{
49+
ConfigFile: inputConfigFile,
50+
HostName: inputHostName,
51+
}, nil
52+
}
53+
54+
func showUsage() {
55+
var usage string
56+
usage = `
57+
Usage:
58+
main [OPTIONS] [collector IP address] [collector port number]
59+
60+
Send mock Netflow version 5 data to designated collector IP & port.
61+
Time stamps in all datagrams are set to UTC.
62+
63+
Application Options:
64+
-t, --target= target ip address of the netflow collector
65+
-p, --port= port number of the target netflow collector
66+
-s, --spike run a second thread generating a spike for the specified protocol
67+
protocol options are as follows:
68+
ftp - generates tcp/21
69+
ssh - generates tcp/22
70+
dns - generates udp/54
71+
http - generates tcp/80
72+
https - generates tcp/443
73+
ntp - generates udp/123
74+
snmp - generates ufp/161
75+
imaps - generates tcp/993
76+
mysql - generates tcp/3306
77+
https_alt - generates tcp/8080
78+
p2p - generates udp/6681
79+
bittorrent - generates udp/6682
80+
-f, --false-index generate a false snmp index values of 1 or 2. The default is 0. (Optional)
81+
-c, --flow-count set the number of flows to generate in each iteration. The default is 16. (Optional)
82+
83+
Example Usage:
84+
85+
-first build from source (one time)
86+
go build
87+
88+
-generate default flows to device 172.16.86.138, port 9995
89+
./nflow-generator -t 172.16.86.138 -p 9995
90+
91+
-generate default flows along with a spike in the specified protocol:
92+
./nflow-generator -t 172.16.86.138 -p 9995 -s ssh
93+
94+
-generate default flows with "false index" settings for snmp interfaces
95+
./nflow-generator -t 172.16.86.138 -p 9995 -f
96+
97+
-generate default flows with up to 256 flows
98+
./nflow-generator -c 128 -t 172.16.86.138 -p 9995
99+
100+
Help Options:
101+
-h, --help Show this help message
102+
`
103+
fmt.Print(usage)
104+
}

0 commit comments

Comments
 (0)