go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/071_span_test.go (about)

     1  package vpp
     2  
     3  import (
     4  	"testing"
     5  
     6  	"go.ligato.io/cn-infra/v2/logging/logrus"
     7  
     8  	ifplugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/vppcalls"
     9  	vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    10  
    11  	_ "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
    12  )
    13  
    14  func TestSpan(t *testing.T) {
    15  	ctx := setupVPP(t)
    16  	defer ctx.teardownVPP()
    17  
    18  	h := ifplugin_vppcalls.CompatibleInterfaceVppHandler(ctx.vppClient, logrus.NewLogger("test"))
    19  
    20  	tests := []struct {
    21  		name string
    22  
    23  		// SPAN params:
    24  		swIfIndexFrom uint32
    25  		swIfIndexTo   uint32
    26  		direction     uint8
    27  		isL2          bool
    28  
    29  		// If dump must return record (true) or empty slice (false):
    30  		isDump bool
    31  		// Action:
    32  		isAdd bool
    33  		// If action must fail:
    34  		isFail bool
    35  	}{
    36  		{"enable Rx SPAN", 0, 1, uint8(vpp_interfaces.Span_RX), false, true, true, false},
    37  		{"enable Tx SPAN", 0, 1, uint8(vpp_interfaces.Span_TX), false, true, true, false},
    38  		{"enable Both SPAN", 0, 1, uint8(vpp_interfaces.Span_BOTH), false, true, true, false},
    39  		{"disable SPAN", 0, 1, uint8(vpp_interfaces.Span_BOTH), false, false, false, false},
    40  		{"enable SPAN with L2 set", 0, 1, uint8(vpp_interfaces.Span_RX), true, true, true, false},
    41  		{"disable SPAN with L2 set", 0, 1, uint8(vpp_interfaces.Span_RX), true, false, false, false},
    42  		{"enable bad SPAN", 0, 0, uint8(vpp_interfaces.Span_BOTH), false, false, true, true},
    43  	}
    44  
    45  	for _, test := range tests {
    46  		t.Run(test.name, func(t *testing.T) {
    47  			var err error
    48  
    49  			if test.isAdd {
    50  				err = h.AddSpan(test.swIfIndexFrom, test.swIfIndexTo, test.direction, test.isL2)
    51  			} else {
    52  				err = h.DelSpan(test.swIfIndexFrom, test.swIfIndexTo, test.isL2)
    53  			}
    54  
    55  			if test.isFail && err == nil {
    56  				t.Fatal("must fail, but no error returned from action")
    57  			} else if !test.isFail && err != nil {
    58  				t.Fatalf("action failed: %v\n", err)
    59  			}
    60  
    61  			dumpResp, err := h.DumpSpan()
    62  			if err != nil {
    63  				t.Fatalf("dump span failed: %v\n", err)
    64  			}
    65  
    66  			if test.isDump {
    67  				if len(dumpResp) != 1 {
    68  					t.Fatalf("wrong number of SPANs in dump. Expected: 1. Got: %d\n", len(dumpResp))
    69  				}
    70  
    71  				if dumpResp[0].SwIfIndexFrom != test.swIfIndexFrom {
    72  					t.Fatalf("wrong SwIfIndexFrom. Expected: %d. Got: %d\n", test.swIfIndexFrom, dumpResp[0].SwIfIndexFrom)
    73  				}
    74  				if dumpResp[0].SwIfIndexTo != test.swIfIndexTo {
    75  					t.Fatalf("wrong SwIfIndexTo. Expected: %d. Got: %d\n", test.swIfIndexTo, dumpResp[0].SwIfIndexTo)
    76  				}
    77  				if dumpResp[0].Direction != test.direction {
    78  					t.Fatalf("wrong Direction. Expected: %d. Got: %d\n", test.direction, dumpResp[0].Direction)
    79  				}
    80  				if dumpResp[0].IsL2 != test.isL2 {
    81  					t.Fatalf("wrong IsL2. Expected: %v. Got: %v\n", test.isL2, dumpResp[0].IsL2)
    82  				}
    83  			} else {
    84  				if len(dumpResp) != 0 {
    85  					t.Fatalf("wrong number of SPANs in dump. Expected: 0. Got: %d\n", len(dumpResp))
    86  				}
    87  			}
    88  
    89  		})
    90  	}
    91  }