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()
	}
}
Exemple #2
0
func TestSFlowWithPCAP(t *testing.T) {
	ts := NewTestStorage()

	aa := helper.NewAgentAnalyzerWithConfig(t, confAgentAnalyzer, ts)
	aa.Start()
	defer aa.Stop()

	client, err := api.NewCrudClientFromConfig(&http.AuthenticationOpts{})
	if err != nil {
		t.Fatal(err.Error())
	}

	capture := api.NewCapture("G.V().Has('Name', '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", capture.ID())
}