Skip to content

Commit

Permalink
Fix downstream_max/upstream_max for cable devices
Browse files Browse the repository at this point in the history
Implements a new query algorithm for the methods downstream_max and
upstream_max. The new algorithm will now perform multiple queries since
the needed information to calculate the values for the methods
downstream_max and upstream_max can be stored in additional sync groups.
The first query will always determine how many sync groups are found. If
only one sync group is found the result from this query will be used for
calculation, if multiple sync groups are found the algorithm queries all
sync groups but stops when a supported sync group mode is found.
Currently only the sync group modes VDSL and CABLE are supported.

refs #72
  • Loading branch information
mcktr committed Jun 9, 2020
1 parent 894645f commit 7e28e2c
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 18 deletions.
77 changes: 68 additions & 9 deletions cmd/check_fritz/check_downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,86 @@ import (

// CheckDownstreamMax checks the maximum downstream that is available on this internet connection
func CheckDownstreamMax(aI ArgumentInformation) {
// Start of the initial request to get the total number of sync groups; we always start with group id 0
resps := make(chan []byte)
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)
initialSoapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
initialSoapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&initialSoapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
initialResponse, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)

if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

downstream, err := strconv.ParseFloat(soapResp.NewMaxDS, 64)
initialSoapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&initialSoapResp, initialResponse)

// Query the total number of sync groups
totalSyncGroups, err := strconv.Atoi(initialSoapResp.NewTotalNumberSyncGroups)
if err != nil {
panic(err)
fmt.Printf("UNKOWN - %s\n", err)
return
}

foundSupportedSyncMode := false
foundSyncMode := make([]string, 0)
var finalSoapResponse *fritz.WANCommonInterfaceOnlineMonitorResponse

for currentSyncGroup := 0; currentSyncGroup < totalSyncGroups; currentSyncGroup++ {
soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}

// We only need to perform additional queries when there are more than 1 sync groups
if totalSyncGroups > 1 {
// Start of additional query attempts (depending on how many sync groups are found)
responseChan := make(chan []byte)
errorChan := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", strconv.Itoa(currentSyncGroup)))
go fritz.DoSoapRequest(&soapReq, responseChan, errorChan, aI.Debug)

resp, err := fritz.ProcessSoapResponse(responseChan, errorChan, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

err = fritz.UnmarshalSoapResponse(&soapResp, resp)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}
} else {
soapResp = initialSoapResp
}

syncGroupMode := soapResp.NewSyncGroupMode
foundSyncMode = append(foundSyncMode, syncGroupMode)

// Search for supported sync groups
if syncGroupMode == "VDSL" || syncGroupMode == "CABLE" {
foundSupportedSyncMode = true
finalSoapResponse = &soapResp

break
}
}

var downstream float64

if foundSupportedSyncMode {
downstream, err = strconv.ParseFloat(finalSoapResponse.NewMaxDS, 64)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}
} else {
fmt.Printf("UNKNOWN - Could not find a supported SyncGroup (VDSL or CABLE); found the following: %s\n", strings.Join(foundSyncMode, ", "))
return
}

downstream = downstream * 8 / 1000000
Expand Down
77 changes: 68 additions & 9 deletions cmd/check_fritz/check_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,86 @@ import (

// CheckUpstreamMax checks the maximum upstream that is available on this internet connection
func CheckUpstreamMax(aI ArgumentInformation) {
// Start of the initial request to get the total number of sync groups; we always start with group id 0
resps := make(chan []byte)
errs := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&soapReq, resps, errs, aI.Debug)
initialSoapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
initialSoapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", "0"))
go fritz.DoSoapRequest(&initialSoapReq, resps, errs, aI.Debug)

res, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)
initialResponse, err := fritz.ProcessSoapResponse(resps, errs, 1, *aI.Timeout)

if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&soapResp, res)

upstream, err := strconv.ParseFloat(soapResp.NewMaxUS, 64)
initialSoapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}
err = fritz.UnmarshalSoapResponse(&initialSoapResp, initialResponse)

// Query the total number of sync groups
totalSyncGroups, err := strconv.Atoi(initialSoapResp.NewTotalNumberSyncGroups)
if err != nil {
panic(err)
fmt.Printf("UNKOWN - %s\n", err)
return
}

foundSupportedSyncMode := false
foundSyncMode := make([]string, 0)
var finalSoapResponse *fritz.WANCommonInterfaceOnlineMonitorResponse

for currentSyncGroup := 0; currentSyncGroup < totalSyncGroups; currentSyncGroup++ {
soapResp := fritz.WANCommonInterfaceOnlineMonitorResponse{}

// We only need to perform additional queries when there are more than 1 sync groups
if totalSyncGroups > 1 {
// Start of additional query attempts (depending on how many sync groups are found)
responseChan := make(chan []byte)
errorChan := make(chan error)

soapReq := fritz.CreateNewSoapData(*aI.Username, *aI.Password, *aI.Hostname, *aI.Port, "/upnp/control/wancommonifconfig1", "WANCommonInterfaceConfig", "X_AVM-DE_GetOnlineMonitor")
soapReq.AddSoapDataVariable(fritz.CreateNewSoapVariable("NewSyncGroupIndex", strconv.Itoa(currentSyncGroup)))
go fritz.DoSoapRequest(&soapReq, responseChan, errorChan, aI.Debug)

resp, err := fritz.ProcessSoapResponse(responseChan, errorChan, 1, *aI.Timeout)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}

err = fritz.UnmarshalSoapResponse(&soapResp, resp)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}
} else {
soapResp = initialSoapResp
}

syncGroupMode := soapResp.NewSyncGroupMode
foundSyncMode = append(foundSyncMode, syncGroupMode)

// Search for supported sync groups
if syncGroupMode == "VDSL" || syncGroupMode == "CABLE" {
foundSupportedSyncMode = true
finalSoapResponse = &soapResp

break
}
}

var upstream float64

if foundSupportedSyncMode {
upstream, err = strconv.ParseFloat(finalSoapResponse.NewMaxUS, 64)
if err != nil {
fmt.Printf("UNKNOWN - %s\n", err)
return
}
} else {
fmt.Printf("UNKNOWN - Could not find a supported SyncGroup (VDSL or CABLE); found the following: %s\n", strings.Join(foundSyncMode, ", "))
return
}

upstream = upstream * 8 / 1000000
Expand Down

0 comments on commit 7e28e2c

Please sign in to comment.