blob: 8b84a0aeaf3c201696e2c05e49e90108005a5dd9 [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"
21 "github.com/opencord/voltha-protos/v4/go/extension"
22 "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
203 dropEvents := counters.Upstream.GetDropEvents()
204 onuStats.UDropEvents = &dropEvents
205
206 octets := counters.Upstream.GetOctets()
207 onuStats.UOctets = &octets
208
209 frames := counters.Upstream.GetFrames()
210 onuStats.UFrames = &frames
211
212 broadcastFrames := counters.Upstream.GetBroadcastFrames()
213 onuStats.UBroadcastFrames = &broadcastFrames
214
215 multicastFrames := counters.Upstream.GetMulticastFrames()
216 onuStats.UMulticastFrames = &multicastFrames
217
218 crcErroredFrames := counters.Upstream.GetCrcErroredFrames()
219 onuStats.UCrcErroredFrames = &crcErroredFrames
220
221 undersizeFrames := counters.Upstream.GetUndersizeFrames()
222 onuStats.UUndersizeFrames = &undersizeFrames
223
224 oversizeFrames := counters.Upstream.GetOversizeFrames()
225 onuStats.UOversizeFrames = &oversizeFrames
226
227 frames_64Octets := counters.Upstream.GetFrames_64Octets()
228 onuStats.UFrames_64Octets = &frames_64Octets
229
230 frames_65To_127Octets := counters.Upstream.GetFrames_65To_127Octets()
231 onuStats.UFrames_65To_127Octets = &frames_65To_127Octets
232
233 frames_128To_255Octets := counters.Upstream.GetFrames_128To_255Octets()
234 onuStats.UFrames_128To_255Octets = &frames_128To_255Octets
235
236 frames_256To_511Octets := counters.Upstream.GetFrames_256To_511Octets()
237 onuStats.UFrames_256To_511Octets = &frames_256To_511Octets
238
239 frames_512To_1023Octets := counters.Upstream.GetFrames_512To_1023Octets()
240 onuStats.UFrames_512To_1023Octets = &frames_512To_1023Octets
241
242 frames_1024To_1518Octets := counters.Upstream.GetFrames_1024To_1518Octets()
243 onuStats.UFrames_1024To_1518Octets = &frames_1024To_1518Octets
244
245 dDropEvents := counters.Downstream.GetDropEvents()
246 onuStats.DDropEvents = &dDropEvents
247
248 dOctets := counters.Downstream.GetOctets()
249 onuStats.DOctets = &dOctets
250
251 dFrames := counters.Downstream.GetFrames()
252 onuStats.DFrames = &dFrames
253
254 dBroadcastFrames := counters.Downstream.GetBroadcastFrames()
255 onuStats.DBroadcastFrames = &dBroadcastFrames
256
257 dMulticastFrames := counters.Downstream.GetMulticastFrames()
258 onuStats.DMulticastFrames = &dMulticastFrames
259
260 dCrcErroredFrames := counters.Downstream.GetCrcErroredFrames()
261 onuStats.DCrcErroredFrames = &dCrcErroredFrames
262
263 dUndersizeFrames := counters.Downstream.GetUndersizeFrames()
264 onuStats.DUndersizeFrames = &dUndersizeFrames
265
266 dOversizeFrames := counters.Downstream.GetOversizeFrames()
267 onuStats.DOversizeFrames = &dOversizeFrames
268
269 dFrames_64Octets := counters.Downstream.GetFrames_64Octets()
270 onuStats.DFrames_64Octets = &dFrames_64Octets
271
272 dFrames_65To_127Octets := counters.Downstream.GetFrames_65To_127Octets()
273 onuStats.DFrames_65To_127Octets = &dFrames_65To_127Octets
274
275 dFrames_128To_255Octets := counters.Downstream.GetFrames_128To_255Octets()
276 onuStats.DFrames_128To_255Octets = &dFrames_128To_255Octets
277
278 dFrames_256To_511Octets := counters.Downstream.GetFrames_256To_511Octets()
279 onuStats.DFrames_256To_511Octets = &dFrames_256To_511Octets
280
281 dFrames_512To_1023Octets := counters.Downstream.GetFrames_512To_1023Octets()
282 onuStats.DFrames_512To_1023Octets = &dFrames_512To_1023Octets
283
284 dFrames_1024To_1518Octets := counters.Downstream.GetFrames_1024To_1518Octets()
285 onuStats.DFrames_1024To_1518Octets = &dFrames_1024To_1518Octets
286 return onuStats
287}