From f83d5652799a405831f38575d22c020fa0772de4 Mon Sep 17 00:00:00 2001 From: mikameyer Date: Thu, 25 Feb 2021 15:15:19 +0100 Subject: [PATCH 1/2] ekinops interface normalization --- core/communicator/ekinops.go | 49 +++++++++++++++---- core/communicator/ekinops_module_reader.go | 41 ++++++++++------ .../communicator/ekinops_module_reader_opm.go | 19 +++---- .../ekinops_module_reader_transponder.go | 10 +--- 4 files changed, 74 insertions(+), 45 deletions(-) diff --git a/core/communicator/ekinops.go b/core/communicator/ekinops.go index e142dbd..a4d4aca 100644 --- a/core/communicator/ekinops.go +++ b/core/communicator/ekinops.go @@ -65,15 +65,7 @@ func (c *ekinopsCommunicator) GetInterfaces(ctx context.Context) ([]device.Inter } } - // change ifdescr and ifname of every interface - // they no longer contain Ekinops/C... - // and are now in the form -[Description] - for _, iface := range interfaces { - *iface.IfDescr = strings.Split(*iface.IfDescr, "/")[2] + "-" + strings.Split(strings.Split(*iface.IfDescr, "/")[4], "(")[0] - *iface.IfName = *iface.IfDescr - } - - return interfaces, nil + return normalizeEkinopsInterfaces(interfaces) } func ekinopsInterfacesIfIdentifierToSliceIndex(interfaces []device.Interface) (map[string]int, error) { @@ -92,3 +84,42 @@ func ekinopsInterfacesIfIdentifierToSliceIndex(interfaces []device.Interface) (m } return m, nil } + +func normalizeEkinopsInterfaces(interfaces []device.Interface) ([]device.Interface, error) { + var res []device.Interface + + for _, interf := range interfaces { + if interf.IfDescr == nil { + return nil, fmt.Errorf("no IfDescr set for interface ifIndex: `%d`", *interf.IfIndex) + } + + // change ifType of ports of slots > 1 to "LWL" if ifType equals "other" + slotNumber := strings.Split(*interf.IfName, "/")[2] + if !(slotNumber == "0" || slotNumber == "1") { + if interf.IfType == nil || *interf.IfType == "other" { + lwl := "LWL" + interf.IfType = &lwl + } + } + + // change ifType of OPM8 ports + moduleName := strings.Split(*interf.IfDescr, "/")[3] + if moduleName == "PM_OPM8" { + ifType := "ChannelMonitoring" //TODO switch ifType name + interf.IfType = &ifType + } + + // change ifDescr and ifName of every interface + // they no longer contain Ekinops/C... + // and are now in the form -[Description] + *interf.IfDescr = slotNumber + "-" + strings.Split(strings.Split(*interf.IfDescr, "/")[4], "(")[0] + interf.IfName = interf.IfDescr + + // remove every port on slot 0 starting with "0-FE_" + if slotNumber != "0" || !strings.HasPrefix(*interf.IfName, "0-FE_") { + res = append(res, interf) + } + } + + return res, nil +} diff --git a/core/communicator/ekinops_module_reader.go b/core/communicator/ekinops_module_reader.go index 5c34e5c..f106629 100644 --- a/core/communicator/ekinops_module_reader.go +++ b/core/communicator/ekinops_module_reader.go @@ -176,17 +176,11 @@ func ekinopsGetModuleReader(slotIdentifier, module string) (ekinopsModuleReader, return &ekinopsModuleReaderWrapper{&ekinopsModuleReaderOPM8{ ekinopsModuleData: moduleData, ports: ekinopsOPMOIDs{ - identifierOID: ".1.3.6.1.4.1.20044.66.7.1.1.1.2", - labelOID: ".1.3.6.1.4.1.20044.66.9.2.7.1.3", - rxPowerOID: ".1.3.6.1.4.1.20044.66.3.2.784.1.2", - channelsOid: ".1.3.6.1.4.1.20044.66.3.2", - powerTransformFunc: func(f float64) float64 { - if f < 32768 { - return f / 256 - } else { - return f/256 - 256 - } - }, + identifierOID: ".1.3.6.1.4.1.20044.66.7.1.1.1.2", + labelOID: ".1.3.6.1.4.1.20044.66.9.2.7.1.3", + rxPowerOID: ".1.3.6.1.4.1.20044.66.3.2.784.1.2", + channelsOid: ".1.3.6.1.4.1.20044.66.3.2", + powerTransformFunc: ekinopsPowerTransformOPM8, }, }}, nil } @@ -226,21 +220,36 @@ func (m *ekinopsModuleReaderWrapper) readModuleMetrics(ctx context.Context, inte type ekinopsPowerTransformFunc func(float64) float64 func ekinopsPowerTransform10Log10XMinus40(f float64) float64 { - return 10*math.Log10(f) - 40 + return ekinopsPowerTransformCheckEmpty(10*math.Log10(f) - 40) } func ekinopsPowerTransform10Log10XDivideBy10000(f float64) float64 { - return 10 * math.Log10(f/10000) + return ekinopsPowerTransformCheckEmpty(10 * math.Log10(f/10000)) } func ekionopsPowerTransformShiftDivideBy100(f float64) float64 { if f < 32768 { - return f / 100 + return ekinopsPowerTransformCheckEmpty(f / 100) } else { - return (f - 65536) / 100 + return ekinopsPowerTransformCheckEmpty((f - 65536) / 100) } } func ekinopsPowerTransformMinus32768MultiplyByPoint005(f float64) float64 { - return (f - 32768) * 0.005 + return ekinopsPowerTransformCheckEmpty((f - 32768) * 0.005) +} + +func ekinopsPowerTransformOPM8(f float64) float64 { + if f < 32768 { + return ekinopsPowerTransformCheckEmpty(f / 256) + } else { + return ekinopsPowerTransformCheckEmpty(f/256 - 256) + } +} + +func ekinopsPowerTransformCheckEmpty(f float64) float64 { + if f < -40.4 { + f = -40.4 + } + return f } diff --git a/core/communicator/ekinops_module_reader_opm.go b/core/communicator/ekinops_module_reader_opm.go index 4823bb6..186cc77 100644 --- a/core/communicator/ekinops_module_reader_opm.go +++ b/core/communicator/ekinops_module_reader_opm.go @@ -107,10 +107,7 @@ func ekinopsReadOPMMetrics(ctx context.Context, oids ekinopsOPMOIDs) ([]device.O valueFloat = oids.powerTransformFunc(valueFloat) } - // power <= -95 = no value - if valueFloat > -95 { - opticalOPMInterface.RXPower = &valueFloat - } + opticalOPMInterface.RXPower = &valueFloat } opticalOPMInterfaces = append(opticalOPMInterfaces, opticalOPMInterface) @@ -167,16 +164,14 @@ func ekinopsReadOPMMetrics(ctx context.Context, oids ekinopsOPMOIDs) ([]device.O for channelIdx := 16; channelIdx <= 776; channelIdx += 8 { rxPower := channelValues[k][channelIdx] - // power <= -95 = no value - if rxPower > -95 { - var channel device.OpticalOPMChannel - channel.RXPower = &rxPower - channel.Channel = fmt.Sprintf("C%.2f", channelNum) + channel := device.OpticalOPMChannel{ + Channel: fmt.Sprintf("C%.2f", channelNum), + RXPower: &rxPower, + } - opticalOPMInterfaces[k].Channels = append(opticalOPMInterfaces[k].Channels, channel) + opticalOPMInterfaces[k].Channels = append(opticalOPMInterfaces[k].Channels, channel) - channelNum += 0.5 - } + channelNum += 0.5 } } diff --git a/core/communicator/ekinops_module_reader_transponder.go b/core/communicator/ekinops_module_reader_transponder.go index 871b681..2d8189d 100644 --- a/core/communicator/ekinops_module_reader_transponder.go +++ b/core/communicator/ekinops_module_reader_transponder.go @@ -142,10 +142,7 @@ func ekinopsReadTransponderMetrics(ctx context.Context, oids ekinopsTransponderO valueFloat = oids.powerTransformFunc(valueFloat) } - // power <= -95 = no value - if valueFloat > -95 { - opticalTransponderInterface.RXPower = &valueFloat - } + opticalTransponderInterface.RXPower = &valueFloat } if txPowerResult != nil { @@ -162,10 +159,7 @@ func ekinopsReadTransponderMetrics(ctx context.Context, oids ekinopsTransponderO valueFloat = oids.powerTransformFunc(valueFloat) } - // power <= -95 = no value - if valueFloat > -95 { - opticalTransponderInterface.TXPower = &valueFloat - } + opticalTransponderInterface.TXPower = &valueFloat } if correctedFECResult != nil { From f5163f19c251d7a2964f62c218e38a78f3a0fc77 Mon Sep 17 00:00:00 2001 From: mikameyer Date: Fri, 26 Feb 2021 10:00:07 +0100 Subject: [PATCH 2/2] switched ifType of certain ekinops interfaces to "fibreChannel" --- core/communicator/ekinops.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/communicator/ekinops.go b/core/communicator/ekinops.go index a4d4aca..6c89daf 100644 --- a/core/communicator/ekinops.go +++ b/core/communicator/ekinops.go @@ -93,12 +93,12 @@ func normalizeEkinopsInterfaces(interfaces []device.Interface) ([]device.Interfa return nil, fmt.Errorf("no IfDescr set for interface ifIndex: `%d`", *interf.IfIndex) } - // change ifType of ports of slots > 1 to "LWL" if ifType equals "other" + // change ifType of ports of slots > 1 to "fibreChannel" if ifType equals "other" slotNumber := strings.Split(*interf.IfName, "/")[2] if !(slotNumber == "0" || slotNumber == "1") { if interf.IfType == nil || *interf.IfType == "other" { - lwl := "LWL" - interf.IfType = &lwl + fibreChannel := "fibreChannel" + interf.IfType = &fibreChannel } }