Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "show queue-monitor length" command. #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions module/queue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// Copyright (c) 2015-2016, Arista Networks, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Arista Networks nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

package module

import "fmt"

// ShowQueueMonitor represents "show queue-monitor length" output
type ShowQueueMonitor struct {
Cmd string
ReportTime float64 `json:"report_time"`
Warnings string `json:"warnings"`
BytesPerTxmpSegment uint `json:"bytes_per_txmp_segment"`
GlobalHitCount uint `json:"global_hit_count"`
LanzEnabled bool `json:"lanz_enabled"`
PlatformName string `json:"platform_name"`
EntryList []*Entry `json:"entry_list"`
}

// Entry is queueing event entry from the ShowQueueMonitor output:
// Type Time Intf(TC) Queue Duration Ingress
// Length Port-set
// (bytes) (usecs)
//---------- ----------------------- --------------- ------------- ---------------- ------------------------------------------------
// P 0:00:03.83243 ago Et24/1(2) 41904 1000000 Et3/1,4/1,5/1,8/1,9/1,10/1,25/1,26/1,30/1
type Entry struct {
EntryTimeUsecs int64 `json:"entry_time_usecs"`
GlobalProtectionModeEnabled bool `json:"global_protection_mode_enabled"`
EntryTime float64 `json:"entry_time"`
Interface string `json:"interface"`
Duration uint `json:"duration"`
DurationUsecs uint32 `json:"duration_usecs"`
EntryType string `json:"entry_type"`
QueueLength uint32 `json:"queue_length"`
TrafficClass uint `json:"traffic_class"`
IngressPortSet []string `json:"ingress_port_set"`
}

func (l *ShowQueueMonitor) SetCmd(port string, limit bool, limitBy string, limitValue int) {
base := "show queue-monitor length"
if limit {
l.Cmd = fmt.Sprintf("%s %s limit %d %s", base, port, limitValue, limitBy)
} else {
l.Cmd = fmt.Sprintf("%s %s", base, port)
}
}

func (l *ShowQueueMonitor) GetCmd() string {
return l.Cmd
}

func (s *ShowEntity) ShowQueueMonitor(port string, limit bool, limitBy string, limitValue int) (ShowQueueMonitor, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only request I would make relates to the method name. It may be better to rename this ShowQueueMonitorWithLimit() and remove the requirement for limit bool. You could then have another method ShowQueueMonitor() that performs the underlying call to SetCmd() with no limit set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied. There are two methods now as requested:
ShowQueueMonitorWithLimit()
ShowQueueMonitor()

show := module.Show(node)
showqueue, _ := show.ShowQueueMonitor("Et24/1")

or
show := module.Show(node)
showqueue, _ := show.ShowQueueMonitorWithLimit("Et24/1", "seconds", 60)

or
showqueueLimit := &module.ShowQueueMonitor{}
showqueueLimit.SetCmd("Et24/1", "seconds", 10)
showqueueNoLimit := &module.ShowQueueMonitor{}
showqueueNoLimit.SetCmd("Et24/1", "", 0)

showqueuemonitor := ShowQueueMonitor{}
showqueuemonitor.SetCmd(port, limit, limitBy, limitValue)

handle, err := s.node.GetHandle("json")
if err != nil {
return showqueuemonitor, err
}

err = handle.AddCommand(&showqueuemonitor)
if err != nil {
return showqueuemonitor, err
}

err = handle.Call()
if err != nil {
return showqueuemonitor, err
}

handle.Close()
return showqueuemonitor, nil
}
203 changes: 203 additions & 0 deletions module/queue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package module

import (
"reflect"
"testing"

"github.com/aristanetworks/goeapi"
)

func TestShowQueueMonitor_UnitTest(t *testing.T) {
var dummyNode *goeapi.Node
var dummyConnection *DummyConnection

dummyConnection = &DummyConnection{}

dummyNode = &goeapi.Node{}
dummyNode.SetConnection(dummyConnection)

show := Show(dummyNode)
showqueue, _ := show.ShowQueueMonitor("", false, "", 0)

type ShowQueueMonitor struct {
Cmd string
ReportTime float64 `json:"report_time"`
Warnings string `json:"warnings"`
BytesPerTxmpSegment uint `json:"bytes_per_txmp_segment"`
GlobalHitCount uint `json:"global_hit_count"`
LanzEnabled bool `json:"lanz_enabled"`
PlatformName string `json:"platform_name"`
EntryList []*Entry `json:"entry_list"`
}

type Entry struct {
EntryTimeUsecs int64 `json:"entry_time_usecs"`
GlobalProtectionModeEnabled bool `json:"global_protection_mode_enabled"`
EntryTime float64 `json:"entry_time"`
Interface string `json:"interface"`
Duration uint `json:"duration"`
DurationUsecs uint32 `json:"duration_usecs"`
EntryType string `json:"entry_type"`
QueueLength uint32 `json:"queue_length"`
TrafficClass uint `json:"traffic_class"`
IngressPortSet []string `json:"ingress_port_set"`
}

var scenarios = []struct {
GlobalHitCount uint
LanzEnabled bool
PlatformName string
EntryList []*Entry
}{
{
GlobalHitCount: 0,
LanzEnabled: true,
PlatformName: "Sand",
EntryList: []*Entry{
{
EntryTimeUsecs: 1568892560445182,
GlobalProtectionModeEnabled: true,
EntryTime: 1568892560.445182,
Interface: "Ethernet24",
EntryType: "P",
QueueLength: 73520,
IngressPortSet: []string{
"Ethernet4/1",
"Ethernet8/1",
"Ethernet26/1",
"Ethernet30/1",
"Ethernet10/1",
"Ethernet25/1",
"Ethernet5/1",
"Ethernet9/1",
"Ethernet3/1",
},
},
{
EntryTimeUsecs: 1568892557441976,
GlobalProtectionModeEnabled: true,
EntryTime: 1568892557.441976,
Interface: "Ethernet24/1",
EntryType: "P",
QueueLength: 489744,
IngressPortSet: []string{
"Ethernet24/3",
"Ethernet13/1",
"Ethernet35/1",
"Ethernet23/1",
"Ethernet33/1",
"Ethernet19/1",
"Ethernet14/1",
"Ethernet18/1",
"Ethernet24/1",
"Ethernet34/1",
"Ethernet24/4",
"Ethernet24/2",
},
},
{
EntryTimeUsecs: 1568892549432686,
GlobalProtectionModeEnabled: true,
EntryTime: 1568892549.432686,
Interface: "Ethernet24/1",
EntryType: "P",
QueueLength: 46384,
IngressPortSet: []string{
"Ethernet4/1",
"Ethernet8/1",
"Ethernet26/1",
"Ethernet30/1",
"Ethernet10/1",
"Ethernet25/1",
"Ethernet5/1",
"Ethernet9/1",
"Ethernet3/1",
},
},
{
EntryTimeUsecs: 1568892541423988,
GlobalProtectionModeEnabled: true,
EntryTime: 1568892541.423988,
Interface: "Ethernet24/1",
EntryType: "P",
QueueLength: 247568,
IngressPortSet: []string{
"Ethernet24/3",
"Ethernet13/1",
"Ethernet35/1",
"Ethernet23/1",
"Ethernet33/1",
"Ethernet19/1",
"Ethernet14/1",
"Ethernet18/1",
"Ethernet24/1",
"Ethernet34/1",
"Ethernet24/4",
"Ethernet24/2",
},
},
},
},
}

entries := showqueue.EntryList

for _, tt := range scenarios {
if tt.LanzEnabled != showqueue.LanzEnabled {
t.Errorf("Lanz is disabled, which does not match expected %t, got %t", tt.LanzEnabled,
showqueue.LanzEnabled)
}
if tt.PlatformName != showqueue.PlatformName {
t.Errorf("Platform name doesn't match expected %s, got %s", tt.PlatformName, showqueue.PlatformName)
}
for idx, entry := range tt.EntryList {
if entry.EntryTime != entries[idx].EntryTime {
t.Errorf("Entry time does not match expected %f, got %f",
entry.EntryTime, entries[idx].EntryTime)
}
if entry.EntryType != entries[idx].EntryType {
t.Errorf("Entry type does not match expected %s, got %s",
entry.EntryType, entries[idx].EntryType)
}
if entry.QueueLength != entries[idx].QueueLength {
t.Errorf("Queue Length does not match expected %d, got %d",
entry.QueueLength, entries[idx].QueueLength)
}
if !reflect.DeepEqual(entry.IngressPortSet, entries[idx].IngressPortSet) {
t.Errorf("Ingres Port set does not match expected %v, got %v",
entry.IngressPortSet, entries[idx].IngressPortSet)
}
}
}

showqueue, _ = show.ShowQueueMonitor("Et24", true, "samples", 2)
entries = showqueue.EntryList

for _, tt := range scenarios {
if tt.LanzEnabled != showqueue.LanzEnabled {
t.Errorf("Lanz is disabled, which does not match expected %t, got %t", tt.LanzEnabled,
showqueue.LanzEnabled)
}
if tt.PlatformName != showqueue.PlatformName {
t.Errorf("Platform name doesn't match expected %s, got %s", tt.PlatformName, showqueue.PlatformName)
}
for idx, entry := range tt.EntryList {
if entry.EntryTime != entries[idx].EntryTime {
t.Errorf("Entry time does not match expected %f, got %f",
entry.EntryTime, entries[idx].EntryTime)
}
if entry.EntryType != entries[idx].EntryType {
t.Errorf("Entry type does not match expected %s, got %s",
entry.EntryType, entries[idx].EntryType)
}
if entry.QueueLength != entries[idx].QueueLength {
t.Errorf("Queue Length does not match expected %d, got %d",
entry.QueueLength, entries[idx].QueueLength)
}
if !reflect.DeepEqual(entry.IngressPortSet, entries[idx].IngressPortSet) {
t.Errorf("Ingres Port set does not match expected %v, got %v",
entry.IngressPortSet, entries[idx].IngressPortSet)
}
}
}
}
4 changes: 2 additions & 2 deletions testdata/fixtures/running_config.text
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ ip msdp timer 30
!
lacp system-priority 32768
!
no queue-monitor length
queue-monitor length
!
queue-monitor length global-buffer thresholds 512 256
no queue-monitor length mirror
queue-monitor length mirror
!
queue-monitor length global-buffer
!
Expand Down
Loading