5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-25 21:51:38 +00:00

Show queue capacity in getSwitchQueues

This commit is contained in:
Neil Alexander 2018-09-27 16:19:47 +01:00
parent 7d8a1859f0
commit 69cd736112
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 29 additions and 19 deletions

View File

@ -542,8 +542,9 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo {
{"queues", queues}, {"queues", queues},
{"queues_count", len(switchTable.queues.bufs)}, {"queues_count", len(switchTable.queues.bufs)},
{"queues_size", switchTable.queues.size}, {"queues_size", switchTable.queues.size},
{"max_queues_count", switchTable.queues.maxbufs}, {"highest_queues_count", switchTable.queues.maxbufs},
{"max_queues_size", switchTable.queues.maxsize}, {"highest_queues_size", switchTable.queues.maxsize},
{"maximum_queues_size", switch_buffer_maxSize},
} }
} }
a.core.switchTable.doAdmin(getSwitchQueues) a.core.switchTable.doAdmin(getSwitchQueues)

View File

@ -601,6 +601,8 @@ type switch_packetInfo struct {
time time.Time // Timestamp of when the packet arrived time time.Time // Timestamp of when the packet arrived
} }
const switch_buffer_maxSize = 4 * 1048576 // Maximum 4 MB
// Used to keep track of buffered packets // Used to keep track of buffered packets
type switch_buffer struct { type switch_buffer struct {
packets []switch_packetInfo // Currently buffered packets, which may be dropped if it grows too large packets []switch_packetInfo // Currently buffered packets, which may be dropped if it grows too large
@ -627,8 +629,8 @@ func (b *switch_buffers) cleanup(t *switchTable) {
delete(b.bufs, streamID) delete(b.bufs, streamID)
} }
} }
const maxSize = 4 * 1048576 // Maximum 4 MB
for b.size > maxSize { for b.size > switch_buffer_maxSize {
// Drop a random queue // Drop a random queue
target := rand.Uint64() % b.size target := rand.Uint64() % b.size
var size uint64 // running total var size uint64 // running total

View File

@ -184,44 +184,51 @@ func main() {
} }
} }
case "getswitchqueues": case "getswitchqueues":
maximumqueuesize := float64(4194304)
portqueues := make(map[float64]float64)
portqueuesize := make(map[float64]float64) portqueuesize := make(map[float64]float64)
portqueuepackets := make(map[float64]float64) portqueuepackets := make(map[float64]float64)
v := res["switchqueues"].(map[string]interface{}) v := res["switchqueues"].(map[string]interface{})
if queuecount, ok := v["queues_count"].(float64); ok { if queuecount, ok := v["queues_count"].(float64); ok {
fmt.Printf("Active queue count: %d\n", uint(queuecount)) fmt.Printf("Active queue count: %d queues\n", uint(queuecount))
} }
if queuesize, ok := v["queues_size"].(float64); ok { if queuesize, ok := v["queues_size"].(float64); ok {
fmt.Printf("Active queue size: %d\n", uint(queuesize)) fmt.Printf("Active queue size: %d bytes\n", uint(queuesize))
} }
if maxqueuecount, ok := v["max_queues_count"].(float64); ok { if highestqueuecount, ok := v["highest_queues_count"].(float64); ok {
fmt.Printf("Highest queue count: %d\n", uint(maxqueuecount)) fmt.Printf("Highest queue count: %d queues\n", uint(highestqueuecount))
} }
if maxqueuesize, ok := v["max_queues_size"].(float64); ok { if highestqueuesize, ok := v["highest_queues_size"].(float64); ok {
fmt.Printf("Highest queue size: %d\n", uint(maxqueuesize)) fmt.Printf("Highest queue size: %d bytes\n", uint(highestqueuesize))
}
if m, ok := v["maximum_queues_size"].(float64); ok {
fmt.Printf("Maximum queue size: %d bytes\n", uint(maximumqueuesize))
maximumqueuesize = m
} }
if queues, ok := v["queues"].([]interface{}); ok { if queues, ok := v["queues"].([]interface{}); ok {
if len(queues) == 0 { if len(queues) != 0 {
fmt.Println("No active queues")
return
} else {
fmt.Println("Active queues:") fmt.Println("Active queues:")
for _, v := range queues { for _, v := range queues {
queueport := v.(map[string]interface{})["queue_port"].(float64) queueport := v.(map[string]interface{})["queue_port"].(float64)
queuesize := v.(map[string]interface{})["queue_size"].(float64) queuesize := v.(map[string]interface{})["queue_size"].(float64)
queuepackets := v.(map[string]interface{})["queue_packets"].(float64) queuepackets := v.(map[string]interface{})["queue_packets"].(float64)
queueid := v.(map[string]interface{})["queue_id"].(string) queueid := v.(map[string]interface{})["queue_id"].(string)
portqueues[queueport] += 1
portqueuesize[queueport] += queuesize portqueuesize[queueport] += queuesize
portqueuepackets[queueport] += queuepackets portqueuepackets[queueport] += queuepackets
fmt.Printf("- Switch port %d, Stream ID: %v, size: %d, packets: %d\n", queuesizepercent := (100 / maximumqueuesize) * queuesize
uint(queueport), []byte(queueid), uint(queuesize), uint(queuepackets)) fmt.Printf("- Switch port %d, Stream ID: %v, size: %d bytes (%d%% full), %d packets\n",
uint(queueport), []byte(queueid), uint(queuesize),
uint(queuesizepercent), uint(queuepackets))
} }
} }
} }
if len(portqueuesize) > 0 && len(portqueuepackets) > 0 { if len(portqueuesize) > 0 && len(portqueuepackets) > 0 {
fmt.Println("Queue statistics by switchport:") fmt.Println("Aggregated statistics by switchport:")
for k, v := range portqueuesize { for k, v := range portqueuesize {
fmt.Printf("- Switch port %d, size: %d, packets: %d\n", queuesizepercent := (100 / (portqueues[k] * maximumqueuesize)) * v
uint(k), uint(v), uint(portqueuepackets[k])) fmt.Printf("- Switch port %d, size: %d bytes (%d%% full), %d packets\n",
uint(k), uint(v), uint(queuesizepercent), uint(portqueuepackets[k]))
} }
} }
case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey": case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey":