()
| 76 | } |
| 77 | |
| 78 | func main() { |
| 79 | config.InitConfig("../../daemon/opensn-daemon/config/config.json") |
| 80 | fmt.Printf("Etcd Addr is %s, Port is %d \n", config.GlobalConfig.Dependency.EtcdAddr, config.GlobalConfig.Dependency.EtcdPort) |
| 81 | opensnUtils.InitEtcdClient(config.GlobalConfig.Dependency.EtcdAddr, config.GlobalConfig.Dependency.EtcdPort) |
| 82 | fmt.Printf("This node index is %d\n", ThisNodeIndex) |
| 83 | linkList, err := synchronizer.GetLinkList(ThisNodeIndex) |
| 84 | |
| 85 | if err != nil { |
| 86 | fmt.Println(err) |
| 87 | return |
| 88 | } |
| 89 | linkCaptureLengthMap := make(map[string]uint64) |
| 90 | fmt.Printf("Get %d links\n", len(linkList)) |
| 91 | channel := make(chan utils.PacketWithInterface, CHANNEL_BUFFER_SIZE) |
| 92 | endChan := make(chan int) |
| 93 | for _, linkInfo := range linkList { |
| 94 | utils.StartAsyncCaptureInterfaceWithFilter(linkInfo.GetLinkID(), func(packet gopacket.Packet) bool { |
| 95 | if packet == nil || packet.NetworkLayer() == nil { |
| 96 | return false |
| 97 | } |
| 98 | // networkHeader := packet.NetworkLayer() |
| 99 | //Check Src IP == SRC_IP_ARRAY and Dst IP == DST_IP_ARRAY |
| 100 | // if networkHeader.NetworkFlow().Src().String() == SrcIP && |
| 101 | // networkHeader.NetworkFlow().Dst().String() == DstIP { |
| 102 | // return true |
| 103 | // } |
| 104 | return packet.NetworkLayer().NetworkFlow().Dst().String() == DstIP |
| 105 | }, channel, endChan) |
| 106 | } |
| 107 | // Receice Ctrl+C signal to stop the capture |
| 108 | |
| 109 | osSignal := make(chan os.Signal, 1) |
| 110 | signal.Notify(osSignal, os.Interrupt, syscall.SIGTERM) |
| 111 | |
| 112 | loop: |
| 113 | for { |
| 114 | |
| 115 | select { |
| 116 | case packet := <-channel: |
| 117 | fmt.Println(packet) |
| 118 | linkCaptureLengthMap[packet.InterfaceName] += uint64(packet.Packet.Metadata().CaptureInfo.Length) |
| 119 | if len(timestampSizeArray) == 0 { |
| 120 | timestampSizeArray = append(timestampSizeArray, map[string]uint64{}) |
| 121 | timestampArray = append(timestampArray, uint64(packet.Packet.Metadata().Timestamp.UnixMilli()/GIF_GAP_TEN_MILLISECOND/10)) |
| 122 | timestampSizeArray[0][packet.InterfaceName] = uint64(packet.Packet.Metadata().CaptureInfo.Length) |
| 123 | } else if uint64(packet.Packet.Metadata().Timestamp.UnixMilli())/GIF_GAP_TEN_MILLISECOND/10 > timestampArray[len(timestampSizeArray)-1] { |
| 124 | timestampSizeArray = append(timestampSizeArray, map[string]uint64{}) |
| 125 | timestampArray = append(timestampArray, uint64(packet.Packet.Metadata().Timestamp.UnixMilli()/GIF_GAP_TEN_MILLISECOND/10)) |
| 126 | timestampSizeArray[0][packet.InterfaceName] = uint64(packet.Packet.Metadata().CaptureInfo.Length) |
| 127 | } else { |
| 128 | timestampSizeArray[len(timestampSizeArray)-1][packet.InterfaceName] += uint64(packet.Packet.Metadata().CaptureInfo.Length) |
| 129 | } |
| 130 | case <-osSignal: |
| 131 | fmt.Println("Receive Ctrl+C signal") |
| 132 | // close(endChan) |
| 133 | break loop |
| 134 | } |
| 135 | } |
nothing calls this directly
no test coverage detected