func TestSFlowAgent(t *testing.T) { helper.InitConfig(t, confAgentAnalyzer) router := mux.NewRouter().StrictSlash(true) server, err := analyzer.NewServerFromConfig(router) if err != nil { t.Fatal(err) } ts := NewTestStorage() server.SetStorage(ts) go server.ListenAndServe() defer server.Stop() agent := helper.StartAgent(t) defer agent.Stop() time.Sleep(1 * time.Second) for _, trace := range flowsTraces { fulltrace, _ := filepath.Abs("pcaptraces" + string(filepath.Separator) + trace.filename) helper.ReplayTraceHelper(t, fulltrace, "localhost:55000") /* FIXME (nplanel) remove this Sleep when agent.FlushFlowTable() exist */ time.Sleep(2 * time.Second) ts.Validate(t, &trace) } }
func TestPatchOVS(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "ovs-vsctl add-br br-test1", "ovs-vsctl add-br br-test2", "ovs-vsctl add-port br-test1 patch-br-test2 -- set interface patch-br-test2 type=patch", "ovs-vsctl add-port br-test2 patch-br-test1 -- set interface patch-br-test1 type=patch", "ovs-vsctl set interface patch-br-test2 option:peer=patch-br-test1", "ovs-vsctl set interface patch-br-test1 option:peer=patch-br-test2", } tearDownCmds := []string{ "ovs-vsctl del-br br-test1", "ovs-vsctl del-br br-test2", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 10 && len(g.GetEdges()) >= 9 { patch1 := g.LookupFirstNode(graph.Metadatas{"Type": "patch", "Name": "patch-br-test1", "Driver": "openvswitch"}) if patch1 == nil { return } patch2 := g.LookupFirstNode(graph.Metadatas{"Type": "patch", "Name": "patch-br-test2", "Driver": "openvswitch"}) if patch2 == nil { return } if !g.AreLinked(patch1, patch2) { return } testPassed = true ws.Close() } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"br-test1", "br-test2", "patch-br-test1", "patch-br-test2"}) }
func TestInterfaceOVS(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "ovs-vsctl add-br br-test1", "ovs-vsctl add-port br-test1 intf1 -- set interface intf1 type=internal", } tearDownCmds := []string{ "ovs-vsctl del-br br-test1", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 5 && len(g.GetEdges()) >= 4 { intf := g.LookupFirstNode(graph.Metadatas{"Type": "internal", "Name": "intf1", "Driver": "openvswitch"}) if intf != nil { if _, ok := intf.Metadatas()["UUID"]; ok { // check we don't have another interface potentially added by netlink // should only have ovsport and interface others := g.LookupNodes(graph.Metadatas{"Name": "intf1"}) if len(others) > 2 { return } if _, ok := intf.Metadatas()["MAC"]; !ok { return } testPassed = true ws.Close() } } } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"br-test1", "intf1"}) }
func TestBridgeOVS(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "ovs-vsctl add-br br-test1", } tearDownCmds := []string{ "ovs-vsctl del-br br-test1", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 3 && len(g.GetEdges()) >= 2 { ovsbridge := g.LookupFirstNode(graph.Metadatas{"Type": "ovsbridge", "Name": "br-test1"}) if ovsbridge == nil { return } ovsports := g.LookupChildren(ovsbridge, graph.Metadatas{"Type": "ovsport"}) if len(ovsports) != 1 { return } devices := g.LookupChildren(ovsports[0], graph.Metadatas{"Type": "internal", "Driver": "openvswitch"}) if len(devices) != 1 { return } if ovsbridge.Metadatas()["Host"] == "" || ovsports[0].Metadatas()["Host"] == "" || devices[0].Metadatas()["Host"] == "" { return } testPassed = true ws.Close() } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"br-test1"}) }
func TestBondOVS(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "ovs-vsctl add-br br-test1", "ip tuntap add mode tap dev intf1", "ip tuntap add mode tap dev intf2", "ovs-vsctl add-bond br-test1 bond0 intf1 intf2", } tearDownCmds := []string{ "ovs-vsctl del-br br-test1", "ip link del intf1", "ip link del intf2", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 6 && len(g.GetEdges()) >= 5 { bond := g.LookupFirstNode(graph.Metadatas{"Type": "ovsport", "Name": "bond0"}) if bond != nil { intfs := g.LookupChildren(bond, nil) if len(intfs) != 2 { return } testPassed = true ws.Close() } } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"br-test1", "intf1", "intf2"}) }
func TestBridge(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "brctl addbr br-test", "ip tuntap add mode tap dev intf1", "brctl addif br-test intf1", } tearDownCmds := []string{ "brctl delbr br-test", "ip link del intf1", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 2 && len(g.GetEdges()) >= 1 { bridge := g.LookupFirstNode(graph.Metadatas{"Type": "bridge", "Name": "br-test"}) if bridge != nil { nodes := g.LookupChildren(bridge, graph.Metadatas{"Name": "intf1"}) if len(nodes) == 1 { testPassed = true ws.Close() } } } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"br-test", "intf1"}) }
func TestVeth(t *testing.T) { helper.InitConfig(t, confTopology) g := newGraph(t) agent := helper.StartAgent(t) defer agent.Stop() setupCmds := []string{ "ip l add vm1-veth0 type veth peer name vm1-veth1", } tearDownCmds := []string{ "ip link del vm1-veth0", } testPassed := false onChange := func(ws *websocket.Conn) { g.Lock() defer g.Unlock() if !testPassed && len(g.GetNodes()) >= 2 && len(g.GetEdges()) >= 1 { nodes := g.LookupNodes(graph.Metadatas{"Type": "veth"}) if len(nodes) == 2 { if g.AreLinked(nodes[0], nodes[1]) { testPassed = true ws.Close() } } } } testTopology(t, g, setupCmds, onChange) if !testPassed { t.Error("test not executed or failed") } testCleanup(t, g, tearDownCmds, []string{"vm1-veth0", "vm1-veth1"}) }