-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
102 lines (92 loc) · 2.18 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"time"
"github.com/itochan/aes67-txrx/aes67"
"github.com/itochan/aes67-txrx/sap"
)
var (
mode = flag.String("m", "transmit", "Mode")
interfaceName = flag.String("i", "", "Network interface")
transmitFile = flag.String("f", "", "Transmit File")
address = flag.String("a", "", "Receive address")
)
type TxRxLog struct {
txTime time.Time
rxTime time.Time
rtt time.Duration
}
func main() {
flag.Parse()
sap := sap.NewSAP(*interfaceName)
switch *mode {
case "receive":
log.Printf("IP: %s", net.ParseIP(*address))
r := aes67.NewReceiver(sap.HostAddress, net.ParseIP(*address))
r.Receive()
break
case "transmit":
sap.AnnounceSAP()
s := aes67.NewSender(sap.HostAddress, sap.MulticastAddress)
s.Play(*transmitFile)
break
case "txrx":
sap.AnnounceSAP()
chEnd := make(chan struct{})
go func() {
log.Printf("Start Transmitter")
s := aes67.NewSender(sap.HostAddress, sap.MulticastAddress)
s.Play(*transmitFile)
time.Sleep(20 * time.Millisecond)
close(chEnd)
}()
go func() {
log.Printf("IP: %s", net.ParseIP(*address))
log.Printf("Start Receiver")
r := aes67.NewReceiver(sap.HostAddress, net.ParseIP(*address))
r.Receive()
}()
txRxLog := make([]TxRxLog, 30000)
for {
select {
case txSequenceNo := <-aes67.TxCh:
txRxLog[txSequenceNo-1].txTime = time.Now()
case rxSequenceNo := <-aes67.RxCh:
txRxLog[rxSequenceNo-1].rxTime = time.Now()
txRxLog[rxSequenceNo-1].rtt = txRxLog[rxSequenceNo-1].rxTime.Sub(txRxLog[rxSequenceNo-1].txTime)
case <-chEnd:
file, err := os.Create(fmt.Sprintf("%s.csv", time.Now()))
if err != nil {
log.Fatal(err)
}
defer file.Close()
for i, log := range txRxLog {
line := fmt.Sprintf("%d,%d\n", i+1, log.rtt/time.Nanosecond)
file.WriteString(line)
}
return
}
}
case "rxtx":
rxtx := aes67.NewRxTx(sap.HostAddress, net.ParseIP(*address), sap.HostAddress, sap.MulticastAddress)
chEnd := make(chan struct{})
go func() {
rxtx.ReceiveAndSend()
close(chEnd)
}()
for {
select {
case <-aes67.TxCh:
break
case <-aes67.RxCh:
break
case <-chEnd:
return
}
}
}
}