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

     1  //  Copyright (c) 2020 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  	"io"
    20  	"testing"
    21  
    22  	. "github.com/onsi/gomega"
    23  
    24  	"go.ligato.io/vpp-agent/v3/proto/ligato/configurator"
    25  	"go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler"
    26  	linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces"
    27  	linux_ns "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace"
    28  	vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    29  	. "go.ligato.io/vpp-agent/v3/tests/e2e/e2etest"
    30  )
    31  
    32  func TestTelemetryStatsPoller(t *testing.T) {
    33  	ctx := Setup(t)
    34  	defer ctx.Teardown()
    35  
    36  	const (
    37  		msName     = "microservice1"
    38  		fullMsName = MsNamePrefix + msName
    39  		srcTapName = "vpp_span_src"
    40  		dstTapName = "vpp_span_dst"
    41  	)
    42  
    43  	srcTap := &vpp_interfaces.Interface{
    44  		Name:    srcTapName,
    45  		Type:    vpp_interfaces.Interface_TAP,
    46  		Enabled: true,
    47  		IpAddresses: []string{
    48  			"10.10.1.2/24",
    49  		},
    50  		Link: &vpp_interfaces.Interface_Tap{
    51  			Tap: &vpp_interfaces.TapLink{
    52  				Version: 2,
    53  			},
    54  		},
    55  	}
    56  	srcLinuxTap := &linux_interfaces.Interface{
    57  		Name:    "linux_span_tap1",
    58  		Type:    linux_interfaces.Interface_TAP_TO_VPP,
    59  		Enabled: true,
    60  		IpAddresses: []string{
    61  			"10.10.1.1/24",
    62  		},
    63  		HostIfName: "linux_span_tap1",
    64  		Link: &linux_interfaces.Interface_Tap{
    65  			Tap: &linux_interfaces.TapLink{
    66  				VppTapIfName: srcTapName,
    67  			},
    68  		},
    69  	}
    70  
    71  	dstTap := &vpp_interfaces.Interface{
    72  		Name:    dstTapName,
    73  		Type:    vpp_interfaces.Interface_TAP,
    74  		Enabled: true,
    75  		IpAddresses: []string{
    76  			"10.20.1.2/24",
    77  		},
    78  		Link: &vpp_interfaces.Interface_Tap{
    79  			Tap: &vpp_interfaces.TapLink{
    80  				Version:        2,
    81  				ToMicroservice: fullMsName,
    82  			},
    83  		},
    84  	}
    85  	dstLinuxTap := &linux_interfaces.Interface{
    86  		Name:    "linux_span_tap2",
    87  		Type:    linux_interfaces.Interface_TAP_TO_VPP,
    88  		Enabled: true,
    89  		IpAddresses: []string{
    90  			"10.20.1.1/24",
    91  		},
    92  		HostIfName: "linux_span_tap2",
    93  		Link: &linux_interfaces.Interface_Tap{
    94  			Tap: &linux_interfaces.TapLink{
    95  				VppTapIfName: dstTapName,
    96  			},
    97  		},
    98  		Namespace: &linux_ns.NetNamespace{
    99  			Type:      linux_ns.NetNamespace_MICROSERVICE,
   100  			Reference: fullMsName,
   101  		},
   102  	}
   103  
   104  	spanRx := &vpp_interfaces.Span{
   105  		InterfaceFrom: srcTapName,
   106  		InterfaceTo:   dstTapName,
   107  		Direction:     vpp_interfaces.Span_RX,
   108  	}
   109  
   110  	ctx.StartMicroservice(msName)
   111  
   112  	req := ctx.GenericClient().ChangeRequest()
   113  	err := req.Update(dstTap, dstLinuxTap, spanRx).Send(context.Background())
   114  	ctx.Expect(err).ToNot(HaveOccurred())
   115  
   116  	ctx.Eventually(ctx.GetValueStateClb(dstTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED))
   117  
   118  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_PENDING))
   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  
   126  	ctx.Expect(ctx.GetValueState(spanRx)).To(Equal(kvscheduler.ValueState_CONFIGURED))
   127  
   128  	ctx.Expect(ctx.PingFromVPP("10.20.1.1")).To(Succeed())
   129  	ctx.Expect(ctx.PingFromMs(msName, "10.20.1.2")).To(Succeed())
   130  
   131  	pollerClient := configurator.NewStatsPollerServiceClient(ctx.GRPCConn())
   132  
   133  	t.Run("periodSec=0", func(tt *testing.T) {
   134  		g := NewWithT(tt)
   135  
   136  		stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{
   137  			PeriodSec: 0,
   138  		})
   139  		g.Expect(err).ToNot(HaveOccurred())
   140  		maxSeq := uint32(0)
   141  		n := 0
   142  		for {
   143  			stats, err := stream.Recv()
   144  			if err == io.EOF {
   145  				break
   146  			} else if err != nil {
   147  				tt.Fatal("recv error:", err)
   148  			}
   149  			tt.Logf("stats: %+v", stats)
   150  			n++
   151  			if stats.GetPollSeq() > maxSeq {
   152  				maxSeq = stats.GetPollSeq()
   153  			}
   154  		}
   155  		g.Expect(n).To(BeEquivalentTo(3))
   156  		g.Expect(maxSeq).To(BeEquivalentTo(0))
   157  	})
   158  
   159  	t.Run("numPolls=1", func(tt *testing.T) {
   160  		g := NewWithT(tt)
   161  
   162  		stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{
   163  			NumPolls:  1,
   164  			PeriodSec: 1,
   165  		})
   166  		g.Expect(err).ToNot(HaveOccurred())
   167  		maxSeq := uint32(0)
   168  		n := 0
   169  		for {
   170  			stats, err := stream.Recv()
   171  			if err == io.EOF {
   172  				break
   173  			} else if err != nil {
   174  				tt.Fatal("recv error:", err)
   175  			}
   176  			tt.Logf("stats: %+v", stats)
   177  			n++
   178  			if stats.GetPollSeq() > maxSeq {
   179  				maxSeq = stats.GetPollSeq()
   180  			}
   181  		}
   182  		g.Expect(n).To(BeEquivalentTo(3))
   183  		g.Expect(maxSeq).To(BeEquivalentTo(1))
   184  	})
   185  
   186  	t.Run("numPolls=2", func(tt *testing.T) {
   187  		g := NewWithT(tt)
   188  
   189  		stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{
   190  			NumPolls: 2,
   191  		})
   192  		g.Expect(err).ToNot(HaveOccurred())
   193  		_, err = stream.Recv()
   194  		g.Expect(err).To(HaveOccurred())
   195  	})
   196  
   197  }