Skip to content

Commit

Permalink
Merge pull request #14 from inexio/dev
Browse files Browse the repository at this point in the history
ekinops interface normalization
  • Loading branch information
TheFireMike authored Feb 26, 2021
2 parents e74bde0 + f5163f1 commit 0d0378d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 45 deletions.
49 changes: 40 additions & 9 deletions core/communicator/ekinops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <slot>-[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) {
Expand All @@ -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 "fibreChannel" if ifType equals "other"
slotNumber := strings.Split(*interf.IfName, "/")[2]
if !(slotNumber == "0" || slotNumber == "1") {
if interf.IfType == nil || *interf.IfType == "other" {
fibreChannel := "fibreChannel"
interf.IfType = &fibreChannel
}
}

// 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 <slot>-[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
}
41 changes: 25 additions & 16 deletions core/communicator/ekinops_module_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
19 changes: 7 additions & 12 deletions core/communicator/ekinops_module_reader_opm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down
10 changes: 2 additions & 8 deletions core/communicator/ekinops_module_reader_transponder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 0d0378d

Please sign in to comment.