func TestPcap2SflowReplay(t *testing.T) { conn, err := sflowSetup(t) if err != nil { t.Fatal("SFlow setup failed", err.Error()) } defer conn.Close() laddr, err := net.ResolveUDPAddr(conn.LocalAddr().Network(), conn.LocalAddr().String()) if err != nil { t.Error("Can't read back the local address") } for _, trace := range packetsTraces { var wg sync.WaitGroup wg.Add(1) go asyncSflowListen(t, &wg, conn, &trace) fulltrace, _ := filepath.Abs(trace.filename) err := tools.PCAP2SFlowReplay("localhost", laddr.Port, fulltrace, 1000, 5) if err != nil { t.Fatalf("Error during the replay: %s", err.Error()) } wg.Wait() } }
func TestSFlowWithPCAP(t *testing.T) { ts := NewTestStorage() aa := helper.NewAgentAnalyzerWithConfig(t, confAgentAnalyzer, ts) aa.Start() defer aa.Stop() client := api.NewCrudClientFromConfig(&http.AuthenticationOpts{}) capture := &api.Capture{ProbePath: "*/br-sflow[Type=ovsbridge]"} if err := client.Create("capture", &capture); err != nil { t.Fatal(err.Error()) } time.Sleep(1 * time.Second) setupCmds := []helper.Cmd{ {"ovs-vsctl add-br br-sflow", true}, } tearDownCmds := []helper.Cmd{ {"ovs-vsctl del-br br-sflow", true}, } helper.ExecCmds(t, setupCmds...) defer helper.ExecCmds(t, tearDownCmds...) time.Sleep(5 * time.Second) // FIX(safchain): need to be reworked as there is no more static sflow agent // running at a specific port and agent couldn't speak sflow at all for _, trace := range flowsTraces { fulltrace, _ := filepath.Abs(trace.filename) err := tools.PCAP2SFlowReplay("localhost", 55000, fulltrace, 1000, 5) if err != nil { t.Fatalf("Error during the replay: %s", err.Error()) } aa.Flush() pcapTraceValidate(t, ts.GetFlows(), &trace) } client.Delete("capture", "*/br-sflow[Type=ovsbridge]") }
func TestSFlowWithPCAP(t *testing.T) { ts := NewTestStorage() agent, analyzer := helper.StartAgentAndAnalyzerWithConfig(t, confAgentAnalyzer, ts) defer agent.Stop() defer analyzer.Stop() time.Sleep(1 * time.Second) for _, trace := range flowsTraces { fulltrace, _ := filepath.Abs(trace.filename) err := tools.PCAP2SFlowReplay("localhost", 55000, fulltrace, 1000, 5) if err != nil { t.Fatalf("Error during the replay: %s", err.Error()) } /* FIXME (nplanel) remove this Sleep when agent.FlushFlowTable() exist */ time.Sleep(2 * time.Second) pcapTraceValidate(t, ts.GetFlows(), &trace) } }
} sflowFlag := cmd.LocalFlags().Lookup("sflow-agent").Value.String() sflowTuple := strings.Split(sflowFlag, ":") sflowAddr = sflowTuple[0] sflowPort = 6345 if len(sflowTuple) == 2 { if port, err := strconv.Atoi(sflowTuple[1]); err != nil { logging.GetLogger().Fatal("Can't parse UDP port: ", err) } else { sflowPort = port } } else if len(sflowTuple) > 2 { logging.GetLogger().Fatal("Invalid format for sFlow agent address:", sflowFlag) } }, Run: func(cmd *cobra.Command, args []string) { err := tools.PCAP2SFlowReplay(sflowAddr, sflowPort, pcapTrace, pps, pktsPerFlow) if err != nil { logging.GetLogger().Fatalf("Error during the replay: %s", err.Error()) } }, } func main() { replayCmd.Flags().StringVarP(&pcapTrace, "trace", "t", "trace.pcap", "PCAP trace file to read") replayCmd.Flags().StringP("sflow-agent", "s", "localhost:6345", "sFlow agent address (addr[:port])") replayCmd.Flags().Uint32Var(&pps, "pps", 1000, "packets per second") replayCmd.Flags().Uint32Var(&pktsPerFlow, "pktspersflow", 5, "number of packets per sFlow datagram") replayCmd.Execute() }