|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "fmt" |
| 6 | +) |
| 7 | + |
| 8 | +type errorCountersResponse struct { |
| 9 | + ID uint64 `json:"id" xml:"id"` |
| 10 | + Version string `json:"jsonrpc" xml:"jsonrpc"` |
| 11 | + Result errorCountersResponseResult `json:"result" xml:"result"` |
| 12 | +} |
| 13 | + |
| 14 | +type errorCountersResponseResult struct { |
| 15 | + Body errorCountersResponseResultBody `json:"body" xml:"body"` |
| 16 | +} |
| 17 | + |
| 18 | +type errorCountersResponseResultBody struct { |
| 19 | + ErrorCountersTable errorCountersResponseResultBodyErrorCountersTable `json:"TABLE_interface" xml:"TABLE_interface"` |
| 20 | +} |
| 21 | + |
| 22 | +type errorCountersResponseResultBodyErrorCountersTable struct { |
| 23 | + ErrorCountersRow []errorCountersResponseResultBodyErrorCountersRow `json:"ROW_interface" xml:"ROW_interface"` |
| 24 | +} |
| 25 | + |
| 26 | +type errorCountersResponseResultBodyErrorCountersRow struct { |
| 27 | + Interface string `json:"interface" xml:"interface"` |
| 28 | + EthAlignErr uint64 `json:"eth_align_err" xml:"eth_align_err"` |
| 29 | + EthFCSErr uint64 `json:"eth_fcs_err" xml:"eth_fcs_err"` |
| 30 | + EthOutDiscards uint64 `json:"eth_outdisc" xml:"eth_outdisc"` |
| 31 | + EthRcvErr uint64 `json:"eth_rcv_err" xml:"eth_rcv_err"` |
| 32 | + EthUndersize uint64 `json:"eth_undersize" xml:"eth_undersize"` |
| 33 | + EthXmitErr uint64 `json:"eth_xmit_err" xml:"eth_xmit_err"` |
| 34 | + EthCarriSen uint64 `json:"eth_carri_sen" xml:"eth_carri_sen"` |
| 35 | + EthExcessCol uint64 `json:"eth_excess_col" xml:"eth_excess_col"` |
| 36 | + EthLateCol uint64 `json:"eth_late_col" xml:"eth_late_col"` |
| 37 | + EthMultiCol uint64 `json:"eth_multi_col" xml:"eth_multi_col"` |
| 38 | + EthRunts uint64 `json:"eth_runts" xml:"eth_runts"` |
| 39 | + EthSingleCol uint64 `json:"eth_single_col" xml:"eth_single_col"` |
| 40 | + EthDeferredTx uint64 `json:"eth_deferred_tx" xml:"eth_deferred_tx"` |
| 41 | + EthGiants uint64 `json:"eth_giants" xml:"eth_giants"` |
| 42 | + EthInMacRxErr uint64 `json:"eth_inmacrx_err" xml:"eth_inmacrx_err"` |
| 43 | + EthInMacTxErr uint64 `json:"eth_inmactx_err" xml:"eth_inmactx_err"` |
| 44 | + EthSymbolErr uint64 `json:"eth_symbol_err" xml:"eth_symbol_err"` |
| 45 | + EthInDiscards uint64 `json:"eth_indisc" xml:"eth_indisc"` |
| 46 | +} |
| 47 | + |
| 48 | +type ErrorCounters struct { |
| 49 | + Interface string `json:"interface" xml:"interface"` |
| 50 | + EthAlignErr uint64 `json:"eth_align_err" xml:"eth_align_err"` |
| 51 | + EthCarriSen uint64 `json:"eth_carri_sen" xml:"eth_carri_sen"` |
| 52 | + EthDeferredTx uint64 `json:"eth_deferred_tx" xml:"eth_deferred_tx"` |
| 53 | + EthExcessCol uint64 `json:"eth_excess_col" xml:"eth_excess_col"` |
| 54 | + EthFCSErr uint64 `json:"eth_fcs_err" xml:"eth_fcs_err"` |
| 55 | + EthGiants uint64 `json:"eth_giants" xml:"eth_giants"` |
| 56 | + EthInDiscards uint64 `json:"eth_indisc" xml:"eth_indisc"` |
| 57 | + EthInMacRxErr uint64 `json:"eth_inmacrx_err" xml:"eth_inmacrx_err"` |
| 58 | + EthInMacTxErr uint64 `json:"eth_inmactx_err" xml:"eth_inmactx_err"` |
| 59 | + EthLateCol uint64 `json:"eth_late_col" xml:"eth_late_col"` |
| 60 | + EthMultiCol uint64 `json:"eth_multi_col" xml:"eth_multi_col"` |
| 61 | + EthOutDiscards uint64 `json:"eth_outdisc" xml:"eth_outdisc"` |
| 62 | + EthRcvErr uint64 `json:"eth_rcv_err" xml:"eth_rcv_err"` |
| 63 | + EthRunts uint64 `json:"eth_runts" xml:"eth_runts"` |
| 64 | + EthSingleCol uint64 `json:"eth_single_col" xml:"eth_single_col"` |
| 65 | + EthSymbolErr uint64 `json:"eth_symbol_err" xml:"eth_symbol_err"` |
| 66 | + EthUndersize uint64 `json:"eth_undersize" xml:"eth_undersize"` |
| 67 | + EthXmitErr uint64 `json:"eth_xmit_err" xml:"eth_xmit_err"` |
| 68 | +} |
| 69 | + |
| 70 | +// NewErrorCountersFromString returns ErrorCounter instance from an input string. |
| 71 | +func NewErrorCountersFromString(s string) ([]*ErrorCounters, error) { |
| 72 | + return NewErrorCountersFromBytes([]byte(s)) |
| 73 | +} |
| 74 | + |
| 75 | +// NewErrorCountersFromBytes returns ErrorCounter instance from an input byte array. |
| 76 | +func NewErrorCountersFromBytes(s []byte) ([]*ErrorCounters, error) { |
| 77 | + var errorCounters []*ErrorCounters |
| 78 | + eCountersResponse := &errorCountersResponse{} |
| 79 | + err := json.Unmarshal(s, eCountersResponse) |
| 80 | + if err != nil { |
| 81 | + return nil, fmt.Errorf("parsing error: %s, server response: %s", err, string(s[:])) |
| 82 | + } |
| 83 | + if len(eCountersResponse.Result.Body.ErrorCountersTable.ErrorCountersRow) < 1 { |
| 84 | + return nil, fmt.Errorf("Error parsing the received response: %s", s) |
| 85 | + } |
| 86 | + i, size := 0, len(eCountersResponse.Result.Body.ErrorCountersTable.ErrorCountersRow) |
| 87 | + for _, e := range eCountersResponse.Result.Body.ErrorCountersTable.ErrorCountersRow { |
| 88 | + if i < size/4 { |
| 89 | + errorCounter := &ErrorCounters{} |
| 90 | + errorCounter.Interface = e.Interface |
| 91 | + errorCounter.EthAlignErr = e.EthAlignErr |
| 92 | + errorCounter.EthFCSErr = e.EthFCSErr |
| 93 | + errorCounter.EthOutDiscards = e.EthOutDiscards |
| 94 | + errorCounter.EthRcvErr = e.EthRcvErr |
| 95 | + errorCounter.EthUndersize = e.EthUndersize |
| 96 | + errorCounter.EthXmitErr = e.EthXmitErr |
| 97 | + errorCounters = append(errorCounters, errorCounter) |
| 98 | + } else if i < size/2 { |
| 99 | + errorCounter := errorCounters[i%(size/4)] |
| 100 | + errorCounter.EthCarriSen = e.EthCarriSen |
| 101 | + errorCounter.EthExcessCol = e.EthExcessCol |
| 102 | + errorCounter.EthLateCol = e.EthLateCol |
| 103 | + errorCounter.EthMultiCol = e.EthMultiCol |
| 104 | + errorCounter.EthRunts = e.EthRunts |
| 105 | + errorCounter.EthSingleCol = e.EthSingleCol |
| 106 | + } else if i < 3*size/4 { |
| 107 | + errorCounter := errorCounters[i%(size/4)] |
| 108 | + errorCounter.EthDeferredTx = e.EthDeferredTx |
| 109 | + errorCounter.EthGiants = e.EthGiants |
| 110 | + errorCounter.EthInMacRxErr = e.EthInMacRxErr |
| 111 | + errorCounter.EthInMacTxErr = e.EthInMacTxErr |
| 112 | + errorCounter.EthSymbolErr = e.EthSymbolErr |
| 113 | + } else { |
| 114 | + errorCounter := errorCounters[i%(size/4)] |
| 115 | + errorCounter.EthInDiscards = e.EthInDiscards |
| 116 | + } |
| 117 | + i += 1 |
| 118 | + } |
| 119 | + return errorCounters, nil |
| 120 | +} |
0 commit comments