go.ligato.io/vpp-agent/v3@v3.5.0/plugins/telemetry/vppcalls/vpp2101/telemetry_vppcalls_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 vpp2101_test
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	. "github.com/onsi/gomega"
    22  
    23  	"go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls"
    24  	"go.ligato.io/vpp-agent/v3/plugins/telemetry/vppcalls/vpp2101"
    25  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/vpe"
    26  	"go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock"
    27  )
    28  
    29  func TestGetBuffers(t *testing.T) {
    30  	ctx, handler := testSetup(t)
    31  	defer ctx.TeardownTestCtx()
    32  
    33  	const reply = `Pool Name            Index NUMA  Size  Data Size  Total  Avail  Cached   Used  
    34  default-numa-0         0     0   2304     2048    17290  17290     0       0   `
    35  	ctx.MockVpp.MockReply(&vpe.CliInbandReply{
    36  		Reply: reply,
    37  	})
    38  
    39  	info, err := handler.GetBuffersInfo(context.TODO())
    40  
    41  	Expect(err).ShouldNot(HaveOccurred())
    42  	Expect(info.Items).To(HaveLen(1))
    43  	Expect(info.Items[0]).To(Equal(vppcalls.BuffersItem{
    44  		//ThreadID: 0,
    45  		Name:  "default-numa-0",
    46  		Index: 0,
    47  		Size:  2304,
    48  		Alloc: 0,
    49  		Free:  17290,
    50  		//NumAlloc: 256,
    51  		//NumFree:  19,
    52  	}))
    53  	/*Expect(info.Items[1]).To(Equal(vppcalls.BuffersItem{
    54  		ThreadID: 0,
    55  		Name:     "lacp-ethernet",
    56  		Index:    1,
    57  		Size:     256,
    58  		Alloc:    1130000,
    59  		Free:     27000,
    60  		NumAlloc: 512,
    61  		NumFree:  12,
    62  	}))
    63  	Expect(info.Items[2]).To(Equal(vppcalls.BuffersItem{
    64  		ThreadID: 0,
    65  		Name:     "marker-ethernet",
    66  		Index:    2,
    67  		Size:     256,
    68  		Alloc:    1110000000,
    69  		Free:     0,
    70  		NumAlloc: 0,
    71  		NumFree:  0,
    72  	}))*/
    73  }
    74  
    75  func TestGetRuntime(t *testing.T) {
    76  	tests := []struct {
    77  		name        string
    78  		reply       string
    79  		threadCount int
    80  		itemCount   int
    81  		itemIdx     int
    82  		item        vppcalls.RuntimeItem
    83  	}{
    84  		{
    85  			name: "19.08",
    86  			reply: `Time 84714.7, average vectors/node 0.00, last 128 main loops 0.00 per node 0.00
    87    vector rates in 0.0000e0, out 0.0000e0, drop 0.0000e0, punt 0.0000e0
    88               Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call  
    89  acl-plugin-fa-cleaner-process  event wait                6               5               1          1.10e4            0.00
    90  api-rx-from-ring                 active                  0               0            7870          8.63e5            0.00
    91  avf-process                    event wait                0               0               1          4.53e3            0.00
    92  bfd-process                    event wait                0               0               1          7.01e3            0.00
    93  bond-process                   event wait                0               0               1          2.95e3            0.00
    94  cdp-process                     any wait                 0               0               1          5.46e3            0.00
    95  dhcp-client-process             any wait                 0               0             847          6.63e3            0.00
    96  dhcp6-client-cp-process         any wait                 0               0               1          1.52e3            0.00
    97  dhcp6-pd-client-cp-process      any wait                 0               0               1          1.71e3            0.00
    98  dhcp6-pd-reply-publisher-proce event wait                0               0               1          9.73e2            0.00
    99  dhcp6-reply-publisher-process  event wait                0               0               1          9.12e2            0.00
   100  dns-resolver-process            any wait                 0               0              85          8.98e3            0.00
   101  fib-walk                        any wait                 0               0           42247          1.08e4            0.00
   102  flow-report-process             any wait                 0               0               1          1.33e3            0.00
   103  flowprobe-timer-process         any wait                 0               0               1          5.18e3            0.00
   104  gbp-scanner                    event wait                0               0               1          5.17e3            0.00
   105  igmp-timer-process             event wait                0               0               1          6.53e3            0.00
   106  ikev2-manager-process           any wait                 0               0           84353          7.84e3            0.00
   107  ioam-export-process             any wait                 0               0               1          1.64e3            0.00
   108  ip-neighbor-scan-process        any wait                 0               0            1412          9.65e3            0.00
   109  ip-route-resolver-process       any wait                 0               0             847          6.12e3            0.00
   110  ip4-reassembly-expire-walk      any wait                 0               0            8464          6.92e3            0.00
   111  ip6-icmp-neighbor-discovery-ev  any wait                 0               0           84353          8.58e3            0.00
   112  ip6-reassembly-expire-walk      any wait                 0               0            8464          6.67e3            0.00
   113  l2fib-mac-age-scanner-process  event wait                0               0               1          1.98e3            0.00
   114  lacp-process                   event wait                0               0               1          1.58e5            0.00
   115  lisp-retry-service              any wait                 0               0           42247          1.08e4            0.00
   116  lldp-process                   event wait                0               0               1          8.76e4            0.00
   117  memif-process                  event wait                0               0               1          9.34e3            0.00
   118  nat-det-expire-walk               done                   1               0               0          2.92e3            0.00
   119  nat-ha-process                 event wait                0               0               1          4.12e3            0.00
   120  nat64-expire-walk              event wait                0               0               1          2.41e3            0.00
   121  nsh-md2-ioam-export-process     any wait                 0               0               1          1.10e4            0.00
   122  perfmon-periodic-process       event wait                0               0               1          3.61e7            0.00
   123  rd-cp-process                   any wait                 0               0               1          1.55e3            0.00
   124  send-dhcp6-client-message-proc  any wait                 0               0               1          2.22e3            0.00
   125  send-dhcp6-pd-client-message-p  any wait                 0               0               1          1.43e3            0.00
   126  send-rs-process                 any wait                 0               0               1          1.49e3            0.00
   127  startup-config-process            done                   1               0               1          5.68e3            0.00
   128  statseg-collector-process       time wait                0               0            8464          2.79e5            0.00
   129  udp-ping-process                any wait                 0               0               1          6.96e3            0.00
   130  unix-cli-127.0.0.1:mdns           done                   2               0               4          2.14e9            0.00
   131  unix-epoll-input                 polling          20325059               0               0          1.13e7            0.00
   132  vhost-user-process              any wait                 0               0               1          3.73e3            0.00
   133  vhost-user-send-interrupt-proc  any wait                 0               0               1          1.28e3            0.00
   134  vpe-link-state-process         event wait                0               0               1          9.63e2            0.00
   135  vpe-oam-process                 any wait                 0               0           41419          9.59e3            0.00
   136  vxlan-gpe-ioam-export-process   any wait                 0               0               1          1.60e3            0.00
   137  wildcard-ip4-arp-publisher-pro event wait                0               0               1          1.44e3            0.00
   138  `,
   139  			threadCount: 1,
   140  			itemCount:   49,
   141  			item: vppcalls.RuntimeItem{
   142  				Name:           "acl-plugin-fa-cleaner-process",
   143  				State:          "event wait",
   144  				Calls:          6,
   145  				Vectors:        5,
   146  				Suspends:       1,
   147  				Clocks:         1.10e4,
   148  				VectorsPerCall: 0,
   149  			},
   150  		},
   151  		{
   152  			name: "one thread",
   153  			reply: `Time 3151.2, average vectors/node 1.00, last 128 main loops 0.00 per node 0.00
   154    vector rates in 2.8561e-3, out 0.0000e0, drop 4.4428e-3, punt 0.0000e0
   155               Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call     Perf Ticks   
   156  acl-plugin-fa-cleaner-process  event wait                0               0               1          5.14e3            0.00
   157  af-packet-input               interrupt wa               9               9               0          1.55e5            1.00
   158  api-rx-from-ring                any wait                 0               0            4735          4.72e6            0.00
   159  avf-process                    event wait                0               0               1          4.52e3            0.00
   160  bfd-process                    event wait                0               0               1          6.59e3            0.00
   161  bond-process                   event wait                0               0               1          2.07e3            0.00
   162  cdp-process                     any wait                 0               0               1          4.43e3            0.00
   163  dhcp-client-process             any wait                 0               0              32          8.73e3            0.00
   164  dhcp6-client-cp-process         any wait                 0               0               1          1.94e3            0.00
   165  dhcp6-pd-client-cp-process      any wait                 0               0               1          1.73e3            0.00
   166  dhcp6-pd-reply-publisher-proce event wait                0               0               1          1.01e3            0.00
   167  dhcp6-reply-publisher-process  event wait                0               0               1          8.75e2            0.00
   168  dns-resolver-process            any wait                 0               0               4          2.11e4            0.00
   169  error-drop                       active                 14              14               0          1.29e5            1.00
   170  ethernet-input                   active                  9               9               0          6.41e5            1.00
   171  fib-walk                        any wait                 0               0            1571          2.12e4            0.00
   172  flow-report-process             any wait                 0               0               1          1.13e3            0.00
   173  flowprobe-timer-process         any wait                 0               0               1          5.27e3            0.00
   174  gbp-scanner                    event wait                0               0               1          5.36e3            0.00
   175  igmp-timer-process             event wait                0               0               1          5.24e4            0.00
   176  ikev2-manager-process           any wait                 0               0            3132          1.32e4            0.00
   177  ioam-export-process             any wait                 0               0               1          1.18e3            0.00
   178  ip-neighbor-scan-process        any wait                 0               0              53          1.49e4            0.00
   179  ip-route-resolver-process       any wait                 0               0              32          5.80e3            0.00
   180  ip4-drop                         active                  5               5               0          3.13e3            1.00
   181  ip4-local                        active                  5               5               0          1.00e4            1.00
   182  ip4-lookup                       active                  5               5               0          1.08e6            1.00
   183  ip4-reassembly-expire-walk      any wait                 0               0             315          1.27e4            0.00
   184  ip6-icmp-neighbor-discovery-ev  any wait                 0               0            3132          1.12e4            0.00
   185  ip6-input                        active                  9               9               0          3.41e3            1.00
   186  ip6-not-enabled                  active                  9               9               0          1.47e3            1.00
   187  ip6-reassembly-expire-walk      any wait                 0               0             315          8.52e3            0.00
   188  l2fib-mac-age-scanner-process  event wait                0               0               1          1.18e3            0.00
   189  lacp-process                   event wait                0               0               1          1.84e5            0.00
   190  lisp-retry-service              any wait                 0               0            1571          1.49e4            0.00
   191  lldp-process                   event wait                0               0               1          5.81e5            0.00
   192  memif-process                   any wait                 0               0            1168          1.11e5            0.00
   193  nat-det-expire-walk               done                   1               0               0          2.50e3            0.00
   194  nat64-expire-walk              event wait                0               0               1          1.34e4            0.00
   195  nsh-md2-ioam-export-process     any wait                 0               0               1          7.89e3            0.00
   196  perfmon-periodic-process       event wait                0               0               1          1.18e8            0.00
   197  rd-cp-process                   any wait                 0               0               1          1.52e3            0.00
   198  send-dhcp6-client-message-proc  any wait                 0               0               1          1.56e3            0.00
   199  send-dhcp6-pd-client-message-p  any wait                 0               0               1          1.53e3            0.00
   200  send-rs-process                 any wait                 0               0               1          1.69e3            0.00
   201  startup-config-process            done                   1               0               1          6.13e3            0.00
   202  statseg-collector-process       time wait                0               0             315          3.77e5            0.00
   203  udp-ping-process                any wait                 0               0               1          1.62e4            0.00
   204  unix-cli-127.0.0.1:39670       event wait                0               0             103          2.26e7            0.00
   205  unix-cli-127.0.0.1:40652         active                  1               0               3          4.64e9            0.00
   206  unix-epoll-input                 polling           1698354               0               0          5.00e6            0.00
   207  vhost-user-process              any wait                 0               0               1          5.29e3            0.00
   208  vhost-user-send-interrupt-proc  any wait                 0               0               1          1.88e3            0.00
   209  vpe-link-state-process         event wait                0               0              15          2.33e4            0.00
   210  vpe-oam-process                 any wait                 0               0            1540          1.21e4            0.00
   211  vxlan-gpe-ioam-export-process   any wait                 0               0               1          1.38e3            0.00
   212  wildcard-ip4-arp-publisher-pro event wait                0               0               1          2.24e3            0.00
   213  `,
   214  			threadCount: 1,
   215  			itemCount:   57,
   216  			itemIdx:     1,
   217  			item: vppcalls.RuntimeItem{
   218  				Name:           "af-packet-input",
   219  				State:          "interrupt wa",
   220  				Calls:          9,
   221  				Vectors:        9,
   222  				Suspends:       0,
   223  				Clocks:         1.55e5,
   224  				VectorsPerCall: 1,
   225  			},
   226  		},
   227  		{
   228  			name: "three threads",
   229  			reply: `Thread 0 vpp_main (lcore 0)
   230  Time 21.5, average vectors/node 0.00, last 128 main loops 0.00 per node 0.00
   231    vector rates in 0.0000e0, out 5.0000e-2, drop 0.0000e0, punt 0.0000e0
   232               Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call        
   233  acl-plugin-fa-cleaner-process  event wait                6               5               1          3.12e4            0.00
   234  api-rx-from-ring                any wait                 0               0              31          8.61e6            0.00
   235  avf-process                    event wait                0               0               1          7.79e3            0.00
   236  bfd-process                    event wait                0               0               1          6.80e3            0.00
   237  cdp-process                     any wait                 0               0               1          1.78e8            0.00
   238  dhcp-client-process             any wait                 0               0               1          2.59e3            0.00
   239  dns-resolver-process            any wait                 0               0               1          3.35e3            0.00
   240  fib-walk                        any wait                 0               0              11          1.08e4            0.00
   241  flow-report-process             any wait                 0               0               1          1.64e3            0.00
   242  flowprobe-timer-process         any wait                 0               0               1          1.16e4            0.00
   243  igmp-timer-process             event wait                0               0               1          1.81e4            0.00
   244  ikev2-manager-process           any wait                 0               0              22          5.47e3            0.00
   245  ioam-export-process             any wait                 0               0               1          3.26e3            0.00
   246  ip-route-resolver-process       any wait                 0               0               1          1.69e3            0.00
   247  ip4-reassembly-expire-walk      any wait                 0               0               3          4.27e3            0.00
   248  ip6-icmp-neighbor-discovery-ev  any wait                 0               0              22          4.48e3            0.00
   249  ip6-reassembly-expire-walk      any wait                 0               0               3          6.88e3            0.00
   250  l2fib-mac-age-scanner-process  event wait                0               0               1          3.94e3            0.00
   251  lacp-process                   event wait                0               0               1          1.35e8            0.00
   252  lisp-retry-service              any wait                 0               0              11          9.68e3            0.00
   253  lldp-process                   event wait                0               0               1          1.49e8            0.00
   254  memif-process                  event wait                0               0               1          2.67e4            0.00
   255  nat-det-expire-walk               done                   1               0               0          5.42e3            0.00
   256  nat64-expire-walk              event wait                0               0               1          5.87e4            0.00
   257  rd-cp-process                   any wait                 0               0          614363          3.93e2            0.00
   258  send-rs-process                 any wait                 0               0               1          3.22e3            0.00
   259  startup-config-process            done                   1               0               1          1.33e4            0.00
   260  udp-ping-process                any wait                 0               0               1          3.69e4            0.00
   261  unix-cli-127.0.0.1:38448         active                  0               0              23          6.72e7            0.00
   262  unix-epoll-input                 polling           8550283               0               0          3.77e3            0.00
   263  vhost-user-process              any wait                 0               0               1          2.48e3            0.00
   264  vhost-user-send-interrupt-proc  any wait                 0               0               1          1.43e3            0.00
   265  vpe-link-state-process         event wait                0               0               1          1.58e3            0.00
   266  vpe-oam-process                 any wait                 0               0              11          9.20e3            0.00
   267  vxlan-gpe-ioam-export-process   any wait                 0               0               1          1.59e4            0.00
   268  wildcard-ip4-arp-publisher-pro event wait                0               0               1          1.03e4            0.00
   269  ---------------
   270  Thread 1 vpp_wk_0 (lcore 1)
   271  Time 21.5, average vectors/node 0.00, last 128 main loops 0.00 per node 0.00
   272    vector rates in 0.0000e0, out 0.0000e0, drop 0.0000e0, punt 0.0000e0
   273               Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call     
   274  unix-epoll-input                 polling          15251181               0               0          3.67e3            0.00
   275  ---------------
   276  Thread 2 vpp_wk_1 (lcore 2)
   277  Time 21.5, average vectors/node 0.00, last 128 main loops 0.00 per node 0.00
   278    vector rates in 0.0000e0, out 0.0000e0, drop 0.0000e0, punt 0.0000e0
   279               Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call     
   280  unix-epoll-input                 polling          20563870               0               0          3.56e3            0.00
   281  `,
   282  			threadCount: 3,
   283  			itemCount:   36,
   284  			item: vppcalls.RuntimeItem{
   285  				Name:           "acl-plugin-fa-cleaner-process",
   286  				State:          "event wait",
   287  				Calls:          6,
   288  				Vectors:        5,
   289  				Suspends:       1,
   290  				Clocks:         3.12e4,
   291  				VectorsPerCall: 0,
   292  			},
   293  		},
   294  	}
   295  	for _, test := range tests {
   296  		t.Run(test.name, func(t *testing.T) {
   297  			ctx, handler := testSetup(t)
   298  			defer ctx.TeardownTestCtx()
   299  
   300  			ctx.MockVpp.MockReply(&vpe.CliInbandReply{Reply: test.reply})
   301  
   302  			info, err := handler.GetRuntimeInfo(context.TODO())
   303  
   304  			Expect(err).ShouldNot(HaveOccurred())
   305  			Expect(len(info.Threads)).To(Equal(test.threadCount))
   306  			Expect(info.Threads[0].Items).To(HaveLen(test.itemCount))
   307  			Expect(info.Threads[0].Items[test.itemIdx]).To(Equal(test.item))
   308  		})
   309  	}
   310  }
   311  
   312  func TestGetMemory(t *testing.T) {
   313  	tests := []struct {
   314  		name        string
   315  		reply       string
   316  		threadCount int
   317  		threadIdx   int
   318  		thread      vppcalls.MemoryThread
   319  	}{
   320  		{
   321  			name: "single",
   322  			reply: `Thread 0 vpp_main
   323    base 0x7f74752f2000, size 1g, locked, unmap-on-destroy, name 'main heap'
   324      page stats: page-size 4K, total 262144, mapped 14970, not-mapped 247174
   325        numa 0: 14970 pages, 58.48m bytes
   326      total: 1023.99M, used: 55.46M, free: 968.54M, trimmable: 968.53M
   327        free chunks 310 free fastbin blks 0
   328        max total allocated 1023.99M
   329  `,
   330  			threadCount: 1,
   331  			threadIdx:   0,
   332  			thread: vppcalls.MemoryThread{
   333  				ID:              0,
   334  				Name:            "vpp_main",
   335  				Size:            1e9,
   336  				Pages:           262144,
   337  				PageSize:        4000,
   338  				Used:            55.46e6,
   339  				Total:           1023.99e6,
   340  				Free:            968.54e6,
   341  				Trimmable:       968.53e6,
   342  				FreeChunks:      310,
   343  				FreeFastbinBlks: 0,
   344  				MaxTotalAlloc:   1023.99e6,
   345  			},
   346  		},
   347  		// TODO "unknown" test case fails (probably due to incorrectly updated regexp in telemetry_vppcalls.go:35)
   348  		//
   349  		// {
   350  		// 	name: "unknown",
   351  		// 	//			reply: `Thread 0 vpp_main
   352  		// 	//  base 0x7ff4bf55f000, size 1g, locked, unmap-on-destroy, name 'main heap'
   353  		// 	//    page stats: page-size 4K, total 262144, mapped 14945, not-mapped 247174, unknown 25
   354  		// 	//      numa 0: 14945 pages, 58.38m bytes
   355  		// 	//    total: 1023.99M, used: 55.46M, free: 968.54M, trimmable: 968.53M
   356  		// 	//      free chunks 303 free fastbin blks 0
   357  		// 	//      max total allocated 1023.99M
   358  		// 	//`,
   359  		// 	threadCount: 1,
   360  		// 	threadIdx:   0,
   361  		// 	thread: vppcalls.MemoryThread{
   362  		// 		ID:              0,
   363  		// 		Name:            "vpp_main",
   364  		// 		Size:            1e9,
   365  		// 		Pages:           262144,
   366  		// 		PageSize:        4000,
   367  		// 		Used:            55.46e6,
   368  		// 		Total:           1023.99e6,
   369  		// 		Free:            968.54e6,
   370  		// 		Trimmable:       968.53e6,
   371  		// 		FreeChunks:      303,
   372  		// 		FreeFastbinBlks: 0,
   373  		// 		MaxTotalAlloc:   1023.99e6,
   374  		// 	},
   375  		// },
   376  		{
   377  			name: "3 workers",
   378  			reply: `Thread 0 vpp_main
   379    base 0x7f0f14823000, size 1g, locked, unmap-on-destroy, name 'main heap'
   380      page stats: page-size 4K, total 262144, mapped 19483, not-mapped 242661
   381        numa 0: 19483 pages, 76.11m bytes
   382      total: 1023.99M, used: 72.26M, free: 951.74M, trimmable: 950.90M
   383        free chunks 298 free fastbin blks 0
   384        max total allocated 1023.99M
   385  
   386  Thread 1 vpp_wk_0
   387    base 0x7f0f14823000, size 1g, locked, unmap-on-destroy, name 'main heap'
   388      page stats: page-size 4K, total 262144, mapped 19483, not-mapped 242661
   389        numa 0: 19483 pages, 76.11m bytes
   390      total: 1023.99M, used: 72.26M, free: 951.74M, trimmable: 950.90M
   391        free chunks 299 free fastbin blks 0
   392        max total allocated 1023.99M
   393  
   394  Thread 2 vpp_wk_1
   395    base 0x7f0f14823000, size 1g, locked, unmap-on-destroy, name 'main heap'
   396      page stats: page-size 4K, total 262144, mapped 19483, not-mapped 242661
   397        numa 0: 19483 pages, 76.11m bytes
   398      total: 1023.99M, used: 72.26M, free: 951.74M, trimmable: 950.90M
   399        free chunks 299 free fastbin blks 0
   400        max total allocated 1023.99M
   401  
   402  Thread 3 vpp_wk_2
   403    base 0x7f0f14823000, size 1g, locked, unmap-on-destroy, name 'main heap'
   404      page stats: page-size 4K, total 262144, mapped 19483, not-mapped 242661
   405        numa 0: 19483 pages, 76.11m bytes
   406      total: 1023.99M, used: 72.26M, free: 951.74M, trimmable: 950.90M
   407        free chunks 299 free fastbin blks 0
   408        max total allocated 1023.99M
   409  `,
   410  			threadCount: 4,
   411  			threadIdx:   1,
   412  			thread: vppcalls.MemoryThread{
   413  				ID:              1,
   414  				Name:            "vpp_wk_0",
   415  				Size:            1.e9,
   416  				Pages:           262144,
   417  				PageSize:        4000,
   418  				Used:            72.26e6,
   419  				Total:           1023.99e6,
   420  				Free:            951.74e6,
   421  				Trimmable:       950.90e6,
   422  				FreeChunks:      299,
   423  				FreeFastbinBlks: 0,
   424  				MaxTotalAlloc:   1023.99e6,
   425  			},
   426  		},
   427  		// TODO "19.08 update" test case tests for "page information not available" error.
   428  		// It contains reply from VPP version 20.09. The format of replies changed
   429  		// since VPP version 21.01, so the test case should be updated accordingly.
   430  		//
   431  		// {
   432  		// 	name: "19.08 update",
   433  		// //			reply: `Thread 0 vpp_main
   434  		// //  virtual memory start 0x7fc363c20000, size 1048640k, 262160 pages, page size 4k
   435  		// //    page information not available (errno 1)
   436  		// //  total: 1.00G, used: 56.78M, free: 967.29M, trimmable: 966.64M
   437  		// //    free chunks 337 free fastbin blks 0
   438  		// //    max total allocated 1.00G
   439  		// //`,
   440  		// 	threadCount: 1,
   441  		// 	threadIdx:   0,
   442  		// 	thread: vppcalls.MemoryThread{
   443  		// 		ID:              0,
   444  		// 		Name:            "vpp_main",
   445  		// 		Size:            1048.64e6,
   446  		// 		Pages:           262160,
   447  		// 		PageSize:        4000,
   448  		// 		Used:            56.78e6,
   449  		// 		Total:           1e9,
   450  		// 		Free:            967.29e6,
   451  		// 		Trimmable:       966.64e6,
   452  		// 		FreeChunks:      337,
   453  		// 		FreeFastbinBlks: 0,
   454  		// 		MaxTotalAlloc:   1e9,
   455  		// 	},
   456  		// },
   457  	}
   458  	for _, test := range tests {
   459  		t.Run(test.name, func(t *testing.T) {
   460  			ctx, handler := testSetup(t)
   461  			defer ctx.TeardownTestCtx()
   462  
   463  			ctx.MockVpp.MockReply(&vpe.CliInbandReply{Reply: test.reply})
   464  
   465  			info, err := handler.GetMemory(context.TODO())
   466  
   467  			Expect(err).ShouldNot(HaveOccurred())
   468  			Expect(info.Threads).To(HaveLen(test.threadCount))
   469  			Expect(info.Threads[test.threadIdx]).To(Equal(test.thread))
   470  		})
   471  	}
   472  }
   473  
   474  func TestGetNodeCounters(t *testing.T) {
   475  	ctx, handler := testSetup(t)
   476  	defer ctx.TeardownTestCtx()
   477  
   478  	const reply = `   Count                    Node                  Reason
   479          32            ipsec-output-ip4            IPSec policy protect
   480          32               esp-encrypt              ESP pkts received
   481          64             ipsec-input-ip4            IPSEC pkts received
   482          32             ip4-icmp-input             unknown type
   483          32             ip4-icmp-input             echo replies sent
   484          14             ethernet-input             l3 mac mismatch
   485           1                arp-input               ARP replies sent
   486           4                ip4-input               ip4 spoofed local-address packet drops
   487           2             memif1/1-output            interface is down
   488           1                cdp-input               good cdp packets (processed)
   489  `
   490  	ctx.MockVpp.MockReply(&vpe.CliInbandReply{
   491  		Reply: reply,
   492  	})
   493  
   494  	info, err := handler.GetNodeCounters(context.TODO())
   495  
   496  	Expect(err).ShouldNot(HaveOccurred())
   497  	Expect(info.Counters).To(HaveLen(10))
   498  	Expect(info.Counters[0]).To(Equal(vppcalls.NodeCounter{
   499  		Value: 32,
   500  		Node:  "ipsec-output-ip4",
   501  		Name:  "IPSec policy protect",
   502  	}))
   503  	Expect(info.Counters[6]).To(Equal(vppcalls.NodeCounter{
   504  		Value: 1,
   505  		Node:  "arp-input",
   506  		Name:  "ARP replies sent",
   507  	}))
   508  	Expect(info.Counters[7]).To(Equal(vppcalls.NodeCounter{
   509  		Value: 4,
   510  		Node:  "ip4-input",
   511  		Name:  "ip4 spoofed local-address packet drops",
   512  	}))
   513  	Expect(info.Counters[8]).To(Equal(vppcalls.NodeCounter{
   514  		Value: 2,
   515  		Node:  "memif1/1-output",
   516  		Name:  "interface is down",
   517  	}))
   518  	Expect(info.Counters[9]).To(Equal(vppcalls.NodeCounter{
   519  		Value: 1,
   520  		Node:  "cdp-input",
   521  		Name:  "good cdp packets (processed)",
   522  	}))
   523  }
   524  
   525  func testSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.TelemetryVppAPI) {
   526  	ctx := vppmock.SetupTestCtx(t)
   527  	handler := vpp2101.NewTelemetryVppHandler(ctx.MockVPPClient)
   528  	return ctx, handler
   529  }