blob: 6dbddbdf14ae224bfbcc4141e058277402e524ce [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2 * Copyright 2020-present Open Networking Foundation
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 */
16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package common provides global definitions
18package common
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "container/list"
22 "context"
23 "encoding/binary"
24 "encoding/hex"
Andrea Campanella6515c582020-10-05 11:25:00 +020025 "fmt"
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000026 "strconv"
Holger Hildebrandt93d183f2022-04-22 15:50:26 +000027 "strings"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028 "sync"
mpagenko80622a52021-02-09 16:53:23 +000029 "time" //by now for testing
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030
31 "github.com/google/gopacket"
32 // TODO!!! Some references could be resolved auto, but some need specific context ....
33 gp "github.com/google/gopacket"
34
mpagenko836a1fd2021-11-01 16:12:42 +000035 "github.com/opencord/omci-lib-go/v2"
36 me "github.com/opencord/omci-lib-go/v2/generated"
37 oframe "github.com/opencord/omci-lib-go/v2/meframe"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000038
khenaidoo7d3c5582021-08-11 18:09:44 -040039 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
40
khenaidoo7d3c5582021-08-11 18:09:44 -040041 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoo42dcdfd2021-10-19 17:34:12 -040042 "github.com/opencord/voltha-protos/v5/go/common"
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +000043 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo42dcdfd2021-10-19 17:34:12 -040044 ia "github.com/opencord/voltha-protos/v5/go/inter_adapter"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000045)
46
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000047// ### OMCI related definitions - retrieved from Python adapter code/trace ####
Himani Chawla6d2ae152020-09-02 13:11:20 +053048
Holger Hildebrandt9b64e0b2022-04-21 08:02:00 +000049const maxGemPayloadSize = uint16(2048)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000050const connectivityModeValue = uint8(5)
Himani Chawla4d908332020-08-31 12:30:20 +053051
52//const defaultTPID = uint16(0x8100)
53//const broadComDefaultVID = uint16(4091)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000054
55// UnusedTcontAllocID - TODO: add comment
56const UnusedTcontAllocID = uint16(0xFFFF) //common unused AllocId for G.984 and G.987 systems
mpagenko8b07c1b2020-11-26 10:36:31 +000057
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +000058const cOmciDeviceIdentifierPos = 3
mpagenkoc8bba412021-01-15 15:38:44 +000059const cOmciBaseMessageTrailerLen = 40
60
61// tOmciReceiveError - enum type for detected problems/errors in the received OMCI message (format)
62type tOmciReceiveError uint8
63
64const (
65 // cOmciMessageReceiveNoError - default start state
66 cOmciMessageReceiveNoError tOmciReceiveError = iota
67 // Error indication wrong trailer length within the message
68 cOmciMessageReceiveErrorTrailerLen
69 // Error indication missing trailer within the message
70 cOmciMessageReceiveErrorMissTrailer
71)
72
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000073// CDefaultRetries - TODO: add comment
74const CDefaultRetries = 2
Holger Hildebrandt366ef192021-05-05 11:07:44 +000075
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000076// ### OMCI related definitions - end
77
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000078//CallbackPairEntry to be used for OMCI send/receive correlation
79type CallbackPairEntry struct {
80 CbRespChannel chan Message
81 CbFunction func(context.Context, *omci.OMCI, *gp.Packet, chan Message) error
82 FramePrint bool //true for printing
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000083}
84
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000085//CallbackPair to be used for ReceiveCallback init
86type CallbackPair struct {
87 CbKey uint16
88 CbEntry CallbackPairEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089}
90
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000091// OmciTransferStructure - TODO: add comment
92type OmciTransferStructure struct {
mpagenko80622a52021-02-09 16:53:23 +000093 txFrame []byte
94 timeout int
Holger Hildebrandt366ef192021-05-05 11:07:44 +000095 retries int
mpagenko80622a52021-02-09 16:53:23 +000096 highPrio bool
97 withFramePrint bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000098 cbPair CallbackPair
Holger Hildebrandt366ef192021-05-05 11:07:44 +000099 chSuccess chan bool
kesavand011d5162021-11-25 19:21:06 +0530100 OnuSwWindow *ia.OmciMessages
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000101}
102
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000103type txRxCounters struct {
104 txArFrames uint32
105 txNoArFrames uint32
106 rxAkFrames uint32
107 rxNoAkFrames uint32
108}
109
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000110//OmciCC structure holds information needed for OMCI communication (to/from OLT Adapter)
111type OmciCC struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000112 enabled bool
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000113 pBaseDeviceHandler IdeviceHandler
114 pOnuDeviceEntry IonuDeviceEntry
115 pOnuAlarmManager IonuAlarmManager
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116 deviceID string
khenaidoo7d3c5582021-08-11 18:09:44 -0400117 coreClient *vgrpc.Client
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000118 supportExtMsg bool
mpagenkoc8bba412021-01-15 15:38:44 +0000119 rxOmciFrameError tOmciReceiveError
120
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000121 mutexCounters sync.RWMutex
122 countersBase txRxCounters
123 countersExt txRxCounters
124 txRetries uint32
125 txTimeouts uint32
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126
127 // OMCI params
128 mutexTid sync.Mutex
129 tid uint16
130 mutexHpTid sync.Mutex
131 hpTid uint16
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000132 UploadSequNo uint16
133 UploadNoOfCmds uint16
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000134
Holger Hildebrandt556d56c2022-12-07 09:23:49 +0000135 mutexSendQueuedRequests sync.Mutex
136 mutexLowPrioTxQueue sync.Mutex
137 lowPrioTxQueue *list.List
138 mutexHighPrioTxQueue sync.Mutex
139 highPrioTxQueue *list.List
140 mutexRxSchedMap sync.Mutex
141 rxSchedulerMap map[uint16]CallbackPairEntry
142 mutexMonReq sync.RWMutex
143 monitoredRequests map[uint16]OmciTransferStructure
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000144}
145
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000146var responsesWithMibDataSync = []omci.MessageType{
147 omci.CreateResponseType,
148 omci.DeleteResponseType,
149 omci.SetResponseType,
150 omci.StartSoftwareDownloadResponseType,
151 omci.EndSoftwareDownloadResponseType,
152 omci.ActivateSoftwareResponseType,
153 omci.CommitSoftwareResponseType,
154}
155
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000156//NewOmciCC constructor returns a new instance of a OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000157//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000158func NewOmciCC(ctx context.Context, deviceID string, deviceHandler IdeviceHandler,
159 onuDeviceEntry IonuDeviceEntry, onuAlarmManager IonuAlarmManager,
160 coreClient *vgrpc.Client) *OmciCC {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000161 logger.Debugw(ctx, "init-omciCC", log.Fields{"device-id": deviceID})
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000162 var omciCC OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000163 omciCC.enabled = false
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000164 omciCC.pBaseDeviceHandler = deviceHandler
165 omciCC.pOnuAlarmManager = onuAlarmManager
Himani Chawla4d908332020-08-31 12:30:20 +0530166 omciCC.pOnuDeviceEntry = onuDeviceEntry
167 omciCC.deviceID = deviceID
khenaidoo7d3c5582021-08-11 18:09:44 -0400168 omciCC.coreClient = coreClient
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000169 omciCC.supportExtMsg = false
mpagenkoc8bba412021-01-15 15:38:44 +0000170 omciCC.rxOmciFrameError = cOmciMessageReceiveNoError
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000171 omciCC.countersBase = txRxCounters{0, 0, 0, 0}
172 omciCC.countersExt = txRxCounters{0, 0, 0, 0}
173 omciCC.txRetries = 0
174 omciCC.txTimeouts = 0
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175 omciCC.tid = 0x1
176 omciCC.hpTid = 0x8000
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000177 omciCC.UploadSequNo = 0
178 omciCC.UploadNoOfCmds = 0
Holger Hildebrandt34555512021-10-01 16:26:59 +0000179 omciCC.lowPrioTxQueue = list.New()
180 omciCC.highPrioTxQueue = list.New()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000181 omciCC.rxSchedulerMap = make(map[uint16]CallbackPairEntry)
182 omciCC.monitoredRequests = make(map[uint16]OmciTransferStructure)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000183 return &omciCC
184}
185
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000186//Stop stops/resets the omciCC
187func (oo *OmciCC) Stop(ctx context.Context) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000188 logger.Debugw(ctx, "omciCC-stopping", log.Fields{"device-id": oo.deviceID})
mpagenko900ee4b2020-10-12 11:56:34 +0000189 //reseting all internal data, which might also be helpful for discarding any lingering tx/rx requests
mpagenko8cd1bf72021-06-22 10:11:19 +0000190 oo.CancelRequestMonitoring(ctx)
Holger Hildebrandt34555512021-10-01 16:26:59 +0000191 // clear the tx queues
192 oo.mutexHighPrioTxQueue.Lock()
193 oo.highPrioTxQueue.Init()
194 oo.mutexHighPrioTxQueue.Unlock()
195 oo.mutexLowPrioTxQueue.Lock()
196 oo.lowPrioTxQueue.Init()
197 oo.mutexLowPrioTxQueue.Unlock()
198 //clear the scheduler map
mpagenko900ee4b2020-10-12 11:56:34 +0000199 oo.mutexRxSchedMap.Lock()
200 for k := range oo.rxSchedulerMap {
Holger Hildebrandt34555512021-10-01 16:26:59 +0000201 delete(oo.rxSchedulerMap, k)
mpagenko900ee4b2020-10-12 11:56:34 +0000202 }
203 oo.mutexRxSchedMap.Unlock()
Holger Hildebrandt34555512021-10-01 16:26:59 +0000204 //reset the high prio transactionId
mpagenko900ee4b2020-10-12 11:56:34 +0000205 oo.mutexHpTid.Lock()
Holger Hildebrandt34555512021-10-01 16:26:59 +0000206 oo.hpTid = 0x8000
mpagenko900ee4b2020-10-12 11:56:34 +0000207 oo.mutexHpTid.Unlock()
Holger Hildebrandt34555512021-10-01 16:26:59 +0000208 //reset the low prio transactionId
mpagenko900ee4b2020-10-12 11:56:34 +0000209 oo.mutexTid.Lock()
Holger Hildebrandt34555512021-10-01 16:26:59 +0000210 oo.tid = 1
mpagenko900ee4b2020-10-12 11:56:34 +0000211 oo.mutexTid.Unlock()
212 //reset control values
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000213 oo.UploadSequNo = 0
214 oo.UploadNoOfCmds = 0
mpagenkoc8bba412021-01-15 15:38:44 +0000215 oo.rxOmciFrameError = cOmciMessageReceiveNoError
mpagenko900ee4b2020-10-12 11:56:34 +0000216
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000217 //reset the stats counter
218 oo.mutexCounters.Lock()
219 oo.countersBase = txRxCounters{0, 0, 0, 0}
220 oo.countersExt = txRxCounters{0, 0, 0, 0}
221 oo.txRetries = 0
222 oo.txTimeouts = 0
223 oo.mutexCounters.Unlock()
mpagenko900ee4b2020-10-12 11:56:34 +0000224 return nil
225}
226
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000227// Rx handler for omci messages
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000228func (oo *OmciCC) receiveOnuMessage(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000229 logger.Debugw(ctx, "rx-onu-autonomous-message", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000230 "payload": hex.EncodeToString(omciMsg.Payload)})
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530231 switch omciMsg.MessageType {
232 case omci.AlarmNotificationType:
233 data := OmciMessage{
234 OmciMsg: omciMsg,
235 OmciPacket: packet,
236 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000237 go oo.pOnuAlarmManager.HandleOmciAlarmNotificationMessage(ctx, data)
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530238 return nil
239 default:
240 return fmt.Errorf("receiveOnuMessageType %s unimplemented", omciMsg.MessageType.String())
241 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000242 /*
243 msgType = rxFrame.fields["message_type"] //assumed OmciOperationsValue
244 rxOnuFrames++
245
246 switch msgType {
247 case AlarmNotification:
248 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000249 logger.Info("Unhandled: received-onu-alarm-message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000250 // python code was:
251 //if msg_type == EntityOperations.AlarmNotification.value:
252 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Alarm_Notification)
253 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
254 //
255 return errors.New("RxAlarmNotification unimplemented")
256 }
257 case AttributeValueChange:
258 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000259 logger.Info("Unhandled: received-attribute-value-change")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000260 // python code was:
261 //elif msg_type == EntityOperations.AttributeValueChange.value:
262 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.AVC_Notification)
263 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
264 //
265 return errors.New("RxAttributeValueChange unimplemented")
266 }
267 case TestResult:
268 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000269 logger.Info("Unhandled: received-test-result")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000270 // python code was:
271 //elif msg_type == EntityOperations.TestResult.value:
272 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Test_Result)
273 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
274 //
275 return errors.New("RxTestResult unimplemented")
276 }
277 default:
278 {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000279 logger.Errorw(ctx,"rx-onu-unsupported-autonomous-message", log.Fields{"msgType": msgType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280 rxOnuDiscards++
281 return errors.New("RxOnuMsgType unimplemented")
282 }
283 }
284 */
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000285}
286
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000287func (oo *OmciCC) printRxMessage(ctx context.Context, rxMsg []byte) {
mpagenko80622a52021-02-09 16:53:23 +0000288 //assuming omci message content is hex coded!
289 // with restricted output of 16bytes would be ...rxMsg[:16]
290 logger.Debugw(ctx, "omci-message-received:", log.Fields{
291 "RxOmciMessage": hex.EncodeToString(rxMsg),
292 "device-id": oo.deviceID})
293}
294
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000295// ReceiveMessage - Rx handler for onu messages
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000296// e.g. would call ReceiveOnuMessage() in case of TID=0 or Action=test ...
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000297// nolint: gocyclo
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000298func (oo *OmciCC) ReceiveMessage(ctx context.Context, rxMsg []byte) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000299 //logger.Debugw(ctx,"cc-receive-omci-message", log.Fields{"RxOmciMessage-x2s": hex.EncodeToString(rxMsg)})
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000300
301 if len(rxMsg) < 10 {
302 logger.Errorw(ctx, "rxOmciMessage has wrong length in general - abort",
303 log.Fields{"Length": len(rxMsg), "device-id": oo.deviceID})
304 if len(rxMsg) > 0 {
305 oo.printRxMessage(ctx, rxMsg)
mpagenkoc8bba412021-01-15 15:38:44 +0000306 }
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000307 return fmt.Errorf("rxOmciMessage has wrong length in general - abort %s", oo.deviceID)
308 }
309 if rxMsg[cOmciDeviceIdentifierPos] == byte(omci.BaselineIdent) {
310 if len(rxMsg) >= 44 { // then it should normally include the BaseFormat trailer Len
311 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
312 // (an extendedFormat message could be destroyed this way!)
313 trailerLenData := rxMsg[42:44]
314 trailerLen := binary.BigEndian.Uint16(trailerLenData)
315 //logger.Debugw(ctx,"omci-received-trailer-len", log.Fields{"Length": trailerLen})
316 if trailerLen != cOmciBaseMessageTrailerLen { // invalid base Format entry -> autocorrect
317 binary.BigEndian.PutUint16(rxMsg[42:44], cOmciBaseMessageTrailerLen)
318 if oo.rxOmciFrameError != cOmciMessageReceiveErrorTrailerLen {
319 //do just one error log, expectation is: if seen once it should appear regularly - avoid to many log entries
320 logger.Errorw(ctx, "wrong omci-message trailer length: trailer len auto-corrected",
321 log.Fields{"trailer-length": trailerLen, "device-id": oo.deviceID})
322 oo.rxOmciFrameError = cOmciMessageReceiveErrorTrailerLen
323 }
324 }
325 } else if len(rxMsg) >= cOmciBaseMessageTrailerLen { // workaround for Adtran OLT Sim, which currently does not send trailer bytes at all!
326 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
327 // (an extendedFormat message could be destroyed this way!)
328 // extend/overwrite with trailer
329 trailer := make([]byte, 8)
330 binary.BigEndian.PutUint16(trailer[2:], cOmciBaseMessageTrailerLen) //set the defined baseline length
331 rxMsg = append(rxMsg[:cOmciBaseMessageTrailerLen], trailer...)
332 if oo.rxOmciFrameError != cOmciMessageReceiveErrorMissTrailer {
333 //do just one error log, expectation is: if seen once it should appear regularly - avoid to many log entries
334 logger.Errorw(ctx, "omci-message to short to include trailer len: trailer auto-corrected (added)",
335 log.Fields{"message-length": len(rxMsg), "device-id": oo.deviceID})
336 oo.rxOmciFrameError = cOmciMessageReceiveErrorMissTrailer
337 }
338 } else {
339 logger.Errorw(ctx, "received omci-message too small for OmciBaseFormat - abort",
340 log.Fields{"Length": len(rxMsg), "device-id": oo.deviceID})
341 oo.printRxMessage(ctx, rxMsg)
342 return fmt.Errorf("rxOmciMessage too small for BaseFormat %s", oo.deviceID)
343 }
344 } else if rxMsg[cOmciDeviceIdentifierPos] == byte(omci.ExtendedIdent) {
345 if len(rxMsg) > 1980 {
346 logger.Errorw(ctx, "rxOmciMessage has wrong length for OmciExtendedFormat - abort",
347 log.Fields{"Length": len(rxMsg), "device-id": oo.deviceID})
348 oo.printRxMessage(ctx, rxMsg)
349 return fmt.Errorf("rxOmciMessage has wrong length for OmciExtendedFormat %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000350 }
351 } else {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000352 logger.Errorw(ctx, "rxOmciMessage has wrong Device Identifier - abort",
mpagenkoc8bba412021-01-15 15:38:44 +0000353 log.Fields{"Length": len(rxMsg), "device-id": oo.deviceID})
mpagenko80622a52021-02-09 16:53:23 +0000354 oo.printRxMessage(ctx, rxMsg)
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000355 return fmt.Errorf("rxOmciMessage has wrong Device Identifier %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000356 }
Holger Hildebrandt36747fd2022-03-14 09:47:17 +0000357 decodeOptions := gopacket.DecodeOptions{
358 Lazy: true,
359 NoCopy: true,
360 }
361 packet := gopacket.NewPacket(rxMsg, omci.LayerTypeOMCI, decodeOptions)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000362 if packet == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000363 logger.Errorw(ctx, "omci-message could not be decoded", log.Fields{"device-id": oo.deviceID})
mpagenko80622a52021-02-09 16:53:23 +0000364 oo.printRxMessage(ctx, rxMsg)
Andrea Campanella6515c582020-10-05 11:25:00 +0200365 return fmt.Errorf("could not decode rxMsg as OMCI %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000366 }
367 omciLayer := packet.Layer(omci.LayerTypeOMCI)
368 if omciLayer == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000369 logger.Errorw(ctx, "omci-message could not decode omci layer", log.Fields{"device-id": oo.deviceID})
mpagenko80622a52021-02-09 16:53:23 +0000370 oo.printRxMessage(ctx, rxMsg)
Andrea Campanella6515c582020-10-05 11:25:00 +0200371 return fmt.Errorf("could not decode omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000372 }
mpagenko836a1fd2021-11-01 16:12:42 +0000373 // insert some check on detected OMCI decoding issues and log them
374 // e.g. should indicate problems when detecting some unknown attribute mask content (independent from message type)
375 // even though allowed from omci-lib due to set relaxed decoding
376 // application may dig into further details if wanted/needed on their own [but info is not transferred from here so far]
377 // (compare mib_sync.go unknownAttrLayer)
378 errLayer := packet.Layer(gopacket.LayerTypeDecodeFailure)
379 if failure, decodeOk := errLayer.(*gopacket.DecodeFailure); decodeOk {
380 errMsg := failure.Error()
381 logger.Warnw(ctx, "Detected decode issue on received OMCI frame", log.Fields{
382 "device-id": oo.deviceID, "issue": errMsg})
383 }
384 //anyway try continue OMCI decoding further on message type layer
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000385 omciMsg, ok := omciLayer.(*omci.OMCI)
386 if !ok {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000387 logger.Errorw(ctx, "omci-message could not assign omci layer", log.Fields{"device-id": oo.deviceID})
mpagenko80622a52021-02-09 16:53:23 +0000388 oo.printRxMessage(ctx, rxMsg)
Andrea Campanella6515c582020-10-05 11:25:00 +0200389 return fmt.Errorf("could not assign omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000390 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000391 logger.Debugw(ctx, "omci-message-decoded:", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandt36747fd2022-03-14 09:47:17 +0000392 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16),
393 "DeviceIdent": omciMsg.DeviceIdentifier, "device-id": oo.deviceID})
mpagenko836a1fd2021-11-01 16:12:42 +0000394
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700395 // TestResult is asynchronous indication that carries the same TID as the TestResponse.
396 // We expect to find the TID in the oo.rxSchedulerMap
397 if byte(omciMsg.MessageType)&me.AK == 0 && omciMsg.MessageType != omci.TestResultType {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000398 // Not a response
mpagenko80622a52021-02-09 16:53:23 +0000399 oo.printRxMessage(ctx, rxMsg)
Holger Hildebrandt36747fd2022-03-14 09:47:17 +0000400 logger.Debugw(ctx, "RxMsg is no Omci Response Message", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000401 if omciMsg.TransactionID == 0 {
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000402 if rxMsg[cOmciDeviceIdentifierPos] == byte(omci.BaselineIdent) {
403 oo.incrementBaseRxNoAkFrames()
404 } else {
405 oo.incrementExtRxNoAkFrames()
406 }
Himani Chawlaac1f5ad2021-02-04 21:21:54 +0530407 return oo.receiveOnuMessage(ctx, omciMsg, &packet)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000408 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000409 logger.Errorw(ctx, "Unexpected TransCorrId != 0 not accepted for autonomous messages",
Andrea Campanella6515c582020-10-05 11:25:00 +0200410 log.Fields{"msgType": omciMsg.MessageType, "payload": hex.EncodeToString(omciMsg.Payload),
mpagenko8b07c1b2020-11-26 10:36:31 +0000411 "device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200412 return fmt.Errorf("autonomous Omci Message with TranSCorrId != 0 not acccepted %s", oo.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530413 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000414 //logger.Debug(ctx,"RxMsg is a Omci Response Message: try to schedule it to the requester")
Himani Chawla4d908332020-08-31 12:30:20 +0530415 oo.mutexRxSchedMap.Lock()
416 rxCallbackEntry, ok := oo.rxSchedulerMap[omciMsg.TransactionID]
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000417 if ok && rxCallbackEntry.CbFunction != nil {
Holger Hildebrandt68854a82022-09-05 07:00:21 +0000418
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000419 if rxCallbackEntry.FramePrint {
mpagenko80622a52021-02-09 16:53:23 +0000420 oo.printRxMessage(ctx, rxMsg)
421 }
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000422 if rxMsg[cOmciDeviceIdentifierPos] == byte(omci.BaselineIdent) {
423 oo.incrementBaseRxAkFrames()
424 } else {
425 oo.incrementExtRxAkFrames()
426 }
Himani Chawla4d908332020-08-31 12:30:20 +0530427 //disadvantage of decoupling: error verification made difficult, but anyway the question is
428 // how to react on erroneous frame reception, maybe can simply be ignored
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000429 go rxCallbackEntry.CbFunction(ctx, omciMsg, &packet, rxCallbackEntry.CbRespChannel)
Holger Hildebrandt36747fd2022-03-14 09:47:17 +0000430 isSuccessfulResponse, err := oo.isSuccessfulResponseWithMibDataSync(ctx, omciMsg, &packet)
431 if err != nil {
432 // qualified error logging already done in function above
433 if !rxCallbackEntry.FramePrint {
434 oo.printRxMessage(ctx, rxMsg)
435 }
436 return fmt.Errorf("could not decode further layers %s", oo.deviceID)
437 }
438 if isSuccessfulResponse {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000439 oo.pOnuDeviceEntry.IncrementMibDataSync(ctx)
Holger Hildebrandt36747fd2022-03-14 09:47:17 +0000440 } else {
441 logger.Debugw(ctx, "mibDataSync counter not to be updated for this message type",
442 log.Fields{"omciMsg.MessageType": omciMsg.MessageType, "device-id": oo.deviceID})
Holger Hildebrandt0bd45f82021-01-11 13:29:37 +0000443 }
mpagenkoc8bba412021-01-15 15:38:44 +0000444
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700445 // If omciMsg.MessageType is omci.TestResponseType, we still expect the TestResult OMCI message,
446 // so do not clean up the TransactionID in that case.
447 if omciMsg.MessageType != omci.TestResponseType {
448 // having posted the response the request is regarded as 'done'
449 delete(oo.rxSchedulerMap, omciMsg.TransactionID)
450 }
Himani Chawla4d908332020-08-31 12:30:20 +0530451 oo.mutexRxSchedMap.Unlock()
mpagenko80622a52021-02-09 16:53:23 +0000452 return nil
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000453 }
mpagenko80622a52021-02-09 16:53:23 +0000454 oo.mutexRxSchedMap.Unlock()
455 logger.Errorw(ctx, "omci-message-response for not registered transCorrId", log.Fields{"device-id": oo.deviceID})
456 oo.printRxMessage(ctx, rxMsg)
457 return fmt.Errorf("could not find registered response handler tor transCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000458
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000459 /* py code was:
460 Receive and OMCI message from the proxy channel to the OLT.
461
462 Call this from your ONU Adapter on a new OMCI Rx on the proxy channel
463 :param msg: (str) OMCI binary message (used as input to Scapy packet decoder)
464 """
465 if not self.enabled:
466 return
467
468 try:
469 now = arrow.utcnow()
470 d = None
471
472 # NOTE: Since we may need to do an independent ME map on a per-ONU basis
473 # save the current value of the entity_id_to_class_map, then
474 # replace it with our custom one before decode, and then finally
475 # restore it later. Tried other ways but really made the code messy.
476 saved_me_map = omci_entities.entity_id_to_class_map
477 omci_entities.entity_id_to_class_map = self._me_map
478
479 try:
480 rx_frame = msg if isinstance(msg, OmciFrame) else OmciFrame(msg)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000481 self.logger.debug('recv-omci-msg', omci_msg=hexlify(msg))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000482 except KeyError as e:
483 # Unknown, Unsupported, or vendor-specific ME. Key is the unknown classID
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000484 self.logger.debug('frame-decode-key-error', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000485 rx_frame = self._decode_unknown_me(msg)
486 self._rx_unknown_me += 1
487
488 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000489 self.logger.exception('frame-decode', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000490 return
491
492 finally:
493 omci_entities.entity_id_to_class_map = saved_me_map # Always restore it.
494
495 rx_tid = rx_frame.fields['transaction_id']
496 msg_type = rx_frame.fields['message_type']
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000497 self.logger.debug('Received message for rx_tid', rx_tid = rx_tid, msg_type = msg_type)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000498 # Filter the Test Result frame and route through receive onu
499 # message method.
500 if rx_tid == 0 or msg_type == EntityOperations.TestResult.value:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000501 self.logger.debug('Receive ONU message', rx_tid=0)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000502 return self._receive_onu_message(rx_frame)
503
504 # Previously unreachable if this is the very first round-trip Rx or we
505 # have been running consecutive errors
506 if self._rx_frames == 0 or self._consecutive_errors != 0:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000507 self.logger.debug('Consecutive errors for rx', err = self._consecutive_errors)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000508 self.reactor.callLater(0, self._publish_connectivity_event, True)
509
510 self._rx_frames += 1
511 self._consecutive_errors = 0
512
513 try:
514 high_priority = self._tid_is_high_priority(rx_tid)
515 index = self._get_priority_index(high_priority)
516
517 # (timestamp, defer, frame, timeout, retry, delayedCall)
518 last_tx_tuple = self._tx_request[index]
519
520 if last_tx_tuple is None or \
521 last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id') != rx_tid:
522 # Possible late Rx on a message that timed-out
523 if last_tx_tuple:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000524 self.logger.debug('Unknown message', rx_tid=rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000525 tx_id=last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id'))
526 self._rx_unknown_tid += 1
527 self._rx_late += 1
528 return
529
530 ts, d, tx_frame, timeout, retry, dc = last_tx_tuple
531 if dc is not None and not dc.cancelled and not dc.called:
532 dc.cancel()
533
534 _secs = self._update_rx_tx_stats(now, ts)
535
536 # Late arrival already serviced by a timeout?
537 if d.called:
538 self._rx_late += 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000539 self.logger.debug('Serviced by timeout. Late arrival', rx_late = self._rx_late)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000540 return
541
542 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000543 self.logger.exception('frame-match', msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000544 if d is not None:
545 return d.errback(failure.Failure(e))
546 return
547
548 # Publish Rx event to listeners in a different task
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000549 self.logger.debug('Publish rx event', rx_tid = rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000550 tx_tid = tx_frame.fields['transaction_id'])
551 reactor.callLater(0, self._publish_rx_frame, tx_frame, rx_frame)
552
553 # begin success callback chain (will cancel timeout and queue next Tx message)
554 self._rx_response[index] = rx_frame
555 d.callback(rx_frame)
556
557 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000558 self.logger.exception('rx-msg', e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000559 */
560}
561
Himani Chawla6d2ae152020-09-02 13:11:20 +0530562/*
563func (oo *omciCC) publishRxResponseFrame(ctx context.Context, txFrame []byte, rxFrame []byte) error {
Himani Chawla4d908332020-08-31 12:30:20 +0530564 return errors.New("publishRxResponseFrame unimplemented")
Himani Chawla6d2ae152020-09-02 13:11:20 +0530565 //def _publish_rx_frame(self, tx_frame, rx_frame):
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000566}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530567*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000568
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700569// ReleaseTid releases OMCI transaction identifier from rxSchedulerMap
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000570func (oo *OmciCC) ReleaseTid(ctx context.Context, tid uint16) {
Girish Gowdra6afb56a2021-04-27 17:47:57 -0700571 logger.Debugw(ctx, "releasing tid from rxSchedulerMap", log.Fields{"tid": tid})
572 delete(oo.rxSchedulerMap, tid)
573}
574
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000575// Send - Queue the OMCI Frame for a transmit to the ONU via the proxy_channel
576func (oo *OmciCC) Send(ctx context.Context, txFrame []byte, timeout int, retry int, highPrio bool,
577 receiveCallbackPair CallbackPair) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000578
mpagenkoc26d4c02021-05-06 14:27:57 +0000579 if timeout != 0 {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000580 logger.Debugw(ctx, "register-response-callback:", log.Fields{"for TransCorrId": receiveCallbackPair.CbKey})
mpagenkoc26d4c02021-05-06 14:27:57 +0000581 oo.mutexRxSchedMap.Lock()
582 // it could be checked, if the callback key is already registered - but simply overwrite may be acceptable ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000583 oo.rxSchedulerMap[receiveCallbackPair.CbKey] = receiveCallbackPair.CbEntry
mpagenkoc26d4c02021-05-06 14:27:57 +0000584 oo.mutexRxSchedMap.Unlock()
585 } //else timeout 0 indicates that no response is expected - fire and forget
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000586
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000587 printFrame := receiveCallbackPair.CbEntry.FramePrint //printFrame true means debug print of frame is requested
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000588 //just use a simple list for starting - might need some more effort, especially for multi source write access
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000589 omciTxRequest := OmciTransferStructure{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000590 txFrame,
591 timeout,
592 retry,
593 highPrio,
mpagenko80622a52021-02-09 16:53:23 +0000594 printFrame,
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000595 receiveCallbackPair,
596 nil,
kesavand011d5162021-11-25 19:21:06 +0530597 nil,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000598 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000599 oo.mutexMonReq.Lock()
600 defer oo.mutexMonReq.Unlock()
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000601 if _, exist := oo.monitoredRequests[receiveCallbackPair.CbKey]; !exist {
mpagenko7455fd42021-06-10 16:25:55 +0000602 // do not call processRequestMonitoring in background here to ensure correct sequencing
603 // of requested messages into txQueue (especially for non-response-supervised messages)
604 oo.processRequestMonitoring(ctx, omciTxRequest)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000605 return nil
606 }
607 logger.Errorw(ctx, "A message with this tid is processed already!",
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000608 log.Fields{"tid": receiveCallbackPair.CbKey, "device-id": oo.deviceID})
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000609 return fmt.Errorf("message with tid is processed already %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000610}
611
Holger Hildebrandt34555512021-10-01 16:26:59 +0000612func (oo *OmciCC) sendQueuedRequests(ctx context.Context) {
613 // Avoid accessing the txQueues from parallel send routines to block
614 // parallel omci send requests at least until SendIAP is 'committed'.
615 // To guarantee window size 1 for one ONU it would be necessary to wait
616 // for the corresponding response too (t.b.d.).
617 oo.mutexSendQueuedRequests.Lock()
618 defer oo.mutexSendQueuedRequests.Unlock()
619 if err := oo.sendQueuedHighPrioRequests(ctx); err != nil {
620 logger.Errorw(ctx, "Error during sending high prio requests!",
621 log.Fields{"err": err, "device-id": oo.deviceID})
622 return
623 }
624 if err := oo.sendQueuedLowPrioRequests(ctx); err != nil {
625 logger.Errorw(ctx, "Error during sending low prio requests!",
626 log.Fields{"err": err, "device-id": oo.deviceID})
627 return
628 }
629}
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000630
Holger Hildebrandt34555512021-10-01 16:26:59 +0000631func (oo *OmciCC) sendQueuedHighPrioRequests(ctx context.Context) error {
632 oo.mutexHighPrioTxQueue.Lock()
633 defer oo.mutexHighPrioTxQueue.Unlock()
634 for oo.highPrioTxQueue.Len() > 0 {
635 queueElement := oo.highPrioTxQueue.Front() // First element
636 if err := oo.sendOMCIRequest(ctx, queueElement.Value.(OmciTransferStructure)); err != nil {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000637 // Element will be removed from the queue regardless of the send success, to prevent
638 // an accumulation of send requests for the same message in the event of an error.
639 // In this case, resend attempts for the message are ensured by our retry
640 // mechanism after omci-timeout.
641 oo.highPrioTxQueue.Remove(queueElement) // Dequeue
Holger Hildebrandt34555512021-10-01 16:26:59 +0000642 return err
mpagenko80622a52021-02-09 16:53:23 +0000643 }
Holger Hildebrandt34555512021-10-01 16:26:59 +0000644 oo.highPrioTxQueue.Remove(queueElement) // Dequeue
645 }
646 return nil
647}
648
649func (oo *OmciCC) sendQueuedLowPrioRequests(ctx context.Context) error {
650 oo.mutexLowPrioTxQueue.Lock()
651 for oo.lowPrioTxQueue.Len() > 0 {
652 queueElement := oo.lowPrioTxQueue.Front() // First element
kesavand011d5162021-11-25 19:21:06 +0530653 // check if the element is for onu sw section
654 aOmciTxReq := queueElement.Value.(OmciTransferStructure)
655 if aOmciTxReq.OnuSwWindow != nil {
656 if err := oo.sendOnuSwSectionsOfWindow(ctx, aOmciTxReq); err != nil {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000657 // Element will be removed from the queue regardless of the send success, to prevent
658 // an accumulation of send requests for the same message in the event of an error.
659 // In this case, resend attempts for the message are ensured by our retry
660 // mechanism after omci-timeout.
661 oo.lowPrioTxQueue.Remove(queueElement) // Dequeue
kesavand011d5162021-11-25 19:21:06 +0530662 oo.mutexLowPrioTxQueue.Unlock()
663 return err
664 }
665 } else {
666 err := oo.sendOMCIRequest(ctx, queueElement.Value.(OmciTransferStructure))
667 if err != nil {
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000668 // Element will be removed from the queue regardless of the send success, to prevent
669 // an accumulation of send requests for the same message in the event of an error.
670 // In this case, resend attempts for the message are ensured by our retry
671 // mechanism after omci-timeout.
672 oo.lowPrioTxQueue.Remove(queueElement) // Dequeue
kesavand011d5162021-11-25 19:21:06 +0530673 oo.mutexLowPrioTxQueue.Unlock()
674 return err
675 }
amit.ghosh58b704b2021-06-18 03:45:52 +0200676 }
Holger Hildebrandt34555512021-10-01 16:26:59 +0000677 oo.lowPrioTxQueue.Remove(queueElement) // Dequeue
678 // Interrupt the sending of low priority requests to process any high priority requests
679 // that may have arrived in the meantime
680 oo.mutexLowPrioTxQueue.Unlock()
681 if err := oo.sendQueuedHighPrioRequests(ctx); err != nil {
682 return err
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000683 }
Holger Hildebrandt34555512021-10-01 16:26:59 +0000684 oo.mutexLowPrioTxQueue.Lock()
685 }
686
687 oo.mutexLowPrioTxQueue.Unlock()
688 return nil
689}
690
691func (oo *OmciCC) sendOMCIRequest(ctx context.Context, omciTxRequest OmciTransferStructure) error {
692 if omciTxRequest.withFramePrint {
693 logger.Debugw(ctx, "omci-message-to-send:", log.Fields{
694 "TxOmciMessage": hex.EncodeToString(omciTxRequest.txFrame),
695 "device-id": oo.deviceID,
696 "toDeviceType": oo.pBaseDeviceHandler.GetProxyAddressType(),
697 "proxyDeviceID": oo.pBaseDeviceHandler.GetProxyAddressID(),
698 "proxyAddress": oo.pBaseDeviceHandler.GetProxyAddress()})
699 }
khenaidoo42dcdfd2021-10-19 17:34:12 -0400700 omciMsg := &ia.OmciMessage{
Holger Hildebrandt34555512021-10-01 16:26:59 +0000701 ParentDeviceId: oo.pBaseDeviceHandler.GetProxyAddressID(),
702 ChildDeviceId: oo.deviceID,
703 Message: omciTxRequest.txFrame,
704 ProxyAddress: oo.pBaseDeviceHandler.GetProxyAddress(),
705 ConnectStatus: common.ConnectStatus_REACHABLE, // If we are sending OMCI messages means we are connected, else we should not be here
706 }
707 sendErr := oo.pBaseDeviceHandler.SendOMCIRequest(ctx, oo.pBaseDeviceHandler.GetProxyAddress().AdapterEndpoint, omciMsg)
708 if sendErr != nil {
Holger Hildebrandtabfef032022-02-25 12:40:20 +0000709 logger.Errorw(ctx, "send omci request error", log.Fields{"device-id": oo.deviceID, "ChildId": oo.deviceID, "error": sendErr})
Holger Hildebrandt34555512021-10-01 16:26:59 +0000710 return sendErr
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000711 }
Holger Hildebrandt66af5ce2022-09-07 13:38:02 +0000712 if omciTxRequest.txFrame[cOmciDeviceIdentifierPos] == byte(omci.BaselineIdent) {
713 oo.incrementBaseTxArFrames()
714 } else {
715 oo.incrementExtTxArFrames()
716 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000717 return nil
718}
719
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000720// GetNextTid - TODO: add comment
721func (oo *OmciCC) GetNextTid(highPriority bool) uint16 {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000722 var next uint16
723 if highPriority {
mpagenko900ee4b2020-10-12 11:56:34 +0000724 oo.mutexHpTid.Lock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000725 next = oo.hpTid
Himani Chawla4d908332020-08-31 12:30:20 +0530726 oo.hpTid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000727 if oo.hpTid < 0x8000 {
728 oo.hpTid = 0x8000
729 }
mpagenko900ee4b2020-10-12 11:56:34 +0000730 oo.mutexHpTid.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000731 } else {
mpagenko900ee4b2020-10-12 11:56:34 +0000732 oo.mutexTid.Lock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000733 next = oo.tid
Himani Chawla4d908332020-08-31 12:30:20 +0530734 oo.tid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000735 if oo.tid >= 0x8000 {
736 oo.tid = 1
737 }
mpagenko900ee4b2020-10-12 11:56:34 +0000738 oo.mutexTid.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000739 }
740 return next
741}
742
kesavand011d5162021-11-25 19:21:06 +0530743//GetOnuSwSecNextTid get the next low prio tid for the onu sw sections
744//onu sw sections uses only low priority tids
745//The mutexTid lock should be taken prior to using this function
746func (oo *OmciCC) GetOnuSwSecNextTid() uint16 {
747 next := oo.tid
748 oo.tid++
749 if oo.tid >= 0x8000 {
750 oo.tid = 1
751 }
752 return next
753}
754
755//GetOnuSwSecLastTid gets the last allocated tid
756//The mutexTid lock should be taken prior to using this function
757func (oo *OmciCC) GetOnuSwSecLastTid() uint16 {
758 next := oo.tid
759 lastAllocatedTid := next - 1
760 return lastAllocatedTid
761}
762
763//LockMutexTID locks mutexTid
764func (oo *OmciCC) LockMutexTID() {
765 oo.mutexTid.Lock()
766}
767
768//UnLockMutexTID unlocks mutexTid
769func (oo *OmciCC) UnLockMutexTID() {
770 oo.mutexTid.Unlock()
771}
772
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000773// ###################################################################################
774// # utility methods provided to work on OMCI messages
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000775
776// Serialize - TODO: add comment
777func Serialize(ctx context.Context, msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000778 omciLayer := &omci.OMCI{
779 TransactionID: tid,
780 MessageType: msgType,
781 }
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000782 return SerializeOmciLayer(ctx, omciLayer, request)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000783}
784
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +0000785// SerializeOmciLayer - TODO: add comment
786func SerializeOmciLayer(ctx context.Context, aOmciLayer *omci.OMCI, aRequest gopacket.SerializableLayer) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000787 var options gopacket.SerializeOptions
788 options.FixLengths = true
789
790 buffer := gopacket.NewSerializeBuffer()
Himani Chawla4d908332020-08-31 12:30:20 +0530791 err := gopacket.SerializeLayers(buffer, options, aOmciLayer, aRequest)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000792 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000793 logger.Errorw(ctx, "Could not create goPacket Omci serial buffer", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000794 return nil, err
795 }
796 return buffer.Bytes(), nil
797}
798
Himani Chawla4d908332020-08-31 12:30:20 +0530799/*
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000800func hexEncode(omciPkt []byte) ([]byte, error) {
801 dst := make([]byte, hex.EncodedLen(len(omciPkt)))
802 hex.Encode(dst, omciPkt)
803 return dst, nil
804}
Himani Chawla4d908332020-08-31 12:30:20 +0530805*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000806
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000807//supply a response handler for omci response messages to be transferred to the requested FSM
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000808func (oo *OmciCC) receiveOmciResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000809
dbainbri4d3a0dc2020-12-02 00:33:42 +0000810 logger.Debugw(ctx, "omci-message-response - transfer on omciRespChannel", log.Fields{"omciMsgType": omciMsg.MessageType,
divyadesai4d299552020-08-18 07:13:49 +0000811 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000812
813 if oo.pOnuDeviceEntry == nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000814 logger.Errorw(ctx, "Abort receiving OMCI response, DeviceEntryPointer is nil", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000815 "device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200816 return fmt.Errorf("deviceEntryPointer is nil %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000817 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000818 oo.mutexMonReq.RLock()
819 if _, exist := oo.monitoredRequests[omciMsg.TransactionID]; exist {
mpagenko8cd1bf72021-06-22 10:11:19 +0000820 //implement non-blocking channel send to avoid blocking on mutexMonReq later
821 select {
822 case oo.monitoredRequests[omciMsg.TransactionID].chSuccess <- true:
823 default:
824 logger.Debugw(ctx, "response not send on omciRespChannel (no receiver)", log.Fields{
825 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
826 }
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000827 } else {
828 logger.Infow(ctx, "reqMon: map entry does not exist!",
829 log.Fields{"tid": omciMsg.TransactionID, "device-id": oo.deviceID})
830 }
831 oo.mutexMonReq.RUnlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000832
833 // no further test on SeqNo is done here, assignment from rxScheduler is trusted
834 // MibSync responses are simply transferred via deviceEntry to MibSync, no specific analysis here
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000835 omciRespMsg := Message{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000836 Type: OMCI,
837 Data: OmciMessage{
838 OmciMsg: omciMsg,
839 OmciPacket: packet,
840 },
841 }
dbainbri4d3a0dc2020-12-02 00:33:42 +0000842 //logger.Debugw(ctx,"Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000843 respChan <- omciRespMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000844
845 return nil
846}
847
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000848// SendMibReset sends MibResetRequest
849func (oo *OmciCC) SendMibReset(ctx context.Context, timeout int, highPrio bool) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000850
dbainbri4d3a0dc2020-12-02 00:33:42 +0000851 logger.Debugw(ctx, "send MibReset-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000852 request := &omci.MibResetRequest{
853 MeBasePacket: omci.MeBasePacket{
854 EntityClass: me.OnuDataClassID,
855 },
856 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000857 tid := oo.GetNextTid(highPrio)
858 pkt, err := Serialize(ctx, omci.MibResetRequestType, request, tid)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000859 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000860 logger.Errorw(ctx, "Cannot serialize MibResetRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000861 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000862 return err
863 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000864 omciRxCallbackPair := CallbackPair{
865 CbKey: tid,
866 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibUploadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000867 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000868 return oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000869}
870
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000871// SendReboot sends RebootRequest
872func (oo *OmciCC) SendReboot(ctx context.Context, timeout int, highPrio bool, responseChannel chan Message) error {
873 logger.Debugw(ctx, "send reboot-msg to:", log.Fields{"device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300874 request := &omci.RebootRequest{
875 MeBasePacket: omci.MeBasePacket{
876 EntityClass: me.OnuGClassID,
877 },
878 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000879 tid := oo.GetNextTid(highPrio)
880 pkt, err := Serialize(ctx, omci.RebootRequestType, request, tid)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300881 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000882 logger.Errorw(ctx, "Cannot serialize RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000883 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300884 return err
885 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000886 omciRxCallbackPair := CallbackPair{
887 CbKey: tid,
888 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetOmciRebootMsgRevChan(), oo.receiveOmciResponse, true},
ozgecanetsiae11479f2020-07-06 09:44:47 +0300889 }
890
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000891 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300892 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000893 logger.Errorw(ctx, "Cannot send RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000894 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300895 return err
896 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000897 err = oo.pOnuDeviceEntry.WaitForRebootResponse(ctx, responseChannel)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300898 if err != nil {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000899 logger.Errorw(ctx, "aborting ONU reboot!", log.Fields{
Andrea Campanella6515c582020-10-05 11:25:00 +0200900 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300901 return err
902 }
903 return nil
904}
905
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000906// SendMibUpload sends MibUploadRequest
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000907func (oo *OmciCC) SendMibUpload(ctx context.Context, timeout int, highPrio bool, isExtOmciSupported bool) error {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000908 logger.Debugw(ctx, "send MibUpload-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000909
910 tid := oo.GetNextTid(highPrio)
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000911
912 omciLayer := &omci.OMCI{
913 TransactionID: tid,
914 MessageType: omci.MibUploadRequestType,
915 }
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000916 if isExtOmciSupported {
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000917 omciLayer.DeviceIdentifier = omci.ExtendedIdent
918 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000919 request := &omci.MibUploadRequest{
920 MeBasePacket: omci.MeBasePacket{
921 EntityClass: me.OnuDataClassID,
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000922 Extended: isExtOmciSupported,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000923 },
924 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000925 var options gopacket.SerializeOptions
926 options.FixLengths = true
927
928 buffer := gopacket.NewSerializeBuffer()
929 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000930 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000931 logger.Errorw(ctx, "Cannot serialize MibUploadRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000932 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000933 return err
934 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000935 oo.UploadSequNo = 0
936 oo.UploadNoOfCmds = 0
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000937
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000938 omciRxCallbackPair := CallbackPair{
939 CbKey: tid,
940 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibUploadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000941 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000942 return oo.Send(ctx, buffer.Bytes(), timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000943}
944
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000945// SendMibUploadNext sends MibUploadNextRequest
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000946func (oo *OmciCC) SendMibUploadNext(ctx context.Context, timeout int, highPrio bool, isExtOmciSupported bool) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000947 logger.Debugw(ctx, "send MibUploadNext-msg to:", log.Fields{"device-id": oo.deviceID, "UploadSequNo": oo.UploadSequNo})
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000948
949 tid := oo.GetNextTid(highPrio)
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000950
951 omciLayer := &omci.OMCI{
952 TransactionID: tid,
953 MessageType: omci.MibUploadNextRequestType,
954 }
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000955 if isExtOmciSupported {
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000956 omciLayer.DeviceIdentifier = omci.ExtendedIdent
957 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000958 request := &omci.MibUploadNextRequest{
959 MeBasePacket: omci.MeBasePacket{
960 EntityClass: me.OnuDataClassID,
Holger Hildebrandt5458d892022-05-31 09:52:06 +0000961 Extended: isExtOmciSupported,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000962 },
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000963 CommandSequenceNumber: oo.UploadSequNo,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000964 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000965 var options gopacket.SerializeOptions
966 options.FixLengths = true
967
968 buffer := gopacket.NewSerializeBuffer()
969 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000970 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000971 logger.Errorw(ctx, "Cannot serialize MibUploadNextRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000972 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000973 return err
974 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000975 oo.UploadSequNo++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000976
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000977 omciRxCallbackPair := CallbackPair{
978 CbKey: tid,
mpagenko80622a52021-02-09 16:53:23 +0000979 //frame printing for MibUpload frames disabled now per default to avoid log file abort situations (size/speed?)
980 // if wanted, rx frame printing should be specifically done within the MibUpload FSM or controlled via extra parameter
981 // compare also software upgrade download section handling
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000982 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibUploadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000983 }
Holger Hildebrandt0edf5b02022-05-04 14:19:43 +0000984 return oo.Send(ctx, buffer.Bytes(), timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000985}
986
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000987// SendGetAllAlarm gets all alarm ME instances
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +0000988func (oo *OmciCC) SendGetAllAlarm(ctx context.Context, alarmRetreivalMode uint8, timeout int, highPrio bool, isExtendedOmci bool) error {
Himani Chawlad3dac422021-03-13 02:31:31 +0530989 logger.Debugw(ctx, "send GetAllAlarms-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +0000990
991 tid := oo.GetNextTid(highPrio)
992 omciLayer := &omci.OMCI{
993 TransactionID: tid,
994 MessageType: omci.GetAllAlarmsRequestType,
995 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
996 }
997 if isExtendedOmci {
998 omciLayer.DeviceIdentifier = omci.ExtendedIdent
999 }
Himani Chawlad3dac422021-03-13 02:31:31 +05301000 request := &omci.GetAllAlarmsRequest{
1001 MeBasePacket: omci.MeBasePacket{
1002 EntityClass: me.OnuDataClassID,
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001003 Extended: isExtendedOmci,
Himani Chawlad3dac422021-03-13 02:31:31 +05301004 },
1005 AlarmRetrievalMode: byte(alarmRetreivalMode),
1006 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001007 var options gopacket.SerializeOptions
1008 options.FixLengths = true
1009 buffer := gopacket.NewSerializeBuffer()
1010 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
Himani Chawlad3dac422021-03-13 02:31:31 +05301011 if err != nil {
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001012 logger.Errorw(ctx, "Cannot serialize GetAllAlarmsRequest", log.Fields{"Err": err,
1013 "device-id": oo.deviceID})
Himani Chawlad3dac422021-03-13 02:31:31 +05301014 return err
1015 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001016 outgoingPacket := buffer.Bytes()
1017
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001018 oo.pOnuAlarmManager.ResetAlarmUploadCounters()
Himani Chawlad3dac422021-03-13 02:31:31 +05301019
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001020 omciRxCallbackPair := CallbackPair{
1021 CbKey: tid,
1022 CbEntry: CallbackPairEntry{oo.pOnuAlarmManager.GetAlarmMgrEventChannel(), oo.receiveOmciResponse, true},
Himani Chawlad3dac422021-03-13 02:31:31 +05301023 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001024 err = oo.Send(ctx, outgoingPacket, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
1025 if err != nil {
1026 logger.Errorw(ctx, "Cannot send GetAllAlarmsRequest", log.Fields{"Err": err,
1027 "device-id": oo.deviceID})
1028 return err
1029 }
1030 logger.Debug(ctx, "send GetAllAlarmsRequest done")
1031 return nil
Himani Chawlad3dac422021-03-13 02:31:31 +05301032}
1033
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001034// SendGetAllAlarmNext gets next alarm ME instance
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001035func (oo *OmciCC) SendGetAllAlarmNext(ctx context.Context, timeout int, highPrio bool, isExtendedOmci bool) error {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001036 alarmUploadSeqNo := oo.pOnuAlarmManager.GetAlarmUploadSeqNo()
1037 logger.Debugw(ctx, "send SendGetAllAlarmNext-msg to:", log.Fields{"device-id": oo.deviceID,
Himani Chawlad3dac422021-03-13 02:31:31 +05301038 "alarmUploadSeqNo": alarmUploadSeqNo})
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001039
1040 tid := oo.GetNextTid(highPrio)
1041 omciLayer := &omci.OMCI{
1042 TransactionID: tid,
1043 MessageType: omci.GetAllAlarmsNextRequestType,
1044 // DeviceIdentifier: omci.BaselineIdent, // Optional, defaults to Baseline
1045 }
1046 if isExtendedOmci {
1047 omciLayer.DeviceIdentifier = omci.ExtendedIdent
1048 }
Himani Chawlad3dac422021-03-13 02:31:31 +05301049 request := &omci.GetAllAlarmsNextRequest{
1050 MeBasePacket: omci.MeBasePacket{
1051 EntityClass: me.OnuDataClassID,
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001052 Extended: isExtendedOmci,
Himani Chawlad3dac422021-03-13 02:31:31 +05301053 },
1054 CommandSequenceNumber: alarmUploadSeqNo,
1055 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001056 var options gopacket.SerializeOptions
1057 options.FixLengths = true
1058 buffer := gopacket.NewSerializeBuffer()
1059 err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
Himani Chawlad3dac422021-03-13 02:31:31 +05301060 if err != nil {
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001061 logger.Errorw(ctx, "Cannot serialize GetAllAlarmsNextRequest", log.Fields{"Err": err,
1062 "device-id": oo.deviceID})
Himani Chawlad3dac422021-03-13 02:31:31 +05301063 return err
1064 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001065 outgoingPacket := buffer.Bytes()
1066
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001067 oo.pOnuAlarmManager.IncrementAlarmUploadSeqNo()
Himani Chawlad3dac422021-03-13 02:31:31 +05301068
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001069 omciRxCallbackPair := CallbackPair{
1070 CbKey: tid,
1071 CbEntry: CallbackPairEntry{oo.pOnuAlarmManager.GetAlarmMgrEventChannel(), oo.receiveOmciResponse, true},
Himani Chawlad3dac422021-03-13 02:31:31 +05301072 }
Holger Hildebrandt3b29a8a2022-07-11 05:55:13 +00001073 err = oo.Send(ctx, outgoingPacket, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
1074 if err != nil {
1075 logger.Errorw(ctx, "Cannot send GetAllAlarmsNextRequest", log.Fields{"Err": err,
1076 "device-id": oo.deviceID})
1077 return err
1078 }
1079 logger.Debug(ctx, "send GetAllAlarmsNextRequest done")
1080 return nil
Himani Chawlad3dac422021-03-13 02:31:31 +05301081}
1082
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001083// SendCreateGalEthernetProfile creates GalEthernetProfile ME instance
1084func (oo *OmciCC) SendCreateGalEthernetProfile(ctx context.Context, timeout int, highPrio bool) (*me.ManagedEntity, error) {
1085 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001086 logger.Debugw(ctx, "send GalEnetProfile-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001087 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001088
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001089 meParams := me.ParamData{
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001090 EntityID: GalEthernetEID,
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001091 Attributes: me.AttributeValueMap{me.GalEthernetProfile_MaximumGemPayloadSize: maxGemPayloadSize},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001092 }
1093 meInstance, omciErr := me.NewGalEthernetProfile(meParams)
1094 if omciErr.GetError() == nil {
1095 //all setByCreate parameters already set, no default option required ...
mpagenko836a1fd2021-11-01 16:12:42 +00001096 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType, oframe.TransactionID(tid))
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001097 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001098 logger.Errorw(ctx, "Cannot encode GalEnetProfileInstance for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001099 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001100 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001101 }
1102
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001103 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001104 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001105 logger.Errorw(ctx, "Cannot serialize GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001106 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001107 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001108 }
1109
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001110 omciRxCallbackPair := CallbackPair{
1111 CbKey: tid,
1112 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibDownloadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001113 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001114 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001115 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001116 logger.Errorw(ctx, "Cannot send GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001117 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001118 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001119 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001120 logger.Debug(ctx, "send GalEnetProfile-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001121 return meInstance, nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001122 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001123 logger.Errorw(ctx, "Cannot generate GalEnetProfileInstance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001124 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001125 return nil, omciErr.GetError()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001126}
1127
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001128// SendSetOnu2g sets Onu2G ME instance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001129// might be needed to extend for parameter arguments, here just for setting the ConnectivityMode!!
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001130func (oo *OmciCC) SendSetOnu2g(ctx context.Context, timeout int, highPrio bool) (*me.ManagedEntity, error) {
1131 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001132 logger.Debugw(ctx, "send ONU2-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001133 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001134
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001135 // ONU-G ME-ID is defined to be 0, but we could verify, if the ONU really supports the desired
1136 // connectivity mode 5 (in ConnCap)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001137 // By now we just use fix values to fire - this is anyway what the python adapter does
1138 // read ONU-2G from DB ???? //TODO!!!
1139 meParams := me.ParamData{
1140 EntityID: 0,
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001141 Attributes: me.AttributeValueMap{me.Onu2G_CurrentConnectivityMode: connectivityModeValue},
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001142 }
1143 meInstance, omciErr := me.NewOnu2G(meParams)
1144 if omciErr.GetError() == nil {
mpagenko836a1fd2021-11-01 16:12:42 +00001145 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType, oframe.TransactionID(tid))
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001146 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001147 logger.Errorw(ctx, "Cannot encode ONU2-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001148 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001149 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001150 }
1151
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001152 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001153 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001154 logger.Errorw(ctx, "Cannot serialize ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001155 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001156 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001157 }
1158
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001159 omciRxCallbackPair := CallbackPair{
1160 CbKey: tid,
1161 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibDownloadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001162 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001163 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001164 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001165 logger.Errorw(ctx, "Cannot send ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001166 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001167 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001168 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001169 logger.Debug(ctx, "send ONU2-G-Set-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001170 return meInstance, nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001171 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001172 logger.Errorw(ctx, "Cannot generate ONU2-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001173 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001174 return nil, omciErr.GetError()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001175}
1176
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001177// SendCreateMBServiceProfile creates MacBridgeServiceProfile ME instance
1178func (oo *OmciCC) SendCreateMBServiceProfile(ctx context.Context,
1179 aPUniPort *OnuUniPort, timeout int, highPrio bool) (*me.ManagedEntity, error) {
1180 tid := oo.GetNextTid(highPrio)
1181 instID := MacBridgeServiceProfileEID + uint16(aPUniPort.MacBpNo)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001182 logger.Debugw(ctx, "send MBSP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001183 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001184
1185 meParams := me.ParamData{
1186 EntityID: instID,
1187 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001188 me.MacBridgeServiceProfile_Priority: 0x8000,
1189 me.MacBridgeServiceProfile_MaxAge: 20 * 256, //20s
1190 me.MacBridgeServiceProfile_HelloTime: 2 * 256, //2s
1191 me.MacBridgeServiceProfile_ForwardDelay: 15 * 256, //15s
1192 me.MacBridgeServiceProfile_DynamicFilteringAgeingTime: 0,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001193 },
1194 }
1195
1196 meInstance, omciErr := me.NewMacBridgeServiceProfile(meParams)
1197 if omciErr.GetError() == nil {
1198 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001199 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1200 oframe.TransactionID(tid), oframe.AddDefaults(true))
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001201 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001202 logger.Errorw(ctx, "Cannot encode MBSP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001203 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001204 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001205 }
1206
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001207 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001208 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001209 logger.Errorw(ctx, "Cannot serialize MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001210 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001211 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001212 }
1213
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001214 omciRxCallbackPair := CallbackPair{
1215 CbKey: tid,
1216 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibDownloadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001217 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001218 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001219 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001220 logger.Errorw(ctx, "Cannot send MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001221 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001222 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001223 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001224 logger.Debug(ctx, "send MBSP-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001225 return meInstance, nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001226 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001227 logger.Errorw(ctx, "Cannot generate MBSP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001228 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001229 return nil, omciErr.GetError()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001230}
1231
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001232// SendCreateMBPConfigDataUniSide creates MacBridgePortConfigurationData ME instance
1233func (oo *OmciCC) SendCreateMBPConfigDataUniSide(ctx context.Context,
1234 aPUniPort *OnuUniPort, timeout int, highPrio bool) (*me.ManagedEntity, error) {
1235 tid := oo.GetNextTid(highPrio)
1236 instID, idErr := GenerateUNISideMBPCDEID(uint16(aPUniPort.MacBpNo))
Mahir Gunyel6781f962021-05-16 23:30:08 -07001237 if idErr != nil {
1238 logger.Errorw(ctx, "Cannot generate MBPCD entity id", log.Fields{
1239 "Err": idErr, "device-id": oo.deviceID})
1240 return nil, idErr
1241 }
1242 logger.Debugw(ctx, "send MBPCD-Create-msg for uni side:", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001243 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16), "macBpNo": aPUniPort.MacBpNo})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001244
1245 meParams := me.ParamData{
1246 EntityID: instID,
1247 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001248 me.MacBridgePortConfigurationData_BridgeIdPointer: MacBridgeServiceProfileEID + uint16(aPUniPort.MacBpNo),
1249 me.MacBridgePortConfigurationData_PortNum: aPUniPort.MacBpNo,
1250 me.MacBridgePortConfigurationData_TpType: uint8(aPUniPort.PortType),
1251 me.MacBridgePortConfigurationData_TpPointer: aPUniPort.EntityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001252 },
1253 }
1254 meInstance, omciErr := me.NewMacBridgePortConfigurationData(meParams)
1255 if omciErr.GetError() == nil {
1256 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001257 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1258 oframe.TransactionID(tid), oframe.AddDefaults(true))
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001259 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001260 logger.Errorw(ctx, "Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001261 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001262 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001263 }
1264
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001265 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001266 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001267 logger.Errorw(ctx, "Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001268 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001269 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001270 }
1271
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001272 omciRxCallbackPair := CallbackPair{
1273 CbKey: tid,
1274 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibDownloadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001275 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001276 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001277 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001278 logger.Errorw(ctx, "Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001279 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001280 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001281 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001282 logger.Debug(ctx, "send MBPCD-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001283 return meInstance, nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001284 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001285 logger.Errorw(ctx, "Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001286 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001287 return nil, omciErr.GetError()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001288}
1289
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001290// SendCreateEVTOConfigData creates ExtendedVlanTaggingOperationConfigurationData ME instance
1291func (oo *OmciCC) SendCreateEVTOConfigData(ctx context.Context,
1292 aPUniPort *OnuUniPort, timeout int, highPrio bool) (*me.ManagedEntity, error) {
1293 tid := oo.GetNextTid(highPrio)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001294 //same entityId is used as for MBSP (see there), but just arbitrary ...
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001295 instID := MacBridgeServiceProfileEID + uint16(aPUniPort.MacBpNo)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001296 logger.Debugw(ctx, "send EVTOCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001297 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001298
1299 // compare python adapter code WA VOL-1311: this is not done here!
1300 // (setting TPID values for the create would probably anyway be ignored by the omci lib)
1301 // but perhaps we have to be aware of possible problems at get(Next) Request handling for EVTOOCD tables later ...
1302 assType := uint8(2) // default AssociationType is PPTPEthUni
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001303 if aPUniPort.PortType == UniVEIP {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001304 assType = uint8(10) // for VEIP
1305 }
1306 meParams := me.ParamData{
1307 EntityID: instID,
1308 Attributes: me.AttributeValueMap{
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001309 me.ExtendedVlanTaggingOperationConfigurationData_AssociationType: assType,
1310 me.ExtendedVlanTaggingOperationConfigurationData_AssociatedMePointer: aPUniPort.EntityID,
mpagenko836a1fd2021-11-01 16:12:42 +00001311 //EnhancedMode not yet supported, used with default options
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001312 },
1313 }
1314 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(meParams)
1315 if omciErr.GetError() == nil {
1316 //all setByCreate parameters already set, no default option required ...
mpagenko836a1fd2021-11-01 16:12:42 +00001317 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1318 oframe.TransactionID(tid), oframe.AddDefaults(true))
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001319 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001320 logger.Errorw(ctx, "Cannot encode EVTOCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001321 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001322 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001323 }
1324
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001325 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001326 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001327 logger.Errorw(ctx, "Cannot serialize EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001328 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001329 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001330 }
1331
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001332 omciRxCallbackPair := CallbackPair{
1333 CbKey: tid,
1334 CbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.GetMibDownloadFsmCommChan(), oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001335 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001336 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001337 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001338 logger.Errorw(ctx, "Cannot send EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001339 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001340 return nil, err
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001341 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001342 logger.Debug(ctx, "send EVTOCD-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001343 return meInstance, nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001344 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001345 logger.Errorw(ctx, "Cannot generate EVTOCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001346 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001347 return nil, omciErr.GetError()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001348}
1349
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001350// SendSetOnuGLS sets OnuG ME instance
1351func (oo *OmciCC) SendSetOnuGLS(ctx context.Context, timeout int,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001352 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001353 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001354 logger.Debugw(ctx, "send ONU-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001355 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001356
1357 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1358 meParams := me.ParamData{
1359 EntityID: 0,
1360 Attributes: requestedAttributes,
1361 }
1362 meInstance, omciErr := me.NewOnuG(meParams)
1363 if omciErr.GetError() == nil {
mpagenko836a1fd2021-11-01 16:12:42 +00001364 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType, oframe.TransactionID(tid))
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001365 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001366 logger.Errorw(ctx, "Cannot encode ONU-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001367 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001368 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001369 }
1370
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001371 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001372 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001373 logger.Errorw(ctx, "Cannot serialize ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001374 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001375 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001376 }
1377
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001378 omciRxCallbackPair := CallbackPair{
1379 CbKey: tid,
1380 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001381 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001382 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001383 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001384 logger.Errorw(ctx, "Cannot send ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001385 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001386 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001387 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001388 logger.Debug(ctx, "send ONU-G-Set-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001389 return meInstance, nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001390 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001391 logger.Errorw(ctx, "Cannot generate ONU-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001392 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001393 return nil, omciErr.GetError()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001394}
1395
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001396// SendSetPptpEthUniLS sets PhysicalPathTerminationPointEthernetUni ME instance
1397func (oo *OmciCC) SendSetPptpEthUniLS(ctx context.Context, aInstNo uint16, timeout int,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001398 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001399 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001400 logger.Debugw(ctx, "send PPTPEthUni-Set-msg:", log.Fields{"device-id": oo.deviceID,
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001401 "SequNo": strconv.FormatInt(int64(tid), 16)})
1402
1403 // PPTPEthUni ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
1404 meParams := me.ParamData{
1405 EntityID: aInstNo,
1406 Attributes: requestedAttributes,
1407 }
1408 meInstance, omciErr := me.NewPhysicalPathTerminationPointEthernetUni(meParams)
1409 if omciErr.GetError() == nil {
mpagenko836a1fd2021-11-01 16:12:42 +00001410 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType, oframe.TransactionID(tid))
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001411 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001412 logger.Errorw(ctx, "Cannot encode PPTPEthUni instance for set", log.Fields{
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001413 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001414 return nil, err
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001415 }
1416
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001417 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001418 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001419 logger.Errorw(ctx, "Cannot serialize PPTPEthUni-Set", log.Fields{
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001420 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001421 return nil, err
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001422 }
1423
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001424 omciRxCallbackPair := CallbackPair{
1425 CbKey: tid,
1426 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001427 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001428 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001429 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001430 logger.Errorw(ctx, "Cannot send PPTPEthUni-Set", log.Fields{
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001431 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001432 return nil, err
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001433 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001434 logger.Debug(ctx, "send PPTPEthUni-Set-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001435 return meInstance, nil
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001436 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001437 logger.Errorw(ctx, "Cannot generate PPTPEthUni", log.Fields{
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001438 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001439 return nil, omciErr.GetError()
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001440}
1441
1442/* UniG obsolete by now, left here in case it should be needed once again
1443 UniG AdminState anyway should be ignored by ONU acc. to G988
Himani Chawla6d2ae152020-09-02 13:11:20 +05301444func (oo *omciCC) sendSetUniGLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001445 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001446 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001447 logger.Debugw(ctx,"send UNI-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001448 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001449
1450 // UNI-G ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
1451 meParams := me.ParamData{
1452 EntityID: aInstNo,
1453 Attributes: requestedAttributes,
1454 }
1455 meInstance, omciErr := me.NewUniG(meParams)
1456 if omciErr.GetError() == nil {
mpagenko836a1fd2021-11-01 16:12:42 +00001457 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType, oframe.TransactionID(tid))
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001458 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001459 logger.Errorw(ctx,"Cannot encode UNI-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001460 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001461 return nil
1462 }
1463
1464 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1465 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001466 logger.Errorw(ctx,"Cannot serialize UNI-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001467 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001468 return nil
1469 }
1470
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001471 omciRxCallbackPair := CallbackPair{
1472 CbKey: tid,
1473 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001474 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001475 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001476 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001477 logger.Errorw(ctx,"Cannot send UNIG-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001478 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001479 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001480 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001481 logger.Debug(ctx,"send UNI-G-Set-msg done")
mpagenko3dbcdd22020-07-22 07:38:45 +00001482 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001483 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001484 logger.Errorw(ctx,"Cannot generate UNI-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001485 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001486 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001487}
Holger Hildebrandt2fb70892020-10-28 11:53:18 +00001488*/
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001489
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001490// SendSetVeipLS sets VirtualEthernetInterfacePoint ME instance
1491func (oo *OmciCC) SendSetVeipLS(ctx context.Context, aInstNo uint16, timeout int,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001492 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001493 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001494 logger.Debugw(ctx, "send VEIP-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001495 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001496
1497 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1498 meParams := me.ParamData{
1499 EntityID: aInstNo,
1500 Attributes: requestedAttributes,
1501 }
1502 meInstance, omciErr := me.NewVirtualEthernetInterfacePoint(meParams)
1503 if omciErr.GetError() == nil {
mpagenko836a1fd2021-11-01 16:12:42 +00001504 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType, oframe.TransactionID(tid))
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001505 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001506 logger.Errorw(ctx, "Cannot encode VEIP instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001507 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001508 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001509 }
1510
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001511 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001512 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001513 logger.Errorw(ctx, "Cannot serialize VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001514 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001515 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001516 }
1517
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001518 omciRxCallbackPair := CallbackPair{
1519 CbKey: tid,
1520 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001521 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001522 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001523 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001524 logger.Errorw(ctx, "Cannot send VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001525 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001526 return nil, err
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001527 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001528 logger.Debug(ctx, "send VEIP-Set-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001529 return meInstance, nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001530 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001531 logger.Errorw(ctx, "Cannot generate VEIP", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001532 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001533 return nil, omciErr.GetError()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001534}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001535
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001536// SendGetMe gets ME instance
1537func (oo *OmciCC) SendGetMe(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributes me.AttributeValueMap,
Holger Hildebrandtd930cb22022-06-17 09:24:50 +00001538 timeout int, highPrio bool, rxChan chan Message, isExtendedOmci bool) (*me.ManagedEntity, error) {
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001539
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001540 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001541 logger.Debugw(ctx, "send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001542 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001543
1544 meParams := me.ParamData{
1545 EntityID: entityID,
1546 Attributes: requestedAttributes,
1547 }
Holger Hildebrandtd930cb22022-06-17 09:24:50 +00001548 var messageSet omci.DeviceIdent = omci.BaselineIdent
1549 if isExtendedOmci {
1550 messageSet = omci.ExtendedIdent
1551 }
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001552 meInstance, omciErr := me.LoadManagedEntityDefinition(classID, meParams)
1553 if omciErr.GetError() == nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301554 meClassIDName := meInstance.GetName()
Holger Hildebrandtd930cb22022-06-17 09:24:50 +00001555 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.GetRequestType, oframe.TransactionID(tid), oframe.FrameFormat(messageSet))
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001556 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001557 logger.Errorf(ctx, "Cannot encode instance for get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001558 return nil, err
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001559 }
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001560 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001561 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001562 logger.Errorw(ctx, "Cannot serialize get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001563 return nil, err
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001564 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001565 omciRxCallbackPair := CallbackPair{
1566 CbKey: tid,
1567 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001568 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001569 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001570 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001571 logger.Errorw(ctx, "Cannot send get-request-msg", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001572 return nil, err
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001573 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001574 logger.Debugw(ctx, "send get-request-msg done", log.Fields{"meClassIDName": meClassIDName, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001575 return meInstance, nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001576 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001577 logger.Errorw(ctx, "Cannot generate meDefinition", log.Fields{"classID": classID, "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001578 return nil, omciErr.GetError()
mpagenko3dbcdd22020-07-22 07:38:45 +00001579}
1580
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001581// SendGetMeWithAttributeMask gets ME instance with attribute mask
1582func (oo *OmciCC) SendGetMeWithAttributeMask(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributesMask uint16,
Himani Chawla43f95ff2021-06-03 00:24:12 +05301583 timeout int, highPrio bool, rxChan chan Message) error {
1584
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001585 tid := oo.GetNextTid(highPrio)
Himani Chawla43f95ff2021-06-03 00:24:12 +05301586 logger.Debugw(ctx, "send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
1587 "SequNo": strconv.FormatInt(int64(tid), 16)})
1588
1589 request := &omci.GetRequest{
1590 MeBasePacket: omci.MeBasePacket{
1591 EntityInstance: entityID,
1592 EntityClass: classID,
1593 },
1594 AttributeMask: requestedAttributesMask,
1595 }
1596
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001597 pkt, err := Serialize(ctx, omci.GetRequestType, request, tid)
Himani Chawla43f95ff2021-06-03 00:24:12 +05301598 if err != nil {
1599 logger.Errorw(ctx, "Cannot serialize get-request", log.Fields{"meClassIDName": classID, "Err": err, "device-id": oo.deviceID})
1600 return err
1601 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001602 omciRxCallbackPair := CallbackPair{
1603 CbKey: tid,
1604 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
Himani Chawla43f95ff2021-06-03 00:24:12 +05301605 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001606 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
Himani Chawla43f95ff2021-06-03 00:24:12 +05301607 if err != nil {
1608 logger.Errorw(ctx, "Cannot send get-request-msg", log.Fields{"meClassIDName": classID, "Err": err, "device-id": oo.deviceID})
1609 return err
1610 }
1611 logger.Debugw(ctx, "send get-request-msg done", log.Fields{"meClassIDName": classID, "device-id": oo.deviceID})
1612 return nil
1613}
1614
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001615// SendCreateDot1PMapper creates Ieee8021PMapperServiceProfile ME instance
1616func (oo *OmciCC) SendCreateDot1PMapper(ctx context.Context, timeout int, highPrio bool,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001617 aInstID uint16, rxChan chan Message) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001618 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001619 logger.Debugw(ctx, "send .1pMapper-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001620 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
1621
1622 meParams := me.ParamData{
mpagenko8b5fdd22020-12-17 17:58:32 +00001623 EntityID: aInstID,
1624 Attributes: me.AttributeValueMap{
1625 //workaround for unsuitable omci-lib default values, cmp VOL-3729
Holger Hildebrandt3ac49bd2022-02-07 17:46:43 +00001626 me.Ieee8021PMapperServiceProfile_TpPointer: 0xFFFF,
1627 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority0: 0xFFFF,
1628 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority1: 0xFFFF,
1629 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority2: 0xFFFF,
1630 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority3: 0xFFFF,
1631 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority4: 0xFFFF,
1632 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority5: 0xFFFF,
1633 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority6: 0xFFFF,
1634 me.Ieee8021PMapperServiceProfile_InterworkTpPointerForPBitPriority7: 0xFFFF,
mpagenko8b5fdd22020-12-17 17:58:32 +00001635 },
mpagenko3dbcdd22020-07-22 07:38:45 +00001636 }
1637 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
1638 if omciErr.GetError() == nil {
1639 //we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001640 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1641 oframe.TransactionID(tid), oframe.AddDefaults(true))
mpagenko3dbcdd22020-07-22 07:38:45 +00001642 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001643 logger.Errorw(ctx, "Cannot encode .1pMapper for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001644 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001645 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001646 }
1647
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001648 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
mpagenko3dbcdd22020-07-22 07:38:45 +00001649 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001650 logger.Errorw(ctx, "Cannot serialize .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001651 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001652 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001653 }
1654
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001655 omciRxCallbackPair := CallbackPair{
1656 CbKey: tid,
1657 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
mpagenko3dbcdd22020-07-22 07:38:45 +00001658 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001659 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001660 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001661 logger.Errorw(ctx, "Cannot send .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001662 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001663 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001664 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001665 logger.Debug(ctx, "send .1pMapper-create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001666 return meInstance, nil
mpagenko3dbcdd22020-07-22 07:38:45 +00001667 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001668 logger.Errorw(ctx, "Cannot generate .1pMapper", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001669 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001670 return nil, omciErr.GetError()
mpagenko3dbcdd22020-07-22 07:38:45 +00001671}
1672
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001673// SendCreateMBPConfigDataVar creates MacBridgePortConfigurationData ME instance
1674func (oo *OmciCC) SendCreateMBPConfigDataVar(ctx context.Context, timeout int, highPrio bool,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001675 rxChan chan Message, params ...me.ParamData) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001676 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001677 logger.Debugw(ctx, "send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001678 "SequNo": strconv.FormatInt(int64(tid), 16),
1679 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1680
1681 meInstance, omciErr := me.NewMacBridgePortConfigurationData(params[0])
1682 if omciErr.GetError() == nil {
1683 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001684 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1685 oframe.TransactionID(tid), oframe.AddDefaults(true))
mpagenko3dbcdd22020-07-22 07:38:45 +00001686 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001687 logger.Errorw(ctx, "Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001688 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001689 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001690 }
1691
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001692 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
mpagenko3dbcdd22020-07-22 07:38:45 +00001693 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001694 logger.Errorw(ctx, "Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001695 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001696 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001697 }
1698
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001699 omciRxCallbackPair := CallbackPair{
1700 CbKey: tid,
1701 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
mpagenko3dbcdd22020-07-22 07:38:45 +00001702 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001703 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001704 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001705 logger.Errorw(ctx, "Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001706 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001707 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001708 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001709 logger.Debug(ctx, "send MBPCD-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001710 return meInstance, nil
mpagenko3dbcdd22020-07-22 07:38:45 +00001711 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001712 logger.Errorw(ctx, "Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001713 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001714 return nil, omciErr.GetError()
mpagenko3dbcdd22020-07-22 07:38:45 +00001715}
1716
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001717// SendCreateGemNCTPVar creates GemPortNetworkCtp ME instance
1718func (oo *OmciCC) SendCreateGemNCTPVar(ctx context.Context, timeout int, highPrio bool,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001719 rxChan chan Message, params ...me.ParamData) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001720 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001721 logger.Debugw(ctx, "send GemNCTP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001722 "SequNo": strconv.FormatInt(int64(tid), 16),
1723 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1724
1725 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1726 if omciErr.GetError() == nil {
1727 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001728 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1729 oframe.TransactionID(tid), oframe.AddDefaults(true))
mpagenko3dbcdd22020-07-22 07:38:45 +00001730 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001731 logger.Errorw(ctx, "Cannot encode GemNCTP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001732 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001733 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001734 }
1735
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001736 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
mpagenko3dbcdd22020-07-22 07:38:45 +00001737 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001738 logger.Errorw(ctx, "Cannot serialize GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001739 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001740 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001741 }
1742
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001743 omciRxCallbackPair := CallbackPair{
1744 CbKey: tid,
1745 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
mpagenko3dbcdd22020-07-22 07:38:45 +00001746 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001747 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001748 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001749 logger.Errorw(ctx, "Cannot send GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001750 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001751 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001752 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001753 logger.Debug(ctx, "send GemNCTP-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001754 return meInstance, nil
mpagenko3dbcdd22020-07-22 07:38:45 +00001755 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001756 logger.Errorw(ctx, "Cannot generate GemNCTP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001757 "Err": omciErr.GetError(), "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001758 return nil, omciErr.GetError()
mpagenko3dbcdd22020-07-22 07:38:45 +00001759}
1760
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001761// SendSetGemNCTPVar sets GemPortNetworkCtp ME instance
1762func (oo *OmciCC) SendSetGemNCTPVar(ctx context.Context, timeout int, highPrio bool, rxChan chan Message, params ...me.ParamData) (*me.ManagedEntity, error) {
1763 tid := oo.GetNextTid(highPrio)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001764 logger.Debugw(ctx, "send GemNCTP-Set-msg:", log.Fields{"device-id": oo.deviceID,
1765 "SequNo": strconv.FormatInt(int64(tid), 16),
1766 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1767
1768 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1769 if omciErr.GetError() == nil {
1770 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
mpagenko836a1fd2021-11-01 16:12:42 +00001771 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.SetRequestType,
1772 oframe.TransactionID(tid), oframe.AddDefaults(true))
ozgecanetsia82b91a62021-05-21 18:54:49 +03001773 if err != nil {
1774 logger.Errorw(ctx, "Cannot encode GemNCTP for set", log.Fields{
1775 "Err": err, "device-id": oo.deviceID})
1776 return nil, err
1777 }
1778
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001779 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001780 if err != nil {
1781 logger.Errorw(ctx, "Cannot serialize GemNCTP set", log.Fields{
1782 "Err": err, "device-id": oo.deviceID})
1783 return nil, err
1784 }
1785
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001786 omciRxCallbackPair := CallbackPair{
1787 CbKey: tid,
1788 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
ozgecanetsia82b91a62021-05-21 18:54:49 +03001789 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001790 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
ozgecanetsia82b91a62021-05-21 18:54:49 +03001791 if err != nil {
1792 logger.Errorw(ctx, "Cannot send GemNCTP set", log.Fields{
1793 "Err": err, "device-id": oo.deviceID})
1794 return nil, err
1795 }
1796 logger.Debug(ctx, "send GemNCTP-Set-msg done", log.Fields{"device-id": oo.deviceID})
1797 return meInstance, nil
1798 }
1799 logger.Errorw(ctx, "Cannot generate GemNCTP Instance", log.Fields{
1800 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1801 return nil, omciErr.GetError()
1802}
1803
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001804// SendCreateGemIWTPVar creates GemInterworkingTerminationPoint ME instance
1805func (oo *OmciCC) SendCreateGemIWTPVar(ctx context.Context, timeout int, highPrio bool,
ozgecanetsiab36ed572021-04-01 10:38:48 +03001806 rxChan chan Message, params ...me.ParamData) (*me.ManagedEntity, error) {
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001807 tid := oo.GetNextTid(highPrio)
dbainbri4d3a0dc2020-12-02 00:33:42 +00001808 logger.Debugw(ctx, "send GemIwTp-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001809 "SequNo": strconv.FormatInt(int64(tid), 16),
1810 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1811
1812 meInstance, omciErr := me.NewGemInterworkingTerminationPoint(params[0])
1813 if omciErr.GetError() == nil {
1814 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
mpagenko836a1fd2021-11-01 16:12:42 +00001815 omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.CreateRequestType,
1816 oframe.TransactionID(tid))
mpagenko3dbcdd22020-07-22 07:38:45 +00001817 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001818 logger.Errorw(ctx, "Cannot encode GemIwTp for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001819 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001820 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001821 }
1822
Holger Hildebrandta6ef0e82022-04-06 13:11:32 +00001823 pkt, err := SerializeOmciLayer(ctx, omciLayer, msgLayer)
mpagenko3dbcdd22020-07-22 07:38:45 +00001824 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001825 logger.Errorw(ctx, "Cannot serialize GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001826 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001827 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001828 }
1829
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001830 omciRxCallbackPair := CallbackPair{
1831 CbKey: tid,
1832 CbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse, true},
mpagenko3dbcdd22020-07-22 07:38:45 +00001833 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +00001834 err = oo.Send(ctx, pkt, timeout, CDefaultRetries, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001835 if err != nil {
dbainbri4d3a0dc2020-12-02 00:33:42 +00001836 logger.Errorw(ctx, "Cannot send GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001837 "Err": err, "device-id": oo.deviceID})
ozgecanetsiab36ed572021-04-01 10:38:48 +03001838 return nil, err
mpagenko3dbcdd22020-07-22 07:38:45 +00001839 }
dbainbri4d3a0dc2020-12-02 00:33:42 +00001840 logger.Debug(ctx, "send GemIwTp-Create-msg done")
ozgecanetsiab36ed572021-04-01 10:38:48 +03001841 return meInstance, nil
mpagenko3dbcdd22020-07-22 07:38:45 +00001842 }