2024-05-23 20:08:14 +02:00
|
|
|
package limits
|
|
|
|
|
|
|
|
import (
|
2024-06-05 17:45:14 +02:00
|
|
|
"fmt"
|
2024-05-23 20:08:14 +02:00
|
|
|
"github.com/openziti/zrok/controller/store"
|
2024-06-03 20:01:20 +02:00
|
|
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
2024-06-11 18:00:12 +02:00
|
|
|
"github.com/openziti/zrok/util"
|
2024-05-23 20:08:14 +02:00
|
|
|
)
|
|
|
|
|
2024-06-03 20:01:20 +02:00
|
|
|
type configBandwidthClass struct {
|
|
|
|
periodInMinutes int
|
|
|
|
bw *Bandwidth
|
|
|
|
limitAction store.LimitAction
|
2024-05-23 20:08:14 +02:00
|
|
|
}
|
|
|
|
|
2024-06-03 20:06:07 +02:00
|
|
|
func newConfigBandwidthClasses(cfg *BandwidthPerPeriod) []store.BandwidthClass {
|
2024-06-03 20:01:20 +02:00
|
|
|
return []store.BandwidthClass{
|
|
|
|
&configBandwidthClass{
|
2024-06-03 20:06:07 +02:00
|
|
|
periodInMinutes: int(cfg.Period.Minutes()),
|
|
|
|
bw: cfg.Warning,
|
2024-06-03 20:01:20 +02:00
|
|
|
limitAction: store.WarningLimitAction,
|
|
|
|
},
|
2024-06-03 20:06:07 +02:00
|
|
|
&configBandwidthClass{
|
|
|
|
periodInMinutes: int(cfg.Period.Minutes()),
|
|
|
|
bw: cfg.Limit,
|
|
|
|
limitAction: store.LimitLimitAction,
|
|
|
|
},
|
2024-05-23 20:08:14 +02:00
|
|
|
}
|
2024-06-03 20:01:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) IsGlobal() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-06-06 19:49:36 +02:00
|
|
|
func (bc *configBandwidthClass) IsScoped() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-06-04 20:06:44 +02:00
|
|
|
func (bc *configBandwidthClass) GetLimitClassId() int {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2024-06-03 20:01:20 +02:00
|
|
|
func (bc *configBandwidthClass) GetShareMode() sdk.ShareMode {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetBackendMode() sdk.BackendMode {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetPeriodMinutes() int {
|
|
|
|
return bc.periodInMinutes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetRxBytes() int64 {
|
|
|
|
return bc.bw.Rx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetTxBytes() int64 {
|
|
|
|
return bc.bw.Tx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetTotalBytes() int64 {
|
|
|
|
return bc.bw.Total
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bc *configBandwidthClass) GetLimitAction() store.LimitAction {
|
|
|
|
return bc.limitAction
|
2024-05-23 20:08:14 +02:00
|
|
|
}
|
2024-06-05 17:45:14 +02:00
|
|
|
|
|
|
|
func (bc *configBandwidthClass) String() string {
|
2024-06-06 19:49:36 +02:00
|
|
|
out := fmt.Sprintf("ConfigClass<periodMinutes: %d", bc.periodInMinutes)
|
|
|
|
if bc.bw.Rx > store.Unlimited {
|
2024-06-11 18:00:12 +02:00
|
|
|
out += fmt.Sprintf(", rxBytes: %v", util.BytesToSize(bc.bw.Rx))
|
2024-06-06 19:49:36 +02:00
|
|
|
}
|
|
|
|
if bc.bw.Tx > store.Unlimited {
|
2024-06-11 18:00:12 +02:00
|
|
|
out += fmt.Sprintf(", txBytes: %v", util.BytesToSize(bc.bw.Tx))
|
2024-06-06 19:49:36 +02:00
|
|
|
}
|
|
|
|
if bc.bw.Total > store.Unlimited {
|
2024-06-11 18:00:12 +02:00
|
|
|
out += fmt.Sprintf(", totalBytes: %v", util.BytesToSize(bc.bw.Total))
|
2024-06-05 17:45:14 +02:00
|
|
|
}
|
2024-06-06 19:49:36 +02:00
|
|
|
out += fmt.Sprintf(", limitAction: %s>", bc.limitAction)
|
|
|
|
return out
|
2024-06-05 17:45:14 +02:00
|
|
|
}
|