Start sending PTP packets
()
| 87 | |
| 88 | // Start sending PTP packets |
| 89 | func (s *Sender) Start() ([]*PathInfo, error) { |
| 90 | icmpAddr, err := net.ResolveIPAddr("ip6:ipv6-icmp", "") |
| 91 | if err != nil { |
| 92 | return nil, fmt.Errorf("unable to resolve source address: %w", err) |
| 93 | } |
| 94 | icmpConn, err := net.ListenIP("ip6:ipv6-icmp", icmpAddr) |
| 95 | if err != nil { |
| 96 | return nil, fmt.Errorf("unable to listen to icmp: %w", err) |
| 97 | } |
| 98 | defer icmpConn.Close() |
| 99 | |
| 100 | if s.rackSwHostname, err = rackSwHostnameMonitor(s.Config.Device, s.Config.LLDPWaitTime); err != nil { |
| 101 | log.Warn("unable to learn name of rack switch via LLDP") |
| 102 | } |
| 103 | |
| 104 | s.icmpDone = make(chan bool) |
| 105 | s.icmpConn = icmpConn |
| 106 | |
| 107 | log.Infof("sending %v flows of PTP %v packets to %v from source port range %v-%v to destination port %v with %v packets per hop, max hop count of %v and min hop count of %v and "+ |
| 108 | "sweeping %v other addresses in target network prefix with a per hop timeout of %v. Total flows %v.\n\n", |
| 109 | s.Config.PortCount, s.Config.MessageType, s.Config.DestinationAddress, |
| 110 | s.Config.SourcePort, s.Config.SourcePort+s.Config.PortCount-1, s.Config.DestinationPort, |
| 111 | s.Config.PacketsPerHop, |
| 112 | s.Config.HopMax, s.Config.HopMin, s.Config.IPCount, s.Config.IcmpTimeout, |
| 113 | s.Config.PortCount+s.Config.PortCount*s.Config.IPCount) |
| 114 | |
| 115 | var g sync.WaitGroup |
| 116 | // prepare tasks |
| 117 | tasks := prepareTracing(s.Config) |
| 118 | // prepare input queue |
| 119 | s.inputQueue = make([]chan *SwitchTrafficInfo, len(tasks)) |
| 120 | for i := range tasks { |
| 121 | s.inputQueue[i] = make(chan *SwitchTrafficInfo, s.Config.QueueCap) |
| 122 | } |
| 123 | // start icmp listener |
| 124 | go s.monitorIcmp(s.icmpConn) |
| 125 | |
| 126 | routes := make([]*PathInfo, len(tasks)) |
| 127 | var mu sync.Mutex |
| 128 | for _, t := range tasks { |
| 129 | g.Add(1) |
| 130 | go func(t traceTask) { |
| 131 | defer g.Done() |
| 132 | route, err := s.traceRoute(t.destinationIP, t.sendingPort, t.routeID) |
| 133 | if err != nil { |
| 134 | log.Errorf("traceRoute failed: %v", err) |
| 135 | return |
| 136 | } |
| 137 | mu.Lock() |
| 138 | routes[t.routeID] = route |
| 139 | mu.Unlock() |
| 140 | }(t) |
| 141 | } |
| 142 | g.Wait() |
| 143 | |
| 144 | // Waiting for late packets, if any |
| 145 | time.Sleep(s.Config.IcmpReplyTime) |
| 146 | s.popAllQueue(routes) |
no test coverage detected