Skip to content

Commit

Permalink
added aviat rx/tx frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFireMike committed Dec 15, 2021
1 parent fbeb39b commit d2a7b6a
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 13 deletions.
74 changes: 73 additions & 1 deletion config/codecommunicator/aviat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...grouppr
var filterWithIfType []groupproperty.Filter
for _, fil := range filter {
if valueFilter, ok := fil.(groupproperty.ValueFilter); ok {
filterWithIfType = append(filterWithIfType, valueFilter.AddException([]string{"ifType"}))
if f := valueFilter.AddException([]string{"ifType"}); f != nil {
filterWithIfType = append(filterWithIfType, f)
}
}
}

Expand Down Expand Up @@ -223,6 +225,76 @@ func (c *aviatCommunicator) getRadioInterface(ctx context.Context, interfaces []
}
}

// aviatRfFreqTx
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.5.2.1.1.1")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatRfFreqTx")
return interfaces, nil
}

for _, r := range res {
txFrequencyVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatRfFreqTx value")
}
txFrequency, err := txFrequencyVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatRfFreqTx value")
}
txFrequency = txFrequency / 1000

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].TXFrequency = &txFrequency
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
TXFrequency: &txFrequency,
})
}
}

// aviatRfFreqRx
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.5.2.1.1.2")
if err != nil {
log.Ctx(ctx).Debug().Err(err).Msg("failed to get aviatRfFreqRx")
return interfaces, nil
}

for _, r := range res {
rxFrequencyVal, err := r.GetValue()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatRfFreqRx value")
}
rxFrequency, err := rxFrequencyVal.Float64()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatRfFreqRx value")
}
rxFrequency = rxFrequency / 1000

target := names[r.GetOID().GetIndex()]
found := false
for i, channel := range channels {
if channel.Channel != nil && *channel.Channel == target {
channels[i].RXFrequency = &rxFrequency
found = true
break
}
}
if !found {
channels = append(channels, device.RadioChannel{
Channel: &target,
RXFrequency: &rxFrequency,
})
}
}

for i, interf := range interfaces {
if interf.IfType != nil && *interf.IfType == "radioMAC" {
interfaces[i].MaxSpeedIn = &maxCapacity
Expand Down
6 changes: 4 additions & 2 deletions internal/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ type EthernetLikeInterface struct {
//
// swagger:model
type RadioInterface struct {
LevelIn *int64 `yaml:"level_in" json:"level_in" xml:"level_in" mapstructure:"level_in"`
LevelOut *int64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
LevelIn *float64 `yaml:"level_in" json:"level_in" xml:"level_in" mapstructure:"level_in"`
LevelOut *float64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
MaxbitrateIn *uint64 `yaml:"maxbitrate_in" json:"maxbitrate_in" xml:"maxbitrate_in" mapstructure:"maxbitrate_in"`
MaxbitrateOut *uint64 `yaml:"maxbitrate_out" json:"maxbitrate_out" xml:"maxbitrate_out" mapstructure:"maxbitrate_out"`
RXFrequency *float64 `yaml:"rx_frequency" json:"rx_frequency" xml:"rx_frequency" mapstructure:"rx_frequency"`
Expand All @@ -189,6 +189,8 @@ type RadioChannel struct {
LevelOut *float64 `yaml:"level_out" json:"level_out" xml:"level_out" mapstructure:"level_out"`
MaxbitrateIn *uint64 `yaml:"maxbitrate_in" json:"maxbitrate_in" xml:"maxbitrate_in" mapstructure:"maxbitrate_in"`
MaxbitrateOut *uint64 `yaml:"maxbitrate_out" json:"maxbitrate_out" xml:"maxbitrate_out" mapstructure:"maxbitrate_out"`
RXFrequency *float64 `yaml:"rx_frequency" json:"rx_frequency" xml:"rx_frequency" mapstructure:"rx_frequency"`
TXFrequency *float64 `yaml:"tx_frequency" json:"tx_frequency" xml:"tx_frequency" mapstructure:"tx_frequency"`
}

// DWDMInterface
Expand Down
40 changes: 31 additions & 9 deletions internal/deviceclass/groupproperty/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/inexio/thola/internal/value"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"reflect"
"regexp"
"strconv"
)
Expand Down Expand Up @@ -181,6 +182,9 @@ func (g *valueFilter) CheckMatch(value []string) bool {
return false
}
}
if len(value) < len(g.value) {
return false
}
return true
}

Expand Down Expand Up @@ -306,16 +310,34 @@ func filterPropertyGroupKey(ctx context.Context, group propertyGroup, key []stri
if del {
log.Ctx(ctx).Debug().Str("value", k).Msg("filter matched on value in property group")
} else {
var nextGroup propertyGroup
err := nextGroup.encode(v)
if err != nil {
return nil, errors.Wrap(err, "failed to encode next filter key value to property group")
}
r, err := filterPropertyGroupKey(ctx, nextGroup, key[1:], matcher)
if err != nil {
return nil, err
switch reflect.TypeOf(v).Kind() {
case reflect.Slice:
var nextGroups PropertyGroups
err := nextGroups.Encode(v)
if err != nil {
return nil, errors.Wrap(err, "failed to encode next filter key value to property groups")
}
var filteredGroups PropertyGroups
for _, nextGroup := range nextGroups {
r, err := filterPropertyGroupKey(ctx, nextGroup, key[1:], matcher)
if err != nil {
return nil, err
}
filteredGroups = append(filteredGroups, r)
}
groupCopy[k] = filteredGroups
default:
var nextGroup propertyGroup
err := nextGroup.encode(v)
if err != nil {
return nil, errors.Wrap(err, "failed to encode next filter key value to property group")
}
r, err := filterPropertyGroupKey(ctx, nextGroup, key[1:], matcher)
if err != nil {
return nil, err
}
groupCopy[k] = r
}
groupCopy[k] = r
}
continue
}
Expand Down
45 changes: 44 additions & 1 deletion internal/deviceclass/groupproperty/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ func TestValueFilter_CheckMatch(t *testing.T) {
filter, ok := valueFilter.(ValueFilter)
assert.True(t, ok, "value filter is not implementing the ValueFilter interface")

assert.True(t, filter.CheckMatch([]string{"radio"}))
assert.False(t, filter.CheckMatch([]string{"radio"}))
assert.False(t, filter.CheckMatch([]string{"ifDescr"}))
assert.True(t, filter.CheckMatch([]string{"radio", "level_in"}))
assert.False(t, filter.CheckMatch([]string{"radio", "level_in", "test"}))
assert.False(t, filter.CheckMatch([]string{"radio", "level_out"}))
assert.False(t, filter.CheckMatch([]string{"radio", "level_out", "test"}))
}

func TestValueFilter_ApplyPropertyGroups(t *testing.T) {
Expand Down Expand Up @@ -330,6 +332,47 @@ func TestValueFilter_ApplyPropertyGroups_nested(t *testing.T) {
assert.Equal(t, expected, filteredGroup)
}

func TestValueFilter_ApplyPropertyGroups_nestedArray(t *testing.T) {
filter := GetValueFilter([]string{"radio", "level_in"})

groups := PropertyGroups{
propertyGroup{
"ifIndex": "1",
"ifDescr": "Ethernet #1",
"radio": []propertyGroup{
{
"level_in": "10",
"level_out": "10",
},
{
"level_in": "7",
"level_out": "5",
},
},
},
}

filteredGroup, err := filter.ApplyPropertyGroups(context.Background(), groups)
assert.NoError(t, err)

expected := PropertyGroups{
propertyGroup{
"ifIndex": "1",
"ifDescr": "Ethernet #1",
"radio": PropertyGroups{
{
"level_out": "10",
},
{
"level_out": "5",
},
},
},
}

assert.Equal(t, expected, filteredGroup)
}

func TestValueFilter_ApplyPropertyGroups_nestedWholeMatch(t *testing.T) {
filter := GetValueFilter([]string{"radio"})

Expand Down
2 changes: 2 additions & 0 deletions internal/request/check_interface_metrics_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (r *CheckInterfaceMetricsRequest) getFilter() []groupproperty.Filter {
// Radio
groupproperty.GetValueFilter([]string{"radio", "rx_frequency"}),
groupproperty.GetValueFilter([]string{"radio", "tx_frequency"}),
groupproperty.GetValueFilter([]string{"radio", "channels", "rx_frequency"}),
groupproperty.GetValueFilter([]string{"radio", "channels", "tx_frequency"}),
}

if !r.PrintInterfaces {
Expand Down

0 comments on commit d2a7b6a

Please sign in to comment.