blob: ad09d166b558b4bd03f9efa95f791053fbba5e24 [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 Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "container/list"
22 "context"
23 "encoding/binary"
24 "encoding/hex"
25 "errors"
Andrea Campanella6515c582020-10-05 11:25:00 +020026 "fmt"
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000027 "strconv"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028 "sync"
mpagenkodff5dda2020-08-28 11:52:01 +000029
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 //"time"
31
32 "github.com/google/gopacket"
33 // TODO!!! Some references could be resolved auto, but some need specific context ....
34 gp "github.com/google/gopacket"
35
36 "github.com/opencord/omci-lib-go"
37 me "github.com/opencord/omci-lib-go/generated"
38 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
39
40 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
41 "github.com/opencord/voltha-lib-go/v3/pkg/log"
42 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
43 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
44 //"github.com/opencord/voltha-protos/v3/go/voltha"
45)
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
49//ConstDefaultOmciTimeout - Default OMCI Timeout
Holger Hildebrandtfa074992020-03-27 15:42:06 +000050const ConstDefaultOmciTimeout = 10 // ( 3 ?) Seconds
51
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000052const galEthernetEID = uint16(1)
53const maxGemPayloadSize = uint16(48)
54const connectivityModeValue = uint8(5)
Himani Chawla4d908332020-08-31 12:30:20 +053055
56//const defaultTPID = uint16(0x8100)
57//const broadComDefaultVID = uint16(4091)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000058const macBridgeServiceProfileEID = uint16(0x201) // TODO: most all these need better definition or tuning
59const ieeeMapperServiceProfileEID = uint16(0x8001)
60const macBridgePortAniEID = uint16(0x2102)
61
62// ### OMCI related definitions - end
63
Himani Chawla6d2ae152020-09-02 13:11:20 +053064//callbackPairEntry to be used for OMCI send/receive correlation
65type callbackPairEntry struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000066 cbRespChannel chan Message
67 cbFunction func(*omci.OMCI, *gp.Packet, chan Message) error
68}
69
Himani Chawla6d2ae152020-09-02 13:11:20 +053070//callbackPair to be used for ReceiveCallback init
71type callbackPair struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000072 cbKey uint16
Himani Chawla6d2ae152020-09-02 13:11:20 +053073 cbEntry callbackPairEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074}
75
76type omciTransferStructure struct {
77 txFrame []byte
78 timeout int
79 retry int
80 highPrio bool
81}
82
Himani Chawla6d2ae152020-09-02 13:11:20 +053083//omciCC structure holds information needed for OMCI communication (to/from OLT Adapter)
84type omciCC struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085 enabled bool
86 pOnuDeviceEntry *OnuDeviceEntry
87 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053088 pBaseDeviceHandler *deviceHandler
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089 coreProxy adapterif.CoreProxy
90 adapterProxy adapterif.AdapterProxy
91 supportExtMsg bool
92 //txRequest
93 //rxResponse
94 //pendingRequest
95 txFrames, txOnuFrames uint32
96 rxFrames, rxOnuFrames, rxOnuDiscards uint32
97
98 // OMCI params
99 mutexTid sync.Mutex
100 tid uint16
101 mutexHpTid sync.Mutex
102 hpTid uint16
103 uploadSequNo uint16
104 uploadNoOfCmds uint16
105
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000106 mutexTxQueue sync.Mutex
107 txQueue *list.List
108 mutexRxSchedMap sync.Mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530109 rxSchedulerMap map[uint16]callbackPairEntry
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000110 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111}
112
Himani Chawla6d2ae152020-09-02 13:11:20 +0530113//newOmciCC constructor returns a new instance of a OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000114//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530115func newOmciCC(ctx context.Context, onuDeviceEntry *OnuDeviceEntry,
116 deviceID string, deviceHandler *deviceHandler,
117 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy) *omciCC {
Himani Chawla4d908332020-08-31 12:30:20 +0530118 logger.Infow("init-omciCC", log.Fields{"device-id": deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530119 var omciCC omciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 omciCC.enabled = false
Himani Chawla4d908332020-08-31 12:30:20 +0530121 omciCC.pOnuDeviceEntry = onuDeviceEntry
122 omciCC.deviceID = deviceID
123 omciCC.pBaseDeviceHandler = deviceHandler
124 omciCC.coreProxy = coreProxy
125 omciCC.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 omciCC.supportExtMsg = false
127 omciCC.txFrames = 0
128 omciCC.txOnuFrames = 0
129 omciCC.rxFrames = 0
130 omciCC.rxOnuFrames = 0
131 omciCC.rxOnuDiscards = 0
132 omciCC.tid = 0x1
133 omciCC.hpTid = 0x8000
134 omciCC.uploadSequNo = 0
135 omciCC.uploadNoOfCmds = 0
136
137 omciCC.txQueue = list.New()
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138 omciCC.rxSchedulerMap = make(map[uint16]callbackPairEntry)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000139
140 return &omciCC
141}
142
mpagenko900ee4b2020-10-12 11:56:34 +0000143//stop stops/resets the omciCC
144func (oo *omciCC) stop(ctx context.Context) error {
145 logger.Debugw("omciCC-stopping", log.Fields{"for device-id": oo.deviceID})
146 //reseting all internal data, which might also be helpful for discarding any lingering tx/rx requests
147 oo.mutexTxQueue.Lock()
148 oo.txQueue.Init() // clear the tx queue
149 oo.mutexTxQueue.Unlock()
150 oo.mutexRxSchedMap.Lock()
151 for k := range oo.rxSchedulerMap {
152 delete(oo.rxSchedulerMap, k) //clear the scheduler map
153 }
154 oo.mutexRxSchedMap.Unlock()
155 oo.mutexHpTid.Lock()
156 oo.hpTid = 0x8000 //reset the high prio transactionId
157 oo.mutexHpTid.Unlock()
158 oo.mutexTid.Lock()
159 oo.tid = 1 //reset the low prio transactionId
160 oo.mutexTid.Unlock()
161 //reset control values
162 oo.uploadSequNo = 0
163 oo.uploadNoOfCmds = 0
164 //reset the stats counter - which might be topic of discussion ...
165 oo.txFrames = 0
166 oo.txOnuFrames = 0
167 oo.rxFrames = 0
168 oo.rxOnuFrames = 0
169 oo.rxOnuDiscards = 0
170
171 return nil
172}
173
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174// Rx handler for omci messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530175func (oo *omciCC) receiveOnuMessage(ctx context.Context, omciMsg *omci.OMCI) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000176 logger.Debugw("rx-onu-autonomous-message", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000177 "payload": hex.EncodeToString(omciMsg.Payload)})
178 /*
179 msgType = rxFrame.fields["message_type"] //assumed OmciOperationsValue
180 rxOnuFrames++
181
182 switch msgType {
183 case AlarmNotification:
184 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000185 logger.Info("Unhandled: received-onu-alarm-message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000186 // python code was:
187 //if msg_type == EntityOperations.AlarmNotification.value:
188 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Alarm_Notification)
189 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
190 //
191 return errors.New("RxAlarmNotification unimplemented")
192 }
193 case AttributeValueChange:
194 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000195 logger.Info("Unhandled: received-attribute-value-change")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000196 // python code was:
197 //elif msg_type == EntityOperations.AttributeValueChange.value:
198 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.AVC_Notification)
199 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
200 //
201 return errors.New("RxAttributeValueChange unimplemented")
202 }
203 case TestResult:
204 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000205 logger.Info("Unhandled: received-test-result")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000206 // python code was:
207 //elif msg_type == EntityOperations.TestResult.value:
208 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Test_Result)
209 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
210 //
211 return errors.New("RxTestResult unimplemented")
212 }
213 default:
214 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000215 logger.Errorw("rx-onu-unsupported-autonomous-message", log.Fields{"msgType": msgType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000216 rxOnuDiscards++
217 return errors.New("RxOnuMsgType unimplemented")
218 }
219 }
220 */
Himani Chawla4d908332020-08-31 12:30:20 +0530221 return errors.New("receiveOnuMessage unimplemented")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000222}
223
224// Rx handler for onu messages
225// e.g. would call ReceiveOnuMessage() in case of TID=0 or Action=test ...
Himani Chawla6d2ae152020-09-02 13:11:20 +0530226func (oo *omciCC) receiveMessage(ctx context.Context, rxMsg []byte) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000227 //logger.Debugw("cc-receive-omci-message", log.Fields{"RxOmciMessage-x2s": hex.EncodeToString(rxMsg)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000228 if len(rxMsg) >= 44 { // then it should normally include the BaseFormat trailer Len
229 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
230 // (am extendedFormat message could be destroyed this way!)
231 trailerLenData := rxMsg[42:44]
232 trailerLen := binary.BigEndian.Uint16(trailerLenData)
mpagenko1cc3cb42020-07-27 15:24:38 +0000233 //logger.Debugw("omci-received-trailer-len", log.Fields{"Length": trailerLen})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 if trailerLen != 40 { // invalid base Format entry -> autocorrect
235 binary.BigEndian.PutUint16(rxMsg[42:44], 40)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000236 logger.Debug("cc-corrected-omci-message: trailer len inserted")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000237 }
238 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530239 logger.Errorw("received omci-message too small for OmciBaseFormat - abort", log.Fields{"Length": len(rxMsg)})
Andrea Campanella6515c582020-10-05 11:25:00 +0200240 return fmt.Errorf("rxOmciMessage too small for BaseFormat %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000241 }
242
243 packet := gopacket.NewPacket(rxMsg, omci.LayerTypeOMCI, gopacket.NoCopy)
244 if packet == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200245 logger.Errorw("omci-message could not be decoded", log.Fields{"deviceID": oo.deviceID})
246 return fmt.Errorf("could not decode rxMsg as OMCI %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000247 }
248 omciLayer := packet.Layer(omci.LayerTypeOMCI)
249 if omciLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200250 logger.Errorw("omci-message could not decode omci layer", log.Fields{"deviceID": oo.deviceID})
251 return fmt.Errorf("could not decode omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000252 }
253 omciMsg, ok := omciLayer.(*omci.OMCI)
254 if !ok {
Andrea Campanella6515c582020-10-05 11:25:00 +0200255 logger.Errorw("omci-message could not assign omci layer", log.Fields{"deviceID": oo.deviceID})
256 return fmt.Errorf("could not assign omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000257 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000258 logger.Debugw("omci-message-decoded:", log.Fields{"omciMsgType": omciMsg.MessageType,
mpagenko3dbcdd22020-07-22 07:38:45 +0000259 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "DeviceIdent": omciMsg.DeviceIdentifier})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000260 if byte(omciMsg.MessageType) & ^me.AK == 0 {
261 // Not a response
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000262 logger.Debug("RxMsg is no Omci Response Message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000263 if omciMsg.TransactionID == 0 {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530264 return oo.receiveOnuMessage(ctx, omciMsg)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000265 }
Himani Chawla4d908332020-08-31 12:30:20 +0530266 logger.Errorw("Unexpected TransCorrId != 0 not accepted for autonomous messages",
Andrea Campanella6515c582020-10-05 11:25:00 +0200267 log.Fields{"msgType": omciMsg.MessageType, "payload": hex.EncodeToString(omciMsg.Payload),
268 "deviceID": oo.deviceID})
269 return fmt.Errorf("autonomous Omci Message with TranSCorrId != 0 not acccepted %s", oo.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530270
271 }
272 //logger.Debug("RxMsg is a Omci Response Message: try to schedule it to the requester")
273 oo.mutexRxSchedMap.Lock()
274 rxCallbackEntry, ok := oo.rxSchedulerMap[omciMsg.TransactionID]
275 if ok && rxCallbackEntry.cbFunction != nil {
276 //disadvantage of decoupling: error verification made difficult, but anyway the question is
277 // how to react on erroneous frame reception, maybe can simply be ignored
278 go rxCallbackEntry.cbFunction(omciMsg, &packet, rxCallbackEntry.cbRespChannel)
279 // having posted the response the request is regarded as 'done'
280 delete(oo.rxSchedulerMap, omciMsg.TransactionID)
281 oo.mutexRxSchedMap.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000282 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530283 oo.mutexRxSchedMap.Unlock()
Andrea Campanella6515c582020-10-05 11:25:00 +0200284 logger.Errorw("omci-message-response for not registered transCorrId", log.Fields{"deviceID": oo.deviceID})
285 return fmt.Errorf("could not find registered response handler tor transCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000286 }
287
288 return nil
289 /* py code was:
290 Receive and OMCI message from the proxy channel to the OLT.
291
292 Call this from your ONU Adapter on a new OMCI Rx on the proxy channel
293 :param msg: (str) OMCI binary message (used as input to Scapy packet decoder)
294 """
295 if not self.enabled:
296 return
297
298 try:
299 now = arrow.utcnow()
300 d = None
301
302 # NOTE: Since we may need to do an independent ME map on a per-ONU basis
303 # save the current value of the entity_id_to_class_map, then
304 # replace it with our custom one before decode, and then finally
305 # restore it later. Tried other ways but really made the code messy.
306 saved_me_map = omci_entities.entity_id_to_class_map
307 omci_entities.entity_id_to_class_map = self._me_map
308
309 try:
310 rx_frame = msg if isinstance(msg, OmciFrame) else OmciFrame(msg)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000311 self.logger.debug('recv-omci-msg', omci_msg=hexlify(msg))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000312 except KeyError as e:
313 # Unknown, Unsupported, or vendor-specific ME. Key is the unknown classID
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000314 self.logger.debug('frame-decode-key-error', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000315 rx_frame = self._decode_unknown_me(msg)
316 self._rx_unknown_me += 1
317
318 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000319 self.logger.exception('frame-decode', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000320 return
321
322 finally:
323 omci_entities.entity_id_to_class_map = saved_me_map # Always restore it.
324
325 rx_tid = rx_frame.fields['transaction_id']
326 msg_type = rx_frame.fields['message_type']
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000327 self.logger.debug('Received message for rx_tid', rx_tid = rx_tid, msg_type = msg_type)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000328 # Filter the Test Result frame and route through receive onu
329 # message method.
330 if rx_tid == 0 or msg_type == EntityOperations.TestResult.value:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000331 self.logger.debug('Receive ONU message', rx_tid=0)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000332 return self._receive_onu_message(rx_frame)
333
334 # Previously unreachable if this is the very first round-trip Rx or we
335 # have been running consecutive errors
336 if self._rx_frames == 0 or self._consecutive_errors != 0:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000337 self.logger.debug('Consecutive errors for rx', err = self._consecutive_errors)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000338 self.reactor.callLater(0, self._publish_connectivity_event, True)
339
340 self._rx_frames += 1
341 self._consecutive_errors = 0
342
343 try:
344 high_priority = self._tid_is_high_priority(rx_tid)
345 index = self._get_priority_index(high_priority)
346
347 # (timestamp, defer, frame, timeout, retry, delayedCall)
348 last_tx_tuple = self._tx_request[index]
349
350 if last_tx_tuple is None or \
351 last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id') != rx_tid:
352 # Possible late Rx on a message that timed-out
353 if last_tx_tuple:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000354 self.logger.debug('Unknown message', rx_tid=rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000355 tx_id=last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id'))
356 self._rx_unknown_tid += 1
357 self._rx_late += 1
358 return
359
360 ts, d, tx_frame, timeout, retry, dc = last_tx_tuple
361 if dc is not None and not dc.cancelled and not dc.called:
362 dc.cancel()
363
364 _secs = self._update_rx_tx_stats(now, ts)
365
366 # Late arrival already serviced by a timeout?
367 if d.called:
368 self._rx_late += 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000369 self.logger.debug('Serviced by timeout. Late arrival', rx_late = self._rx_late)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000370 return
371
372 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000373 self.logger.exception('frame-match', msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000374 if d is not None:
375 return d.errback(failure.Failure(e))
376 return
377
378 # Publish Rx event to listeners in a different task
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000379 self.logger.debug('Publish rx event', rx_tid = rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000380 tx_tid = tx_frame.fields['transaction_id'])
381 reactor.callLater(0, self._publish_rx_frame, tx_frame, rx_frame)
382
383 # begin success callback chain (will cancel timeout and queue next Tx message)
384 self._rx_response[index] = rx_frame
385 d.callback(rx_frame)
386
387 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000388 self.logger.exception('rx-msg', e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000389 */
390}
391
Himani Chawla6d2ae152020-09-02 13:11:20 +0530392/*
393func (oo *omciCC) publishRxResponseFrame(ctx context.Context, txFrame []byte, rxFrame []byte) error {
Himani Chawla4d908332020-08-31 12:30:20 +0530394 return errors.New("publishRxResponseFrame unimplemented")
Himani Chawla6d2ae152020-09-02 13:11:20 +0530395 //def _publish_rx_frame(self, tx_frame, rx_frame):
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000396}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530397*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000398
399//Queue the OMCI Frame for a transmit to the ONU via the proxy_channel
Himani Chawla6d2ae152020-09-02 13:11:20 +0530400func (oo *omciCC) send(ctx context.Context, txFrame []byte, timeout int, retry int, highPrio bool,
401 receiveCallbackPair callbackPair) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000402
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000403 logger.Debugw("register-response-callback:", log.Fields{"for TansCorrId": receiveCallbackPair.cbKey})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000404 // it could be checked, if the callback keay is already registered - but simply overwrite may be acceptable ...
405 oo.mutexRxSchedMap.Lock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000406 oo.rxSchedulerMap[receiveCallbackPair.cbKey] = receiveCallbackPair.cbEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000407 oo.mutexRxSchedMap.Unlock()
408
409 //just use a simple list for starting - might need some more effort, especially for multi source write access
410 omciTxRequest := omciTransferStructure{
411 txFrame,
412 timeout,
413 retry,
414 highPrio,
415 }
416 oo.mutexTxQueue.Lock()
417 oo.txQueue.PushBack(omciTxRequest) // enqueue
418 oo.mutexTxQueue.Unlock()
419
420 // for first test just bypass and send directly:
421 go oo.sendNextRequest(ctx)
422 return nil
423}
424
425//Pull next tx request and send it
Himani Chawla6d2ae152020-09-02 13:11:20 +0530426func (oo *omciCC) sendNextRequest(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000427 // return errors.New("sendNextRequest unimplemented")
428
429 // just try to get something transferred !!
430 // avoid accessing the txQueue from parallel send requests
431 // block parallel omci send requests at least until SendIAP is 'committed'
432 // that should be feasible for an onu instance as on OMCI anyway window size 1 is assumed
433 oo.mutexTxQueue.Lock()
mpagenkodff5dda2020-08-28 11:52:01 +0000434 defer oo.mutexTxQueue.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000435 for oo.txQueue.Len() > 0 {
436 queueElement := oo.txQueue.Front() // First element
437 omciTxRequest := queueElement.Value.(omciTransferStructure)
438 /* compare olt device handler code:
439 func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000440 logger.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000441 var deviceType string
442 var deviceID string
443 var proxyDeviceID string
444
445 onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
446
447 if onuInCache, ok := dh.onus.Load(onuKey); !ok {
448
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000449 logger.Debugw("omci indication for a device not in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000450 ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
451 kwargs := make(map[string]interface{})
452 kwargs["onu_id"] = omciInd.OnuId
453 kwargs["parent_port_no"] = ponPort
454
455 onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
456 if err != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000457 logger.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId, "error": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000458 return
459 }
460 deviceType = onuDevice.Type
461 deviceID = onuDevice.Id
462 proxyDeviceID = onuDevice.ProxyAddress.DeviceId
463 //if not exist in cache, then add to cache.
464 dh.onus.Store(onuKey, NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID))
465 } else {
466 //found in cache
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000467 logger.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000468 deviceType = onuInCache.(*OnuDevice).deviceType
469 deviceID = onuInCache.(*OnuDevice).deviceID
470 proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID
471 }
472 */
473 /* and compare onu_adapter py code:
474 omci_msg = InterAdapterOmciMessage(
475 message=bytes(frame),
476 proxy_address=self._proxy_address,
477 connect_status=self._device.connect_status)
478
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000479 self.logger.debug('sent-omci-msg', tid=tx_tid, omci_msg=hexlify(bytes(frame)))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000480
481 yield self._adapter_proxy.send_inter_adapter_message(
482 msg=omci_msg,
483 type=InterAdapterMessageType.OMCI_REQUEST,
484 from_adapter=self._device.type,
485 to_adapter=self._proxy_address.device_type,
486 to_device_id=self._device_id,
487 proxy_device_id=self._proxy_address.device_id
488 )
489 */
490 device, err := oo.coreProxy.GetDevice(ctx,
491 oo.pBaseDeviceHandler.deviceID, oo.deviceID) //parent, child
492 if err != nil || device == nil {
493 /*TODO: needs to handle error scenarios */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000494 logger.Errorw("Failed to fetch device", log.Fields{"err": err, "ParentId": oo.pBaseDeviceHandler.deviceID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000495 "ChildId": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200496 return fmt.Errorf("failed to fetch device %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000497 }
498
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000499 logger.Debugw("omci-message-sending", log.Fields{"fromDeviceType": oo.pBaseDeviceHandler.DeviceType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000500 "toDeviceType": oo.pBaseDeviceHandler.ProxyAddressType,
501 "onuDeviceID": oo.deviceID, "proxyDeviceID": oo.pBaseDeviceHandler.ProxyAddressID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000502 logger.Debugw("omci-message-to-send:",
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000503 log.Fields{"TxOmciMessage": hex.EncodeToString(omciTxRequest.txFrame)})
504
505 omciMsg := &ic.InterAdapterOmciMessage{Message: omciTxRequest.txFrame}
506 if sendErr := oo.adapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
507 ic.InterAdapterMessageType_OMCI_REQUEST,
508 //fromType,toType,toDevId, ProxyDevId
509 oo.pBaseDeviceHandler.DeviceType, oo.pBaseDeviceHandler.ProxyAddressType,
510 oo.deviceID, oo.pBaseDeviceHandler.ProxyAddressID, ""); sendErr != nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200511 logger.Errorw("send omci request error", log.Fields{"ChildId": oo.deviceID, "error": sendErr})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000512 return sendErr
513 }
514 oo.txQueue.Remove(queueElement) // Dequeue
515 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000516 return nil
517}
518
Himani Chawla6d2ae152020-09-02 13:11:20 +0530519func (oo *omciCC) getNextTid(highPriority bool) uint16 {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000520 var next uint16
521 if highPriority {
mpagenko900ee4b2020-10-12 11:56:34 +0000522 oo.mutexHpTid.Lock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000523 next = oo.hpTid
Himani Chawla4d908332020-08-31 12:30:20 +0530524 oo.hpTid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000525 if oo.hpTid < 0x8000 {
526 oo.hpTid = 0x8000
527 }
mpagenko900ee4b2020-10-12 11:56:34 +0000528 oo.mutexHpTid.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000529 } else {
mpagenko900ee4b2020-10-12 11:56:34 +0000530 oo.mutexTid.Lock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000531 next = oo.tid
Himani Chawla4d908332020-08-31 12:30:20 +0530532 oo.tid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000533 if oo.tid >= 0x8000 {
534 oo.tid = 1
535 }
mpagenko900ee4b2020-10-12 11:56:34 +0000536 oo.mutexTid.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000537 }
538 return next
539}
540
541// ###################################################################################
542// # utility methods provided to work on OMCI messages
543func serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
544 omciLayer := &omci.OMCI{
545 TransactionID: tid,
546 MessageType: msgType,
547 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000548 return serializeOmciLayer(omciLayer, request)
549}
550
Himani Chawla4d908332020-08-31 12:30:20 +0530551func serializeOmciLayer(aOmciLayer *omci.OMCI, aRequest gopacket.SerializableLayer) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000552 var options gopacket.SerializeOptions
553 options.FixLengths = true
554
555 buffer := gopacket.NewSerializeBuffer()
Himani Chawla4d908332020-08-31 12:30:20 +0530556 err := gopacket.SerializeLayers(buffer, options, aOmciLayer, aRequest)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000557 if err != nil {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000558 logger.Errorw("Could not create goPacket Omci serial buffer", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000559 return nil, err
560 }
561 return buffer.Bytes(), nil
562}
563
Himani Chawla4d908332020-08-31 12:30:20 +0530564/*
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000565func hexEncode(omciPkt []byte) ([]byte, error) {
566 dst := make([]byte, hex.EncodedLen(len(omciPkt)))
567 hex.Encode(dst, omciPkt)
568 return dst, nil
569}
Himani Chawla4d908332020-08-31 12:30:20 +0530570*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000571
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000572//supply a response handler for omci response messages to be transferred to the requested FSM
Himani Chawla6d2ae152020-09-02 13:11:20 +0530573func (oo *omciCC) receiveOmciResponse(omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000574
mpagenko3dbcdd22020-07-22 07:38:45 +0000575 logger.Debugw("omci-message-response - transfer on omciRespChannel", log.Fields{"omciMsgType": omciMsg.MessageType,
divyadesai4d299552020-08-18 07:13:49 +0000576 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000577
578 if oo.pOnuDeviceEntry == nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000579 logger.Errorw("Abort receiving OMCI response, DeviceEntryPointer is nil", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000580 "device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200581 return fmt.Errorf("deviceEntryPointer is nil %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000582 }
583
584 // no further test on SeqNo is done here, assignment from rxScheduler is trusted
585 // MibSync responses are simply transferred via deviceEntry to MibSync, no specific analysis here
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000586 omciRespMsg := Message{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000587 Type: OMCI,
588 Data: OmciMessage{
589 OmciMsg: omciMsg,
590 OmciPacket: packet,
591 },
592 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000593 //logger.Debugw("Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000594 respChan <- omciRespMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000595
596 return nil
597}
598
Himani Chawla6d2ae152020-09-02 13:11:20 +0530599func (oo *omciCC) sendMibReset(ctx context.Context, timeout int, highPrio bool) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000600
divyadesai4d299552020-08-18 07:13:49 +0000601 logger.Debugw("send MibReset-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000602 request := &omci.MibResetRequest{
603 MeBasePacket: omci.MeBasePacket{
604 EntityClass: me.OnuDataClassID,
605 },
606 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530607 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000608 pkt, err := serialize(omci.MibResetRequestType, request, tid)
609 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000610 logger.Errorw("Cannot serialize MibResetRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000611 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000612 return err
613 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530614 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000615 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530616 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000617 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530618 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000619}
620
Himani Chawla6d2ae152020-09-02 13:11:20 +0530621func (oo *omciCC) sendReboot(ctx context.Context, timeout int, highPrio bool, responseChannel chan Message) error {
divyadesai4d299552020-08-18 07:13:49 +0000622 logger.Debugw("send Reboot-msg to:", log.Fields{"device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300623 request := &omci.RebootRequest{
624 MeBasePacket: omci.MeBasePacket{
625 EntityClass: me.OnuGClassID,
626 },
627 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530628 tid := oo.getNextTid(highPrio)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300629 pkt, err := serialize(omci.RebootRequestType, request, tid)
630 if err != nil {
631 logger.Errorw("Cannot serialize RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000632 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300633 return err
634 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530635 omciRxCallbackPair := callbackPair{
ozgecanetsiae11479f2020-07-06 09:44:47 +0300636 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530637 cbEntry: callbackPairEntry{oo.pOnuDeviceEntry.omciRebootMessageReceivedChannel, oo.receiveOmciResponse},
ozgecanetsiae11479f2020-07-06 09:44:47 +0300638 }
639
Himani Chawla6d2ae152020-09-02 13:11:20 +0530640 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300641 if err != nil {
642 logger.Errorw("Cannot send RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000643 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300644 return err
645 }
646 err = oo.pOnuDeviceEntry.waitForRebootResponse(responseChannel)
647 if err != nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200648 logger.Errorw("aborting ONU Reboot!", log.Fields{
649 "Err": err, "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530650 _ = oo.pOnuDeviceEntry.pMibDownloadFsm.pFsm.Event("reset")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300651 return err
652 }
653 return nil
654}
655
Himani Chawla6d2ae152020-09-02 13:11:20 +0530656func (oo *omciCC) sendMibUpload(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000657 logger.Debugw("send MibUpload-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000658 request := &omci.MibUploadRequest{
659 MeBasePacket: omci.MeBasePacket{
660 EntityClass: me.OnuDataClassID,
661 },
662 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530663 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000664 pkt, err := serialize(omci.MibUploadRequestType, request, tid)
665 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000666 logger.Errorw("Cannot serialize MibUploadRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000667 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000668 return err
669 }
670 oo.uploadSequNo = 0
671 oo.uploadNoOfCmds = 0
672
Himani Chawla6d2ae152020-09-02 13:11:20 +0530673 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000674 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530675 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000676 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530677 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000678}
679
Himani Chawla6d2ae152020-09-02 13:11:20 +0530680func (oo *omciCC) sendMibUploadNext(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000681 logger.Debugw("send MibUploadNext-msg to:", log.Fields{"device-id": oo.deviceID, "uploadSequNo": oo.uploadSequNo})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000682 request := &omci.MibUploadNextRequest{
683 MeBasePacket: omci.MeBasePacket{
684 EntityClass: me.OnuDataClassID,
685 },
686 CommandSequenceNumber: oo.uploadSequNo,
687 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530688 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000689 pkt, err := serialize(omci.MibUploadNextRequestType, request, tid)
690 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000691 logger.Errorw("Cannot serialize MibUploadNextRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000692 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000693 return err
694 }
695 oo.uploadSequNo++
696
Himani Chawla6d2ae152020-09-02 13:11:20 +0530697 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000698 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530699 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000700 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530701 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000702}
703
Himani Chawla6d2ae152020-09-02 13:11:20 +0530704func (oo *omciCC) sendCreateGalEthernetProfile(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
705 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000706 logger.Debugw("send GalEnetProfile-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000707 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000708
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000709 meParams := me.ParamData{
710 EntityID: galEthernetEID,
711 Attributes: me.AttributeValueMap{"MaximumGemPayloadSize": maxGemPayloadSize},
712 }
713 meInstance, omciErr := me.NewGalEthernetProfile(meParams)
714 if omciErr.GetError() == nil {
715 //all setByCreate parameters already set, no default option required ...
716 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
717 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000718 logger.Errorw("Cannot encode GalEnetProfileInstance for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000719 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000720 return nil
721 }
722
723 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
724 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000725 logger.Errorw("Cannot serialize GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000726 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000727 return nil
728 }
729
Himani Chawla6d2ae152020-09-02 13:11:20 +0530730 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000731 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530732 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000733 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530734 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000735 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000736 logger.Errorw("Cannot send GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000737 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000738 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000739 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000740 logger.Debug("send GalEnetProfile-Create-msg done")
741 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000742 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000743 logger.Errorw("Cannot generate GalEnetProfileInstance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000744 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000745 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000746}
747
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000748// might be needed to extend for parameter arguments, here just for setting the ConnectivityMode!!
Himani Chawla6d2ae152020-09-02 13:11:20 +0530749func (oo *omciCC) sendSetOnu2g(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
750 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000751 logger.Debugw("send ONU2-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000752 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000753
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000754 // ONU-G ME-ID is defined to be 0, but we could verify, if the ONU really supports the desired
755 // connectivity mode 5 (in ConnCap)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000756 // By now we just use fix values to fire - this is anyway what the python adapter does
757 // read ONU-2G from DB ???? //TODO!!!
758 meParams := me.ParamData{
759 EntityID: 0,
760 Attributes: me.AttributeValueMap{"CurrentConnectivityMode": connectivityModeValue},
761 }
762 meInstance, omciErr := me.NewOnu2G(meParams)
763 if omciErr.GetError() == nil {
764 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
765 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000766 logger.Errorw("Cannot encode ONU2-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000767 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000768 return nil
769 }
770
771 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
772 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000773 logger.Errorw("Cannot serialize ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000774 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000775 return nil
776 }
777
Himani Chawla6d2ae152020-09-02 13:11:20 +0530778 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000779 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530780 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000781 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530782 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000783 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000784 logger.Errorw("Cannot send ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000785 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000786 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000787 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000788 logger.Debug("send ONU2-G-Set-msg done")
789 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000790 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000791 logger.Errorw("Cannot generate ONU2-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000792 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000793 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000794}
795
Himani Chawla6d2ae152020-09-02 13:11:20 +0530796func (oo *omciCC) sendCreateMBServiceProfile(ctx context.Context,
797 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
798 tid := oo.getNextTid(highPrio)
Himani Chawla4d908332020-08-31 12:30:20 +0530799 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000800 logger.Debugw("send MBSP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000801 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000802
803 meParams := me.ParamData{
804 EntityID: instID,
805 Attributes: me.AttributeValueMap{
806 "Priority": 0x8000,
807 "MaxAge": 20 * 256, //20s
808 "HelloTime": 2 * 256, //2s
809 "ForwardDelay": 15 * 256, //15s
810 //note: DynamicFilteringAgeingTime is taken from omci lib default as
811 // which is obviously different from default value used in python lib,
812 // where the value seems to be 0 (ONU defined) - to be considered in case of test artifacts ...
813 },
814 }
815
816 meInstance, omciErr := me.NewMacBridgeServiceProfile(meParams)
817 if omciErr.GetError() == nil {
818 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
819 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
820 omci.TransactionID(tid), omci.AddDefaults(true))
821 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000822 logger.Errorw("Cannot encode MBSP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000823 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000824 return nil
825 }
826
827 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
828 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000829 logger.Errorw("Cannot serialize MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000830 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000831 return nil
832 }
833
Himani Chawla6d2ae152020-09-02 13:11:20 +0530834 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000835 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530836 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000837 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530838 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000839 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000840 logger.Errorw("Cannot send MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000841 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000842 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000843 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000844 logger.Debug("send MBSP-Create-msg done")
845 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000846 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000847 logger.Errorw("Cannot generate MBSP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000848 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000849 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000850}
851
Himani Chawla6d2ae152020-09-02 13:11:20 +0530852func (oo *omciCC) sendCreateMBPConfigData(ctx context.Context,
853 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
854 tid := oo.getNextTid(highPrio)
Himani Chawla26e555c2020-08-31 12:30:20 +0530855 instID := macBridgePortAniEID + aPUniPort.entityID
divyadesai4d299552020-08-18 07:13:49 +0000856 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000857 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000858
859 meParams := me.ParamData{
860 EntityID: instID,
861 Attributes: me.AttributeValueMap{
Himani Chawla4d908332020-08-31 12:30:20 +0530862 "BridgeIdPointer": macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo),
863 "PortNum": aPUniPort.macBpNo,
864 "TpType": uint8(aPUniPort.portType),
Himani Chawla26e555c2020-08-31 12:30:20 +0530865 "TpPointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000866 },
867 }
868 meInstance, omciErr := me.NewMacBridgePortConfigurationData(meParams)
869 if omciErr.GetError() == nil {
870 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
871 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
872 omci.TransactionID(tid), omci.AddDefaults(true))
873 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000874 logger.Errorw("Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000875 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000876 return nil
877 }
878
879 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
880 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000881 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000882 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000883 return nil
884 }
885
Himani Chawla6d2ae152020-09-02 13:11:20 +0530886 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000887 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530888 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000889 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530890 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000891 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000892 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000893 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000894 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000895 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000896 logger.Debug("send MBPCD-Create-msg done")
897 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000898 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000899 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000900 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000901 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000902}
903
Himani Chawla6d2ae152020-09-02 13:11:20 +0530904func (oo *omciCC) sendCreateEVTOConfigData(ctx context.Context,
905 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
906 tid := oo.getNextTid(highPrio)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000907 //same entityId is used as for MBSP (see there), but just arbitrary ...
Himani Chawla4d908332020-08-31 12:30:20 +0530908 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000909 logger.Debugw("send EVTOCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000910 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000911
912 // compare python adapter code WA VOL-1311: this is not done here!
913 // (setting TPID values for the create would probably anyway be ignored by the omci lib)
914 // but perhaps we have to be aware of possible problems at get(Next) Request handling for EVTOOCD tables later ...
915 assType := uint8(2) // default AssociationType is PPTPEthUni
Himani Chawla6d2ae152020-09-02 13:11:20 +0530916 if aPUniPort.portType == uniVEIP {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000917 assType = uint8(10) // for VEIP
918 }
919 meParams := me.ParamData{
920 EntityID: instID,
921 Attributes: me.AttributeValueMap{
922 "AssociationType": assType,
Himani Chawla26e555c2020-08-31 12:30:20 +0530923 "AssociatedMePointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000924 },
925 }
926 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(meParams)
927 if omciErr.GetError() == nil {
928 //all setByCreate parameters already set, no default option required ...
929 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
930 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000931 logger.Errorw("Cannot encode EVTOCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000932 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000933 return nil
934 }
935
936 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
937 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000938 logger.Errorw("Cannot serialize EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000939 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000940 return nil
941 }
942
Himani Chawla6d2ae152020-09-02 13:11:20 +0530943 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000944 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530945 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000946 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530947 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000948 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000949 logger.Errorw("Cannot send EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000950 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000951 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000952 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000953 logger.Debug("send EVTOCD-Create-msg done")
954 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000955 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000956 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000957 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000958 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000959}
960
Himani Chawla6d2ae152020-09-02 13:11:20 +0530961func (oo *omciCC) sendSetOnuGLS(ctx context.Context, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000962 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530963 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000964 logger.Debugw("send ONU-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000965 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000966
967 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
968 meParams := me.ParamData{
969 EntityID: 0,
970 Attributes: requestedAttributes,
971 }
972 meInstance, omciErr := me.NewOnuG(meParams)
973 if omciErr.GetError() == nil {
974 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
975 if err != nil {
976 logger.Errorw("Cannot encode ONU-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000977 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000978 return nil
979 }
980
981 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
982 if err != nil {
983 logger.Errorw("Cannot serialize ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000984 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000985 return nil
986 }
987
Himani Chawla6d2ae152020-09-02 13:11:20 +0530988 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000989 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530990 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000991 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530992 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000993 if err != nil {
994 logger.Errorw("Cannot send ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000995 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000996 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000997 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000998 logger.Debug("send ONU-G-Set-msg done")
999 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001000 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001001 logger.Errorw("Cannot generate ONU-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001002 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001003 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001004}
1005
Himani Chawla6d2ae152020-09-02 13:11:20 +05301006func (oo *omciCC) sendSetUniGLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001007 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301008 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001009 logger.Debugw("send UNI-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001010 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001011
1012 // UNI-G ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
1013 meParams := me.ParamData{
1014 EntityID: aInstNo,
1015 Attributes: requestedAttributes,
1016 }
1017 meInstance, omciErr := me.NewUniG(meParams)
1018 if omciErr.GetError() == nil {
1019 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1020 if err != nil {
1021 logger.Errorw("Cannot encode UNI-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001022 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001023 return nil
1024 }
1025
1026 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1027 if err != nil {
1028 logger.Errorw("Cannot serialize UNI-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001029 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001030 return nil
1031 }
1032
Himani Chawla6d2ae152020-09-02 13:11:20 +05301033 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001034 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301035 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001036 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301037 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001038 if err != nil {
1039 logger.Errorw("Cannot send UNIG-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001040 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001041 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001042 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001043 logger.Debug("send UNI-G-Set-msg done")
1044 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001045 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001046 logger.Errorw("Cannot generate UNI-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001047 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001048 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001049}
1050
Himani Chawla6d2ae152020-09-02 13:11:20 +05301051func (oo *omciCC) sendSetVeipLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001052 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301053 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001054 logger.Debugw("send VEIP-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001055 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001056
1057 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1058 meParams := me.ParamData{
1059 EntityID: aInstNo,
1060 Attributes: requestedAttributes,
1061 }
1062 meInstance, omciErr := me.NewVirtualEthernetInterfacePoint(meParams)
1063 if omciErr.GetError() == nil {
1064 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1065 if err != nil {
1066 logger.Errorw("Cannot encode VEIP instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001067 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001068 return nil
1069 }
1070
1071 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1072 if err != nil {
1073 logger.Errorw("Cannot serialize VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001074 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001075 return nil
1076 }
1077
Himani Chawla6d2ae152020-09-02 13:11:20 +05301078 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001079 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301080 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001081 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301082 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001083 if err != nil {
1084 logger.Errorw("Cannot send VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001085 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001086 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001087 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001088 logger.Debug("send VEIP-Set-msg done")
1089 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001090 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001091 logger.Errorw("Cannot generate VEIP", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001092 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001093 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001094}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001095
Himani Chawla6d2ae152020-09-02 13:11:20 +05301096func (oo *omciCC) sendGetMe(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributes me.AttributeValueMap,
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001097 timeout int, highPrio bool) *me.ManagedEntity {
1098
Himani Chawla6d2ae152020-09-02 13:11:20 +05301099 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001100 logger.Debugw("send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001101 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001102
1103 meParams := me.ParamData{
1104 EntityID: entityID,
1105 Attributes: requestedAttributes,
1106 }
1107 meInstance, omciErr := me.LoadManagedEntityDefinition(classID, meParams)
1108 if omciErr.GetError() == nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301109 meClassIDName := meInstance.GetName()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001110 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.GetRequestType, omci.TransactionID(tid))
1111 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301112 logger.Errorf("Cannot encode instance for get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001113 return nil
1114 }
1115 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1116 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301117 logger.Errorw("Cannot serialize get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001118 return nil
1119 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301120 omciRxCallbackPair := callbackPair{
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001121 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301122 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001123 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301124 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001125 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301126 logger.Errorw("Cannot send get-request-msg", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001127 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001128 }
Himani Chawla4d908332020-08-31 12:30:20 +05301129 logger.Debugw("send get-request-msg done", log.Fields{"meClassIDName": meClassIDName, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001130 return meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001131 }
divyadesai4d299552020-08-18 07:13:49 +00001132 logger.Errorw("Cannot generate meDefinition", log.Fields{"classID": classID, "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001133 return nil
1134}
1135
Himani Chawla6d2ae152020-09-02 13:11:20 +05301136func (oo *omciCC) sendCreateDot1PMapper(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001137 aInstID uint16, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301138 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001139 logger.Debugw("send .1pMapper-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001140 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
1141
1142 meParams := me.ParamData{
1143 EntityID: aInstID,
1144 Attributes: me.AttributeValueMap{},
1145 }
1146 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
1147 if omciErr.GetError() == nil {
1148 //we have to set all 'untouched' parameters to default by some additional option parameter!!
1149 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1150 omci.TransactionID(tid), omci.AddDefaults(true))
1151 if err != nil {
1152 logger.Errorw("Cannot encode .1pMapper for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001153 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001154 return nil
1155 }
1156
1157 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1158 if err != nil {
1159 logger.Errorw("Cannot serialize .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001160 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001161 return nil
1162 }
1163
Himani Chawla6d2ae152020-09-02 13:11:20 +05301164 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001165 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301166 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001167 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301168 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001169 if err != nil {
1170 logger.Errorw("Cannot send .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001171 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001172 return nil
1173 }
1174 logger.Debug("send .1pMapper-create-msg done")
1175 return meInstance
1176 }
1177 logger.Errorw("Cannot generate .1pMapper", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001178 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001179 return nil
1180}
1181
Himani Chawla6d2ae152020-09-02 13:11:20 +05301182func (oo *omciCC) sendCreateMBPConfigDataVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001183 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301184 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001185 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001186 "SequNo": strconv.FormatInt(int64(tid), 16),
1187 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1188
1189 meInstance, omciErr := me.NewMacBridgePortConfigurationData(params[0])
1190 if omciErr.GetError() == nil {
1191 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1192 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1193 omci.TransactionID(tid), omci.AddDefaults(true))
1194 if err != nil {
1195 logger.Errorw("Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001196 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001197 return nil
1198 }
1199
1200 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1201 if err != nil {
1202 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001203 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001204 return nil
1205 }
1206
Himani Chawla6d2ae152020-09-02 13:11:20 +05301207 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001208 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301209 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001210 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301211 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001212 if err != nil {
1213 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001214 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001215 return nil
1216 }
1217 logger.Debug("send MBPCD-Create-msg done")
1218 return meInstance
1219 }
1220 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001221 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001222 return nil
1223}
1224
Himani Chawla6d2ae152020-09-02 13:11:20 +05301225func (oo *omciCC) sendCreateGemNCTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001226 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301227 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001228 logger.Debugw("send GemNCTP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001229 "SequNo": strconv.FormatInt(int64(tid), 16),
1230 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1231
1232 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1233 if omciErr.GetError() == nil {
1234 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1235 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1236 omci.TransactionID(tid), omci.AddDefaults(true))
1237 if err != nil {
1238 logger.Errorw("Cannot encode GemNCTP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001239 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001240 return nil
1241 }
1242
1243 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1244 if err != nil {
1245 logger.Errorw("Cannot serialize GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001246 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001247 return nil
1248 }
1249
Himani Chawla6d2ae152020-09-02 13:11:20 +05301250 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001251 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301252 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001253 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301254 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001255 if err != nil {
1256 logger.Errorw("Cannot send GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001257 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001258 return nil
1259 }
1260 logger.Debug("send GemNCTP-Create-msg done")
1261 return meInstance
1262 }
1263 logger.Errorw("Cannot generate GemNCTP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001264 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001265 return nil
1266}
1267
Himani Chawla6d2ae152020-09-02 13:11:20 +05301268func (oo *omciCC) sendCreateGemIWTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001269 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301270 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001271 logger.Debugw("send GemIwTp-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001272 "SequNo": strconv.FormatInt(int64(tid), 16),
1273 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1274
1275 meInstance, omciErr := me.NewGemInterworkingTerminationPoint(params[0])
1276 if omciErr.GetError() == nil {
1277 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1278 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1279 omci.TransactionID(tid))
1280 if err != nil {
1281 logger.Errorw("Cannot encode GemIwTp for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001282 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001283 return nil
1284 }
1285
1286 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1287 if err != nil {
1288 logger.Errorw("Cannot serialize GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001289 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001290 return nil
1291 }
1292
Himani Chawla6d2ae152020-09-02 13:11:20 +05301293 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001294 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301295 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001296 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301297 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001298 if err != nil {
1299 logger.Errorw("Cannot send GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001300 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001301 return nil
1302 }
1303 logger.Debug("send GemIwTp-Create-msg done")
1304 return meInstance
1305 }
1306 logger.Errorw("Cannot generate GemIwTp Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001307 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001308 return nil
1309}
1310
Himani Chawla6d2ae152020-09-02 13:11:20 +05301311func (oo *omciCC) sendSetTcontVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001312 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301313 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001314 logger.Debugw("send TCont-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001315 "SequNo": strconv.FormatInt(int64(tid), 16),
1316 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1317
1318 meInstance, omciErr := me.NewTCont(params[0])
1319 if omciErr.GetError() == nil {
1320 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1321 if err != nil {
1322 logger.Errorw("Cannot encode TCont for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001323 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001324 return nil
1325 }
1326
1327 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1328 if err != nil {
1329 logger.Errorw("Cannot serialize TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001330 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001331 return nil
1332 }
1333
Himani Chawla6d2ae152020-09-02 13:11:20 +05301334 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001335 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301336 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001337 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301338 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001339 if err != nil {
1340 logger.Errorw("Cannot send TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001341 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001342 return nil
1343 }
1344 logger.Debug("send TCont-set msg done")
1345 return meInstance
1346 }
1347 logger.Errorw("Cannot generate TCont Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001348 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001349 return nil
1350}
1351
Himani Chawla6d2ae152020-09-02 13:11:20 +05301352func (oo *omciCC) sendSetPrioQueueVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001353 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301354 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001355 logger.Debugw("send PrioQueue-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001356 "SequNo": strconv.FormatInt(int64(tid), 16),
1357 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1358
1359 meInstance, omciErr := me.NewPriorityQueue(params[0])
1360 if omciErr.GetError() == nil {
1361 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1362 if err != nil {
1363 logger.Errorw("Cannot encode PrioQueue for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001364 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001365 return nil
1366 }
1367
1368 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1369 if err != nil {
1370 logger.Errorw("Cannot serialize PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001371 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001372 return nil
1373 }
1374
Himani Chawla6d2ae152020-09-02 13:11:20 +05301375 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001376 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301377 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001378 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301379 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001380 if err != nil {
1381 logger.Errorw("Cannot send PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001382 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001383 return nil
1384 }
1385 logger.Debug("send PrioQueue-set msg done")
1386 return meInstance
1387 }
1388 logger.Errorw("Cannot generate PrioQueue Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001389 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001390 return nil
1391}
1392
Himani Chawla6d2ae152020-09-02 13:11:20 +05301393func (oo *omciCC) sendSetDot1PMapperVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001394 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301395 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001396 logger.Debugw("send 1PMapper-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001397 "SequNo": strconv.FormatInt(int64(tid), 16),
1398 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1399
1400 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(params[0])
1401 if omciErr.GetError() == nil {
1402 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1403 if err != nil {
1404 logger.Errorw("Cannot encode 1PMapper for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001405 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001406 return nil
1407 }
1408
1409 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1410 if err != nil {
1411 logger.Errorw("Cannot serialize 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001412 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001413 return nil
1414 }
1415
Himani Chawla6d2ae152020-09-02 13:11:20 +05301416 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001417 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301418 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001419 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301420 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001421 if err != nil {
1422 logger.Errorw("Cannot send 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001423 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001424 return nil
1425 }
1426 logger.Debug("send 1PMapper-set msg done")
1427 return meInstance
1428 }
1429 logger.Errorw("Cannot generate 1PMapper Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001430 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001431 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001432}
mpagenkodff5dda2020-08-28 11:52:01 +00001433
Himani Chawla6d2ae152020-09-02 13:11:20 +05301434func (oo *omciCC) sendCreateVtfdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001435 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301436 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001437 logger.Debugw("send VTFD-Create-msg:", log.Fields{"device-id": oo.deviceID,
1438 "SequNo": strconv.FormatInt(int64(tid), 16),
1439 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1440
1441 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1442 if omciErr.GetError() == nil {
1443 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1444 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1445 omci.TransactionID(tid))
1446 if err != nil {
1447 logger.Errorw("Cannot encode VTFD for create", log.Fields{
1448 "Err": err, "device-id": oo.deviceID})
1449 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1450 // return (dual format) error code that can be used at caller for immediate error treatment
1451 // (relevant to all used sendXX() methods and their error conditions)
1452 return nil
1453 }
1454
1455 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1456 if err != nil {
1457 logger.Errorw("Cannot serialize VTFD create", log.Fields{
1458 "Err": err, "device-id": oo.deviceID})
1459 return nil
1460 }
1461
Himani Chawla6d2ae152020-09-02 13:11:20 +05301462 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001463 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301464 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001465 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301466 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001467 if err != nil {
1468 logger.Errorw("Cannot send VTFD create", log.Fields{
1469 "Err": err, "device-id": oo.deviceID})
1470 return nil
1471 }
1472 logger.Debug("send VTFD-Create-msg done")
1473 return meInstance
1474 }
1475 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1476 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1477 return nil
1478}
1479
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001480func (oo *omciCC) sendSetVtfdVar(ctx context.Context, timeout int, highPrio bool,
1481 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1482 tid := oo.getNextTid(highPrio)
1483 logger.Debugw("send VTFD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1484 "SequNo": strconv.FormatInt(int64(tid), 16),
1485 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1486
1487 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1488 if omciErr.GetError() == nil {
1489 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType,
1490 omci.TransactionID(tid))
1491 if err != nil {
1492 logger.Errorw("Cannot encode VTFD for set", log.Fields{
1493 "Err": err, "device-id": oo.deviceID})
1494 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1495 // return (dual format) error code that can be used at caller for immediate error treatment
1496 // (relevant to all used sendXX() methods and their error conditions)
1497 return nil
1498 }
1499
1500 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1501 if err != nil {
1502 logger.Errorw("Cannot serialize VTFD set", log.Fields{
1503 "Err": err, "device-id": oo.deviceID})
1504 return nil
1505 }
1506
1507 omciRxCallbackPair := callbackPair{
1508 cbKey: tid,
1509 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
1510 }
1511 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1512 if err != nil {
1513 logger.Errorw("Cannot send VTFD set", log.Fields{
1514 "Err": err, "device-id": oo.deviceID})
1515 return nil
1516 }
1517 logger.Debug("send VTFD-Set-msg done")
1518 return meInstance
1519 }
1520 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1521 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1522 return nil
1523}
1524
Himani Chawla6d2ae152020-09-02 13:11:20 +05301525func (oo *omciCC) sendSetEvtocdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001526 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301527 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001528 logger.Debugw("send EVTOCD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1529 "SequNo": strconv.FormatInt(int64(tid), 16),
1530 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1531
1532 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(params[0])
1533 if omciErr.GetError() == nil {
1534 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1535 if err != nil {
1536 logger.Errorw("Cannot encode EVTOCD for set", log.Fields{
1537 "Err": err, "device-id": oo.deviceID})
1538 return nil
1539 }
1540
1541 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1542 if err != nil {
1543 logger.Errorw("Cannot serialize EVTOCD set", log.Fields{
1544 "Err": err, "device-id": oo.deviceID})
1545 return nil
1546 }
1547
Himani Chawla6d2ae152020-09-02 13:11:20 +05301548 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001549 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301550 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001551 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301552 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001553 if err != nil {
1554 logger.Errorw("Cannot send EVTOCD set", log.Fields{
1555 "Err": err, "device-id": oo.deviceID})
1556 return nil
1557 }
1558 logger.Debug("send EVTOCD-set msg done")
1559 return meInstance
1560 }
1561 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
1562 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1563 return nil
1564}