-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdoc.go
63 lines (48 loc) · 2.8 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
const version = "1.2"
const helpMessage = `This program:
1) parses text file with set of ip addresses and/or networks,
2) normalizes them,
3) auto aggregates (optionally),
4) prints resulted set.
[Input file format]
Program scans file line by line and parse beginning of line (until first ";" or EOL) for "|"-separated list of ip addresses and/or networks.
Spaces outside ip addresses and networks are ignored.
Only IPv4 is supported.
Networks must be defined in prefix notation ("127.0.0.1/24").
If there is no prefix ("127.0.0.1") then prefix "/32" will be added.
Some parser's hacks (in order):
1) it silently ignore any line beginning with "Updated:",
2) if first char in line is ";" when this char will be removed before parsing.
[Normalization]
Normalization removes all duplications. Also if network "A" contains network "B" then network "B" will be removed.
Each network itself also will be normalized according their mask: each non significant bits will be set to 0.
[Auto aggregation]
Auto aggregation reduces number of addresses/networks in cost of some addresses which is not belong to original set will be added ("fake" IPs).
Each address which belongs to original set will belongs to resulting set.
There are 2 type of auto aggregation: intensive and usual.
Intensive aggregation applied if all 3 conditions are satisfied:
1) result network's prefix >= "intensive-aggregation-min-prefix",
2) at least "intensive-aggregation-min-nets" nets from original set will be covered by new network,
3) no more than "intensive-aggregation-max-fake-ips" fake IPs will be covered/added by result network.
Usual aggregation computes acceptable percent ("AP") of fake IPs for resulting network.
Usual aggregation applied if all 2 conditions are satisfied:
1) number of fake IPs no more than "aggregation-max-fake-ips",
2) percent of fake IPs no more than "AP".
"AP" is non-linear function of <number of nets from original set which will be covered by new network> defined by 2 points:
1) If number of nets = 2 then "AP" = "aggregation-lo-fake-percent",
2) If number of nets = "aggregation-hi-fake-percent-nets" then "AP" = "aggregation-hi-fake-percent".
If number of nets = "aggregation-hi-fake-percent-nets" then "AP" also = "aggregation-hi-fake-percent".
[Printing result]
Result set is printed into "dst-file" in the following format:
"""
<prefix><network 1 address><delimiter><network 1 prefix or mask><suffix><network-delimiter>
<prefix><network 2 address><delimiter><network 2 prefix or mask><suffix><network-delimiter>
...
<prefix><network n-1 address><delimiter><network n-1 prefix or mask><suffix><network-delimiter>
<prefix><network n address><delimiter><network n prefix or mask><suffix>
"""
What will be printed - prefix or mask - depends on "mask-notation".
Result set is always sorted be network address.
[Usage]
`