From 5c51103fb7fe6905c0973fd19a963ce4be871dea Mon Sep 17 00:00:00 2001 From: mikameyer Date: Thu, 23 Sep 2021 12:12:58 +0200 Subject: [PATCH] added aviat interface code communicator --- config/codecommunicator/aviat.go | 76 ++++++++++++++++++++ config/codecommunicator/ceraos-ip10.go | 2 +- config/codecommunicator/code_communicator.go | 2 + config/deviceclass/generic/routeros.yaml | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 config/codecommunicator/aviat.go diff --git a/config/codecommunicator/aviat.go b/config/codecommunicator/aviat.go new file mode 100644 index 0000000..e747a7e --- /dev/null +++ b/config/codecommunicator/aviat.go @@ -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 +} diff --git a/config/codecommunicator/ceraos-ip10.go b/config/codecommunicator/ceraos-ip10.go index 3bbb847..e20c099 100644 --- a/config/codecommunicator/ceraos-ip10.go +++ b/config/codecommunicator/ceraos-ip10.go @@ -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 diff --git a/config/codecommunicator/code_communicator.go b/config/codecommunicator/code_communicator.go index a33b289..c70c9ad 100644 --- a/config/codecommunicator/code_communicator.go +++ b/config/codecommunicator/code_communicator.go @@ -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)) } diff --git a/config/deviceclass/generic/routeros.yaml b/config/deviceclass/generic/routeros.yaml index ec8e628..fe703cc 100644 --- a/config/deviceclass/generic/routeros.yaml +++ b/config/deviceclass/generic/routeros.yaml @@ -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"