blob: 1fe9c4ca0e08c23d547dd24e2fc9c6737e061b25 [file] [log] [blame]
Himani Chawla40acc122021-05-26 18:52:29 +05301/*
2 * Copyright 2021-present Ciena Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package commands
17
18import (
Himani Chawla553a1392021-06-10 23:39:17 +053019 "fmt"
Himani Chawla40acc122021-05-26 18:52:29 +053020 "github.com/opencord/voltctl/pkg/model"
David K. Bainbridgebd6b2882021-08-26 13:31:02 +000021 "github.com/opencord/voltha-protos/v5/go/extension"
Himani Chawla40acc122021-05-26 18:52:29 +053022 "strings"
23)
24
25type tagBuilder struct {
26 firstField bool
27 tag strings.Builder
28}
29
30func NewTagBuilder() tagBuilder {
31 return tagBuilder{
32 firstField: true,
33 tag: strings.Builder{},
34 }
35}
36func (t *tagBuilder) buildOutputString() string {
37 return t.tag.String()
38}
39func (t *tagBuilder) addFieldInFormat(name string) {
40 if !t.firstField {
Himani Chawla553a1392021-06-10 23:39:17 +053041 t.tag.WriteString("\n")
Himani Chawla40acc122021-05-26 18:52:29 +053042 }
43 t.firstField = false
Himani Chawla553a1392021-06-10 23:39:17 +053044 str := fmt.Sprintf("%s: ", name)
45 t.tag.WriteString(str)
Himani Chawla40acc122021-05-26 18:52:29 +053046 t.tag.WriteString("{{.")
47 t.tag.WriteString(name)
48 t.tag.WriteString("}}")
49}
Himani Chawla40acc122021-05-26 18:52:29 +053050
51/*
52 * Construct a template format string based on the fields required by the
53 * results.
54 */
55func buildOnuStatsOutputFormat(counters *extension.GetOnuCountersResponse) (model.OnuStats, string) {
56 onuStats := model.OnuStats{}
57 tagBuilder := NewTagBuilder()
Himani Chawla40acc122021-05-26 18:52:29 +053058 if counters.IsIntfId != nil {
59 intfId := counters.GetIntfId()
60 onuStats.IntfId = &intfId
61 tagBuilder.addFieldInFormat("IntfId")
62 }
63 if counters.IsOnuId != nil {
64 onuId := counters.GetOnuId()
65 onuStats.OnuId = &onuId
66 tagBuilder.addFieldInFormat("OnuId")
67 }
68 if counters.IsPositiveDrift != nil {
69 positiveDrift := counters.GetPositiveDrift()
70 onuStats.PositiveDrift = &positiveDrift
71 tagBuilder.addFieldInFormat("PositiveDrift")
72 }
73 if counters.IsNegativeDrift != nil {
74 negativeDrift := counters.GetNegativeDrift()
75 onuStats.NegativeDrift = &negativeDrift
76 tagBuilder.addFieldInFormat("NegativeDrift")
77 }
78 if counters.IsDelimiterMissDetection != nil {
79 delimiterMissDet := counters.GetDelimiterMissDetection()
80 onuStats.DelimiterMissDetection = &delimiterMissDet
81 tagBuilder.addFieldInFormat("DelimiterMissDetection")
82 }
83 if counters.IsBipErrors != nil {
84 bipErrors := counters.GetBipErrors()
85 onuStats.BipErrors = &bipErrors
86 tagBuilder.addFieldInFormat("BipErrors")
87 }
88 if counters.IsBipUnits != nil {
89 bipUnits := counters.GetBipUnits()
90 onuStats.BipUnits = &bipUnits
91 tagBuilder.addFieldInFormat("BipUnits")
92 }
93 if counters.IsFecCorrectedSymbols != nil {
94 fecCorrectedSymbols := counters.GetFecCorrectedSymbols()
95 onuStats.FecCorrectedSymbols = &fecCorrectedSymbols
96 tagBuilder.addFieldInFormat("FecCorrectedSymbols")
97 }
98 if counters.IsFecCodewordsCorrected != nil {
99 fecCodewordsCorrected := counters.GetFecCodewordsCorrected()
100 onuStats.FecCodewordsCorrected = &fecCodewordsCorrected
101 tagBuilder.addFieldInFormat("FecCodewordsCorrected")
102 }
103 if counters.IsFecCodewordsUncorrectable != nil {
104 fecCodewordsUncorrectable := counters.GetFecCodewordsUncorrectable()
105 onuStats.FecCodewordsUncorrectable = &fecCodewordsUncorrectable
106 tagBuilder.addFieldInFormat("FecCodewordsUncorrectable")
107 }
108 if counters.IsFecCodewords != nil {
109 fecCodewords := counters.GetFecCodewords()
110 onuStats.FecCodewords = &fecCodewords
111 tagBuilder.addFieldInFormat("FecCodewords")
112 }
113 if counters.IsFecCorrectedUnits != nil {
114 fecCorrectedUnits := counters.GetFecCorrectedUnits()
115 onuStats.FecCorrectedUnits = &fecCorrectedUnits
116 tagBuilder.addFieldInFormat("FecCorrectedUnits")
117 }
118 if counters.IsXgemKeyErrors != nil {
119 xgemKeyErrors := counters.GetXgemKeyErrors()
120 onuStats.XgemKeyErrors = &xgemKeyErrors
121 tagBuilder.addFieldInFormat("XgemKeyErrors")
122 }
123 if counters.IsXgemLoss != nil {
124 xgemLoss := counters.GetXgemLoss()
125 onuStats.XgemLoss = &xgemLoss
126 tagBuilder.addFieldInFormat("XgemLoss")
127 }
128 if counters.IsRxPloamsError != nil {
129 rxPloamsError := counters.GetRxPloamsError()
130 onuStats.RxPloamsError = &rxPloamsError
131 tagBuilder.addFieldInFormat("RxPloamsError")
132 }
133 if counters.IsRxPloamsNonIdle != nil {
134 rxPloamsNonIdle := counters.GetRxPloamsNonIdle()
135 onuStats.RxPloamsNonIdle = &rxPloamsNonIdle
136 tagBuilder.addFieldInFormat("RxPloamsNonIdle")
137 }
138 if counters.IsRxOmci != nil {
139 rxOmci := counters.GetRxOmci()
140 onuStats.RxOmci = &rxOmci
141 tagBuilder.addFieldInFormat("RxOmci")
142 }
143 if counters.IsTxOmci != nil {
144 txOmci := counters.GetTxOmci()
145 onuStats.TxOmci = &txOmci
146 tagBuilder.addFieldInFormat("TxOmci")
147 }
148 if counters.IsRxOmciPacketsCrcError != nil {
149 rxOmciPacketsCrcError := counters.GetRxOmciPacketsCrcError()
150 onuStats.RxOmciPacketsCrcError = &rxOmciPacketsCrcError
151 tagBuilder.addFieldInFormat("RxOmciPacketsCrcError")
152 }
153 if counters.IsRxBytes != nil {
154 rxBytes := counters.GetRxBytes()
155 onuStats.RxBytes = &rxBytes
156 tagBuilder.addFieldInFormat("RxBytes")
157 }
158 if counters.IsRxPackets != nil {
159 rxPackets := counters.GetRxPackets()
160 onuStats.RxPackets = &rxPackets
161 tagBuilder.addFieldInFormat("RxPackets")
162 }
163 if counters.IsTxBytes != nil {
164 txBytes := counters.GetTxBytes()
165 onuStats.TxBytes = &txBytes
166 tagBuilder.addFieldInFormat("TxBytes")
167 }
168 if counters.IsTxPackets != nil {
169 txPackets := counters.GetTxPackets()
170 onuStats.TxPackets = &txPackets
171 tagBuilder.addFieldInFormat("TxPackets")
172 }
173 if counters.IsBerReported != nil {
174 berReported := counters.GetBerReported()
175 onuStats.BerReported = &berReported
176 tagBuilder.addFieldInFormat("BerReported")
177 }
178 if counters.IsLcdgErrors != nil {
179 lcdgErrors := counters.GetLcdgErrors()
180 onuStats.LcdgErrors = &lcdgErrors
181 tagBuilder.addFieldInFormat("LcdgErrors")
182 }
183 if counters.IsRdiErrors != nil {
184 rdiErrors := counters.GetRdiErrors()
185 onuStats.RdiErrors = &rdiErrors
186 tagBuilder.addFieldInFormat("RdiErrors")
187 }
188 if counters.IsTimestamp != nil {
189 timestamp := counters.GetTimestamp()
190 onuStats.Timestamp = &timestamp
191 tagBuilder.addFieldInFormat("Timestamp")
192 }
193 return onuStats, tagBuilder.buildOutputString()
194}
Himani Chawla553a1392021-06-10 23:39:17 +0530195
196/*
197 * Construct a template format string based on the fields required by the
198 * results.
199 */
200func buildOnuEthernetFrameExtendedPmOutputFormat(counters *extension.GetOmciEthernetFrameExtendedPmResponse) model.OnuEthernetFrameExtendedPm {
201 onuStats := model.OnuEthernetFrameExtendedPm{}
202
Himani Chawlabac0f892021-08-25 17:14:06 +0530203 onuStats.PmFormat = counters.GetOmciEthernetFrameExtendedPmFormat().String()
204
Himani Chawla553a1392021-06-10 23:39:17 +0530205 dropEvents := counters.Upstream.GetDropEvents()
206 onuStats.UDropEvents = &dropEvents
207
208 octets := counters.Upstream.GetOctets()
209 onuStats.UOctets = &octets
210
211 frames := counters.Upstream.GetFrames()
212 onuStats.UFrames = &frames
213
214 broadcastFrames := counters.Upstream.GetBroadcastFrames()
215 onuStats.UBroadcastFrames = &broadcastFrames
216
217 multicastFrames := counters.Upstream.GetMulticastFrames()
218 onuStats.UMulticastFrames = &multicastFrames
219
220 crcErroredFrames := counters.Upstream.GetCrcErroredFrames()
221 onuStats.UCrcErroredFrames = &crcErroredFrames
222
223 undersizeFrames := counters.Upstream.GetUndersizeFrames()
224 onuStats.UUndersizeFrames = &undersizeFrames
225
226 oversizeFrames := counters.Upstream.GetOversizeFrames()
227 onuStats.UOversizeFrames = &oversizeFrames
228
229 frames_64Octets := counters.Upstream.GetFrames_64Octets()
230 onuStats.UFrames_64Octets = &frames_64Octets
231
232 frames_65To_127Octets := counters.Upstream.GetFrames_65To_127Octets()
233 onuStats.UFrames_65To_127Octets = &frames_65To_127Octets
234
235 frames_128To_255Octets := counters.Upstream.GetFrames_128To_255Octets()
236 onuStats.UFrames_128To_255Octets = &frames_128To_255Octets
237
238 frames_256To_511Octets := counters.Upstream.GetFrames_256To_511Octets()
239 onuStats.UFrames_256To_511Octets = &frames_256To_511Octets
240
241 frames_512To_1023Octets := counters.Upstream.GetFrames_512To_1023Octets()
242 onuStats.UFrames_512To_1023Octets = &frames_512To_1023Octets
243
244 frames_1024To_1518Octets := counters.Upstream.GetFrames_1024To_1518Octets()
245 onuStats.UFrames_1024To_1518Octets = &frames_1024To_1518Octets
246
247 dDropEvents := counters.Downstream.GetDropEvents()
248 onuStats.DDropEvents = &dDropEvents
249
250 dOctets := counters.Downstream.GetOctets()
251 onuStats.DOctets = &dOctets
252
253 dFrames := counters.Downstream.GetFrames()
254 onuStats.DFrames = &dFrames
255
256 dBroadcastFrames := counters.Downstream.GetBroadcastFrames()
257 onuStats.DBroadcastFrames = &dBroadcastFrames
258
259 dMulticastFrames := counters.Downstream.GetMulticastFrames()
260 onuStats.DMulticastFrames = &dMulticastFrames
261
262 dCrcErroredFrames := counters.Downstream.GetCrcErroredFrames()
263 onuStats.DCrcErroredFrames = &dCrcErroredFrames
264
265 dUndersizeFrames := counters.Downstream.GetUndersizeFrames()
266 onuStats.DUndersizeFrames = &dUndersizeFrames
267
268 dOversizeFrames := counters.Downstream.GetOversizeFrames()
269 onuStats.DOversizeFrames = &dOversizeFrames
270
271 dFrames_64Octets := counters.Downstream.GetFrames_64Octets()
272 onuStats.DFrames_64Octets = &dFrames_64Octets
273
274 dFrames_65To_127Octets := counters.Downstream.GetFrames_65To_127Octets()
275 onuStats.DFrames_65To_127Octets = &dFrames_65To_127Octets
276
277 dFrames_128To_255Octets := counters.Downstream.GetFrames_128To_255Octets()
278 onuStats.DFrames_128To_255Octets = &dFrames_128To_255Octets
279
280 dFrames_256To_511Octets := counters.Downstream.GetFrames_256To_511Octets()
281 onuStats.DFrames_256To_511Octets = &dFrames_256To_511Octets
282
283 dFrames_512To_1023Octets := counters.Downstream.GetFrames_512To_1023Octets()
284 onuStats.DFrames_512To_1023Octets = &dFrames_512To_1023Octets
285
286 dFrames_1024To_1518Octets := counters.Downstream.GetFrames_1024To_1518Octets()
287 onuStats.DFrames_1024To_1518Octets = &dFrames_1024To_1518Octets
288 return onuStats
289}