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

     1  //  Copyright (c) 2019 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package e2e
    16  
    17  import (
    18  	"context"
    19  	"regexp"
    20  	"testing"
    21  
    22  	. "github.com/onsi/gomega"
    23  
    24  	"go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler"
    25  	linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
    26  	linux_ns "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace"
    27  	vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    28  	. "go.ligato.io/vpp-agent/v3/tests/e2e/e2etest"
    29  )
    30  
    31  func TestSpan(t *testing.T) {
    32  	ctx := Setup(t)
    33  	defer ctx.Teardown()
    34  
    35  	const (
    36  		msName     = "microservice1"
    37  		fullMsName = MsNamePrefix + msName
    38  		srcTapName = "vpp_span_src"
    39  		dstTapName = "vpp_span_dst"
    40  	)
    41  
    42  	srcTap := &vpp_interfaces.Interface{
    43  		Name:    srcTapName,
    44  		Type:    vpp_interfaces.Interface_TAP,
    45  		Enabled: true,
    46  		IpAddresses: []string{
    47  			"10.10.1.2/24",
    48  		},
    49  		Link: &vpp_interfaces.Interface_Tap{
    50  			Tap: &vpp_interfaces.TapLink{
    51  				Version: 2,
    52  			},
    53  		},
    54  	}
    55  	srcLinuxTap := &linux_interfaces.Interface{
    56  		Name:    "linux_span_tap1",
    57  		Type:    linux_interfaces.Interface_TAP_TO_VPP,
    58  		Enabled: true,
    59  		IpAddresses: []string{
    60  			"10.10.1.1/24",
    61  		},
    62  		HostIfName: "linux_span_tap1",
    63  		Link: &linux_interfaces.Interface_Tap{
    64  			Tap: &linux_interfaces.TapLink{
    65  				VppTapIfName: srcTapName,
    66  			},
    67  		},
    68  	}
    69  
    70  	dstTap := &vpp_interfaces.Interface{
    71  		Name:    dstTapName,
    72  		Type:    vpp_interfaces.Interface_TAP,
    73  		Enabled: true,
    74  		IpAddresses: []string{
    75  			"10.20.1.2/24",
    76  		},
    77  		Link: &vpp_interfaces.Interface_Tap{
    78  			Tap: &vpp_interfaces.TapLink{
    79  				Version:        2,
    80  				ToMicroservice: fullMsName,
    81  			},
    82  		},
    83  	}
    84  	dstLinuxTap := &linux_interfaces.Interface{
    85  		Name:    "linux_span_tap2",
    86  		Type:    linux_interfaces.Interface_TAP_TO_VPP,
    87  		Enabled: true,
    88  		IpAddresses: []string{
    89  			"10.20.1.1/24",
    90  		},
    91  		HostIfName: "linux_span_tap2",
    92  		Link: &linux_interfaces.Interface_Tap{
    93  			Tap: &linux_interfaces.TapLink{
    94  				VppTapIfName: dstTapName,
    95  			},
    96  		},
    97  		Namespace: &linux_ns.NetNamespace{
    98  			Type:      linux_ns.NetNamespace_MICROSERVICE,
    99  			Reference: fullMsName,
   100  		},
   101  	}
   102  
   103  	spanRx := &vpp_interfaces.Span{
   104  		InterfaceFrom: srcTapName,
   105  		InterfaceTo:   dstTapName,
   106  		Direction:     vpp_interfaces.Span_RX,
   107  	}
   108  
   109  	ctx.StartMicroservice(msName)
   110  	req := ctx.GenericClient().ChangeRequest()
   111  	err := req.Update(dstTap, dstLinuxTap, spanRx).Send(context.Background())
   112  	ctx.Expect(err).ToNot(HaveOccurred(), "Sending change request failed with err")
   113  
   114  	ctx.Eventually(ctx.GetValueStateClb(dstTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED),
   115  		"Destination TAP is not configured")
   116  
   117  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_PENDING),
   118  		"SPAN is not in a `PENDING` state, but `InterfaceFrom` is not ready")
   119  
   120  	req = ctx.GenericClient().ChangeRequest()
   121  	err = req.Update(srcTap, srcLinuxTap).Send(context.Background())
   122  	ctx.Expect(err).ToNot(HaveOccurred())
   123  
   124  	ctx.Eventually(ctx.GetValueStateClb(srcTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED),
   125  		"Source TAP is not configured")
   126  
   127  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_CONFIGURED),
   128  		"SPAN is not in a `CONFIGURED` state, but both interfaces are ready")
   129  
   130  	ctx.StopMicroservice(msName)
   131  	ctx.Eventually(ctx.GetValueStateClb(dstTap)).Should(Equal(kvscheduler.ValueState_PENDING),
   132  		"Destination TAP must be in a `PENDING` state, after its microservice stops")
   133  
   134  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_PENDING),
   135  		"SPAN is not in a `PENDING` state, but `InterfaceTo` is not ready")
   136  
   137  	// Check `show int span` output
   138  	stdout, err := ctx.ExecVppctl("show", "int", "span")
   139  	ctx.Expect(err).ToNot(HaveOccurred(), "Running `show int span` failed with err")
   140  	ctx.Expect(stdout).To(HaveLen(0),
   141  		"Expected empty output from `show int span` command")
   142  
   143  	// Start container and configure destination interface again
   144  	ctx.StartMicroservice(msName)
   145  
   146  	ctx.Eventually(ctx.GetValueStateClb(dstTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED),
   147  		"Destination TAP expected to be configured")
   148  
   149  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_CONFIGURED),
   150  		"SPAN is not in a `CONFIGURED` state, but both interfaces are ready")
   151  
   152  	// Check `show int span` output
   153  	stdout, err = ctx.ExecVppctl("show", "int", "span")
   154  	ctx.Expect(err).ToNot(HaveOccurred(), "Running `show int span` failed with err")
   155  	s := regexp.MustCompile(`\s+`).ReplaceAllString(stdout, " ")
   156  	ctx.Expect(s).To(Equal("Source Destination Device L2 tap1 tap0 ( rx) ( none) "),
   157  		"Output of `show int span` didn't match to expected")
   158  }