Skip to content

Commit

Permalink
added aviat interface code communicator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFireMike committed Sep 23, 2021
1 parent eb1f070 commit 5c51103
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
76 changes: 76 additions & 0 deletions config/codecommunicator/aviat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package codecommunicator

import (
"context"
"github.com/inexio/thola/internal/device"
"github.com/inexio/thola/internal/deviceclass/groupproperty"
"github.com/inexio/thola/internal/network"
"github.com/pkg/errors"
"strconv"
"strings"
)

type aviatCommunicator struct {
codeCommunicator
}

func (c *aviatCommunicator) GetInterfaces(ctx context.Context, filter ...groupproperty.Filter) ([]device.Interface, error) {
interfaces, err := c.deviceClass.GetInterfaces(ctx, filter...)
if err != nil {
return nil, err
}

con, ok := network.DeviceConnectionFromContext(ctx)
if !ok || con.SNMP == nil {
return nil, errors.New("snmp client is empty")
}

// aviatModemCurCapacityTx
res, err := con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.1.1.11")
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityTx")
}

var maxBitRateTx uint64
for _, r := range res {
bitRateString, err := r.GetValueString()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityTx value")
}
bitRate, err := strconv.ParseUint(bitRateString, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityTx value")
}
maxBitRateTx += bitRate * 1000
}

// aviatModemCurCapacityRx
res, err = con.SNMP.SnmpClient.SNMPWalk(ctx, "1.3.6.1.4.1.2509.9.3.2.1.1.12")
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityRx")
}

var maxBitRateRx uint64
for _, r := range res {
bitRateString, err := r.GetValueString()
if err != nil {
return nil, errors.Wrap(err, "failed to get aviatModemCurCapacityRx value")
}
bitRate, err := strconv.ParseUint(bitRateString, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "failed to parse aviatModemCurCapacityRx value")
}
maxBitRateRx += bitRate * 1000
}

for i, interf := range interfaces {
if interf.IfName != nil && strings.HasPrefix(*interf.IfName, "Radio") {
interfaces[i].Radio = &device.RadioInterface{
MaxbitrateOut: &maxBitRateTx,
MaxbitrateIn: &maxBitRateRx,
}
}
}

return interfaces, nil
}
2 changes: 1 addition & 1 deletion config/codecommunicator/ceraos-ip10.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ceraosIP10Communicator struct {
func (c *ceraosIP10Communicator) GetInterfaces(ctx context.Context, filter ...groupproperty.Filter) ([]device.Interface, error) {
subInterfaces, err := c.parent.GetInterfaces(ctx)
if err != nil {
return nil, errors.Wrap(err, "an unexpected error occurred while trying to get ifTable of sub communicator")
return nil, err
}

var targetInterface device.Interface
Expand Down
2 changes: 2 additions & 0 deletions config/codecommunicator/code_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func GetCodeCommunicator(deviceClass communicator.Communicator, parentNetworkDev
return &timosCommunicator{base}, nil
case "junos":
return &junosCommunicator{base}, nil
case "aviat":
return &aviatCommunicator{base}, nil
}
return nil, tholaerr.NewNotFoundError(fmt.Sprintf("no code communicator found for device class identifier '%s'", classIdentifier))
}
Expand Down
2 changes: 1 addition & 1 deletion config/deviceclass/generic/routeros.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ components:
filter_method: "!equals"
value: "0"
max_speed_out:
oid: .1.3.6.1.4.1.14988.1.1.1.3.1.2
oid: 1.3.6.1.4.1.14988.1.1.1.3.1.2
operators:
- type: filter
filter_method: "!equals"
Expand Down

0 comments on commit 5c51103

Please sign in to comment.