mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Remove bandwidth monitoring functionality made obsolete by VLAN trunking to SCCs.
This commit is contained in:
@@ -20,7 +20,6 @@ CREATE TABLE event_settings (
|
||||
apadminwpakey VARCHAR(255),
|
||||
switchaddress VARCHAR(255),
|
||||
switchpassword VARCHAR(255),
|
||||
bandwidthmonitoringenabled bool,
|
||||
plcaddress VARCHAR(255),
|
||||
tbadownloadenabled bool,
|
||||
adminpassword VARCHAR(255),
|
||||
|
||||
@@ -507,7 +507,6 @@ func (arena *Arena) Run() {
|
||||
// Start other loops in goroutines.
|
||||
go arena.listenForDriverStations()
|
||||
go arena.listenForDsUdpPackets()
|
||||
go arena.monitorBandwidth()
|
||||
go arena.Plc.Run()
|
||||
|
||||
for {
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
// Copyright 2015 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Methods for monitoring team bandwidth usage across a managed switch.
|
||||
|
||||
package field
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cdevr/WapSNMP"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
monitoringIntervalMs = 1000
|
||||
toRobotBytesOid = ".1.3.6.1.2.1.2.2.1.10"
|
||||
fromRobotBytesOid = ".1.3.6.1.2.1.2.2.1.16"
|
||||
red1Port = 6
|
||||
red2Port = 8
|
||||
red3Port = 10
|
||||
blue1Port = 12
|
||||
blue2Port = 14
|
||||
blue3Port = 16
|
||||
)
|
||||
|
||||
type BandwidthMonitor struct {
|
||||
allianceStations *map[string]*AllianceStation
|
||||
snmpClient *wapsnmp.WapSNMP
|
||||
toRobotOids []wapsnmp.Oid
|
||||
fromRobotOids []wapsnmp.Oid
|
||||
lastToRobotBytes map[string]interface{}
|
||||
lastFromRobotBytes map[string]interface{}
|
||||
lastBytesTime time.Time
|
||||
}
|
||||
|
||||
// Loops indefinitely to query the managed switch via SNMP (Simple Network Management Protocol).
|
||||
func (arena *Arena) monitorBandwidth() {
|
||||
monitor := BandwidthMonitor{allianceStations: &arena.AllianceStations}
|
||||
|
||||
for _, port := range []int{red1Port, red2Port, red3Port, blue1Port, blue2Port, blue3Port} {
|
||||
toOid := fmt.Sprintf("%s.%d", toRobotBytesOid, 10100+port)
|
||||
fromOid := fmt.Sprintf("%s.%d", fromRobotBytesOid, 10100+port)
|
||||
monitor.toRobotOids = append(monitor.toRobotOids, wapsnmp.MustParseOid(toOid))
|
||||
monitor.fromRobotOids = append(monitor.fromRobotOids, wapsnmp.MustParseOid(fromOid))
|
||||
}
|
||||
|
||||
for {
|
||||
if monitor.snmpClient != nil && monitor.snmpClient.Target != arena.EventSettings.SwitchAddress {
|
||||
// Switch address has changed; must re-create the SNMP client.
|
||||
monitor.snmpClient.Close()
|
||||
monitor.snmpClient = nil
|
||||
}
|
||||
|
||||
if monitor.snmpClient == nil {
|
||||
var err error
|
||||
monitor.snmpClient, err = wapsnmp.NewWapSNMP(arena.EventSettings.SwitchAddress,
|
||||
arena.EventSettings.SwitchPassword, wapsnmp.SNMPv2c, 2*time.Second, 0)
|
||||
if err != nil {
|
||||
log.Printf("Error starting bandwidth monitoring: %v", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if arena.EventSettings.NetworkSecurityEnabled && arena.EventSettings.BandwidthMonitoringEnabled {
|
||||
err := monitor.updateBandwidth()
|
||||
if err != nil {
|
||||
log.Printf("Bandwidth monitoring error: %v", err)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * monitoringIntervalMs)
|
||||
}
|
||||
}
|
||||
|
||||
func (monitor *BandwidthMonitor) updateBandwidth() error {
|
||||
// Retrieve total number of bytes sent/received per port.
|
||||
toRobotBytes, err := monitor.snmpClient.GetMultiple(monitor.toRobotOids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fromRobotBytes, err := monitor.snmpClient.GetMultiple(monitor.fromRobotOids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Calculate the bandwidth usage over time.
|
||||
monitor.updateStationBandwidth("R1", 0, toRobotBytes, fromRobotBytes)
|
||||
monitor.updateStationBandwidth("R2", 1, toRobotBytes, fromRobotBytes)
|
||||
monitor.updateStationBandwidth("R3", 2, toRobotBytes, fromRobotBytes)
|
||||
monitor.updateStationBandwidth("B1", 3, toRobotBytes, fromRobotBytes)
|
||||
monitor.updateStationBandwidth("B2", 4, toRobotBytes, fromRobotBytes)
|
||||
monitor.updateStationBandwidth("B3", 5, toRobotBytes, fromRobotBytes)
|
||||
|
||||
monitor.lastToRobotBytes = toRobotBytes
|
||||
monitor.lastFromRobotBytes = fromRobotBytes
|
||||
monitor.lastBytesTime = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (monitor *BandwidthMonitor) updateStationBandwidth(station string, oidIndex int, toRobotBytes map[string]interface{},
|
||||
fromRobotBytes map[string]interface{}) {
|
||||
dsConn := (*monitor.allianceStations)[station].DsConn
|
||||
if dsConn == nil {
|
||||
// No team assigned; just skip it.
|
||||
return
|
||||
}
|
||||
secondsSinceLast := time.Now().Sub(monitor.lastBytesTime).Seconds()
|
||||
|
||||
toOid := monitor.toRobotOids[oidIndex].String()
|
||||
if _, ok := toRobotBytes[toOid]; !ok {
|
||||
log.Printf("Error: OID %s not present in new to-robot stats %v.", toOid, toRobotBytes)
|
||||
return
|
||||
}
|
||||
toRobotBytesForPort := uint32(toRobotBytes[toOid].(wapsnmp.Counter))
|
||||
if _, ok := monitor.lastToRobotBytes[toOid]; !ok {
|
||||
// This may be the first time reading.
|
||||
return
|
||||
}
|
||||
lastToRobotBytesForPort := uint32(monitor.lastToRobotBytes[toOid].(wapsnmp.Counter))
|
||||
dsConn.MBpsToRobot = float64(toRobotBytesForPort-lastToRobotBytesForPort) / 1024 / 128 / secondsSinceLast
|
||||
|
||||
fromOid := monitor.fromRobotOids[oidIndex].String()
|
||||
if _, ok := fromRobotBytes[fromOid]; !ok {
|
||||
log.Printf("Error: OID %s not present in new from-robot stats %v.", fromOid, fromRobotBytes)
|
||||
return
|
||||
}
|
||||
fromRobotBytesForPort := uint32(fromRobotBytes[fromOid].(wapsnmp.Counter))
|
||||
if _, ok := monitor.lastFromRobotBytes[fromOid]; !ok {
|
||||
// This may be the first time reading.
|
||||
return
|
||||
}
|
||||
lastFromRobotBytesForPort := uint32(monitor.lastFromRobotBytes[fromOid].(wapsnmp.Counter))
|
||||
dsConn.MBpsFromRobot = float64(fromRobotBytesForPort-lastFromRobotBytesForPort) / 1024 / 128 / secondsSinceLast
|
||||
}
|
||||
@@ -39,8 +39,6 @@ type DriverStationConnection struct {
|
||||
BatteryVoltage float64
|
||||
DsRobotTripTimeMs int
|
||||
MissedPacketCount int
|
||||
MBpsToRobot float64
|
||||
MBpsFromRobot float64
|
||||
SecondsSinceLastRobotLink float64
|
||||
lastPacketTime time.Time
|
||||
lastRobotLinkedTime time.Time
|
||||
@@ -120,8 +118,6 @@ func (dsConn *DriverStationConnection) update(arena *Arena) error {
|
||||
dsConn.RadioLinked = false
|
||||
dsConn.RobotLinked = false
|
||||
dsConn.BatteryVoltage = 0
|
||||
dsConn.MBpsToRobot = 0
|
||||
dsConn.MBpsFromRobot = 0
|
||||
}
|
||||
dsConn.SecondsSinceLastRobotLink = time.Since(dsConn.lastRobotLinkedTime).Seconds()
|
||||
|
||||
|
||||
@@ -6,37 +6,36 @@
|
||||
package model
|
||||
|
||||
type EventSettings struct {
|
||||
Id int
|
||||
Name string
|
||||
DisplayBackgroundColor string
|
||||
NumElimAlliances int
|
||||
SelectionRound2Order string
|
||||
SelectionRound3Order string
|
||||
TBADownloadEnabled bool
|
||||
TbaPublishingEnabled bool
|
||||
TbaEventCode string
|
||||
TbaSecretId string
|
||||
TbaSecret string
|
||||
NetworkSecurityEnabled bool
|
||||
ApAddress string
|
||||
ApUsername string
|
||||
ApPassword string
|
||||
ApTeamChannel int
|
||||
ApAdminChannel int
|
||||
ApAdminWpaKey string
|
||||
SwitchAddress string
|
||||
SwitchPassword string
|
||||
BandwidthMonitoringEnabled bool
|
||||
PlcAddress string
|
||||
AdminPassword string
|
||||
ReaderPassword string
|
||||
StemTvPublishingEnabled bool
|
||||
StemTvEventCode string
|
||||
ScaleLedAddress string
|
||||
RedSwitchLedAddress string
|
||||
BlueSwitchLedAddress string
|
||||
RedVaultLedAddress string
|
||||
BlueVaultLedAddress string
|
||||
Id int
|
||||
Name string
|
||||
DisplayBackgroundColor string
|
||||
NumElimAlliances int
|
||||
SelectionRound2Order string
|
||||
SelectionRound3Order string
|
||||
TBADownloadEnabled bool
|
||||
TbaPublishingEnabled bool
|
||||
TbaEventCode string
|
||||
TbaSecretId string
|
||||
TbaSecret string
|
||||
NetworkSecurityEnabled bool
|
||||
ApAddress string
|
||||
ApUsername string
|
||||
ApPassword string
|
||||
ApTeamChannel int
|
||||
ApAdminChannel int
|
||||
ApAdminWpaKey string
|
||||
SwitchAddress string
|
||||
SwitchPassword string
|
||||
PlcAddress string
|
||||
AdminPassword string
|
||||
ReaderPassword string
|
||||
StemTvPublishingEnabled bool
|
||||
StemTvEventCode string
|
||||
ScaleLedAddress string
|
||||
RedSwitchLedAddress string
|
||||
BlueSwitchLedAddress string
|
||||
RedVaultLedAddress string
|
||||
BlueVaultLedAddress string
|
||||
}
|
||||
|
||||
const eventSettingsId = 0
|
||||
|
||||
@@ -19,7 +19,6 @@ var handleArenaStatus = function(data) {
|
||||
if (stationStatus.DsConn) {
|
||||
var dsConn = stationStatus.DsConn;
|
||||
$("#status" + station + " .ds-status").attr("data-status-ok", dsConn.DsLinked);
|
||||
$("#status" + station + " .ds-status").text(dsConn.MBpsToRobot.toFixed(1) + "/" + dsConn.MBpsFromRobot.toFixed(1));
|
||||
$("#status" + station + " .radio-status").attr("data-status-ok", dsConn.RadioLinked);
|
||||
$("#status" + station + " .robot-status").attr("data-status-ok", dsConn.RobotLinked);
|
||||
if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) {
|
||||
|
||||
@@ -65,7 +65,6 @@ var handleArenaStatus = function(data) {
|
||||
if (stationStatus.DsConn) {
|
||||
var dsConn = stationStatus.DsConn;
|
||||
$("#status" + station + " .ds-status").attr("data-status-ok", dsConn.DsLinked);
|
||||
$("#status" + station + " .ds-status").text(dsConn.MBpsToRobot.toFixed(1) + "/" + dsConn.MBpsFromRobot.toFixed(1));
|
||||
$("#status" + station + " .robot-status").attr("data-status-ok", dsConn.RobotLinked);
|
||||
if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) {
|
||||
$("#status" + station + " .robot-status").text(stationStatus.DsConn.SecondsSinceLastRobotLink.toFixed());
|
||||
|
||||
@@ -223,12 +223,6 @@
|
||||
<input type="password" class="form-control" name="switchPassword" value="{{.SwitchPassword}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-7 control-label">Enable bandwidth monitoring</label>
|
||||
<div class="col-lg-1 checkbox">
|
||||
<input type="checkbox" name="bandwidthMonitoringEnabled"{{if .BandwidthMonitoringEnabled}} checked{{end}}>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>PLC</legend>
|
||||
|
||||
@@ -66,7 +66,6 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
eventSettings.ApAdminWpaKey = r.PostFormValue("apAdminWpaKey")
|
||||
eventSettings.SwitchAddress = r.PostFormValue("switchAddress")
|
||||
eventSettings.SwitchPassword = r.PostFormValue("switchPassword")
|
||||
eventSettings.BandwidthMonitoringEnabled = r.PostFormValue("bandwidthMonitoringEnabled") == "on"
|
||||
eventSettings.PlcAddress = r.PostFormValue("plcAddress")
|
||||
eventSettings.AdminPassword = r.PostFormValue("adminPassword")
|
||||
eventSettings.ReaderPassword = r.PostFormValue("readerPassword")
|
||||
|
||||
Reference in New Issue
Block a user