@@ -5,10 +5,12 @@ import (
55 "context"
66 "flag"
77 "log"
8+ "os"
89 "sync"
910 "time"
1011
1112 "github.com/m-lab/traceroute-caller/connection"
13+ "github.com/m-lab/traceroute-caller/tracer"
1214
1315 "github.com/m-lab/go/flagx"
1416 "github.com/m-lab/go/rtx"
@@ -18,23 +20,31 @@ import (
1820 "github.com/m-lab/traceroute-caller/connectionlistener"
1921 "github.com/m-lab/traceroute-caller/connectionpoller"
2022 "github.com/m-lab/traceroute-caller/ipcache"
21- "github.com/m-lab/traceroute-caller/scamper"
2223)
2324
2425var (
25- scamperBin = flag .String ("scamper.bin" , "scamper" , "path of scamper binary" )
26- scattachBin = flag .String ("scamper.sc_attach" , "sc_attach" , "path of sc_attach binary" )
27- scwarts2jsonBin = flag .String ("scamper.sc_warts2json" , "sc_warts2json" , "path of sc_warts2json binary" )
26+ scamperBin = flag .String ("scamper.bin" , "scamper" , "The path to the scamper binary. " )
27+ scattachBin = flag .String ("scamper.sc_attach" , "sc_attach" , "The path to the sc_attach binary. " )
28+ scwarts2jsonBin = flag .String ("scamper.sc_warts2json" , "sc_warts2json" , "The path to the sc_warts2json binary. " )
2829 scamperCtrlSocket = flag .String ("scamper.unixsocket" , "/tmp/scamperctrl" , "The name of the UNIX-domain socket that the scamper daemon should listen on" )
30+ scamperTimeout = flag .Duration ("scamper.timeout" , 300 * time .Second , "how long to wait to complete a scamper trace." )
31+ parisBin = flag .String ("paris.bin" , "paris-traceroute" , "The path to the paris-traceroute binary." )
32+ parisTimeout = flag .Duration ("paris.timeout" , 60 * time .Second , "how long to wait to complete a paris-traceroute trace." )
2933 outputPath = flag .String ("outputPath" , "/var/spool/scamper" , "path of output" )
3034 waitTime = flag .Duration ("waitTime" , 5 * time .Second , "how long to wait between subsequent listings of open connections" )
31- eventsocketDryRun = flag .Bool ("tcpinfo.eventsocket.dryrun" , false , "Whether the eventsocket machinery should be turned on in print-only mode." )
3235 poll = flag .Bool ("poll" , true , "Whether the polling method should be used to see new connections." )
33- scamperTimeout = flag .Duration ("scamperTimeout" , 300 * time .Second , "how long to wait to complete a scamper trace." )
36+ tracerType = flagx.Enum {
37+ Options : []string {"paris-traceroute" , "scamper" },
38+ Value : "scamper" ,
39+ }
3440
3541 ctx , cancel = context .WithCancel (context .Background ())
3642)
3743
44+ func init () {
45+ flag .Var (& tracerType , "tracetool" , "Choose whether paris-traceroute or scamper should be used." )
46+ }
47+
3848// Sample cmd:
3949// go build
4050// ./traceroute-caller --outputPath scamper_output
@@ -43,27 +53,40 @@ func main() {
4353
4454 flag .Parse ()
4555 rtx .Must (flagx .ArgsFromEnv (flag .CommandLine ), "Could not get args from environment" )
56+ rtx .Must (os .MkdirAll (* outputPath , 0557 ), "Could not create data directory" )
4657
4758 defer cancel ()
4859
4960 promSrv := prometheusx .MustServeMetrics ()
5061 defer promSrv .Shutdown (ctx )
5162
52- daemon := scamper.Daemon {
53- Binary : * scamperBin ,
54- AttachBinary : * scattachBin ,
55- Warts2JSONBinary : * scwarts2jsonBin ,
56- OutputPath : * outputPath ,
57- ControlSocket : * scamperCtrlSocket ,
58- ScamperTimeout : * scamperTimeout ,
63+ var trace ipcache.Tracer
64+ switch tracerType .Value {
65+ case "scamper" :
66+ daemon := & tracer.ScamperDaemon {
67+ Binary : * scamperBin ,
68+ AttachBinary : * scattachBin ,
69+ Warts2JSONBinary : * scwarts2jsonBin ,
70+ OutputPath : * outputPath ,
71+ ControlSocket : * scamperCtrlSocket ,
72+ ScamperTimeout : * scamperTimeout ,
73+ }
74+ go func () {
75+ daemon .MustStart (ctx )
76+ cancel ()
77+ }()
78+ trace = daemon
79+ case "paris-traceroute" :
80+ trace = & tracer.Paris {
81+ Binary : * parisBin ,
82+ OutputPath : * outputPath ,
83+ Timeout : * parisTimeout ,
84+ }
5985 }
60- go func () {
61- daemon .MustStart (ctx )
62- cancel ()
63- }()
6486
6587 wg := sync.WaitGroup {}
66- cache := ipcache .New (ctx , & daemon , * ipcache .IPCacheTimeout , * ipcache .IPCacheUpdatePeriod )
88+ cache := ipcache .New (ctx , trace , * ipcache .IPCacheTimeout , * ipcache .IPCacheUpdatePeriod )
89+
6790 if * poll {
6891 wg .Add (1 )
6992 go func (c * ipcache.RecentIPCache ) {
@@ -84,11 +107,6 @@ func main() {
84107 go func () {
85108 connCreator , err := connection .NewCreator ()
86109 rtx .Must (err , "Could not discover local IPs" )
87- esdaemon := daemon
88- esdaemon .DryRun = * eventsocketDryRun
89- if * eventsocketDryRun {
90- cache = ipcache .New (ctx , & esdaemon , * ipcache .IPCacheTimeout , * ipcache .IPCacheUpdatePeriod )
91- }
92110 connListener := connectionlistener .New (connCreator , cache )
93111 eventsocket .MustRun (ctx , * eventsocket .Filename , connListener )
94112 wg .Done ()
0 commit comments