blob: 23fd506cde67eb22394082bfe45af3c18fc07a00 [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"
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000026 "strconv"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000027 "sync"
mpagenkodff5dda2020-08-28 11:52:01 +000028
Holger Hildebrandtfa074992020-03-27 15:42:06 +000029 //"time"
30
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
35 "github.com/opencord/omci-lib-go"
36 me "github.com/opencord/omci-lib-go/generated"
37 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
38
39 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
40 "github.com/opencord/voltha-lib-go/v3/pkg/log"
41 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
42 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
43 //"github.com/opencord/voltha-protos/v3/go/voltha"
44)
45
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000046// ### OMCI related definitions - retrieved from Python adapter code/trace ####
Holger Hildebrandtfa074992020-03-27 15:42:06 +000047const ConstDefaultOmciTimeout = 10 // ( 3 ?) Seconds
48
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000049const galEthernetEID = uint16(1)
50const maxGemPayloadSize = uint16(48)
51const connectivityModeValue = uint8(5)
52const defaultTPID = uint16(0x8100)
53const broadComDefaultVID = uint16(4091)
54const macBridgeServiceProfileEID = uint16(0x201) // TODO: most all these need better definition or tuning
55const ieeeMapperServiceProfileEID = uint16(0x8001)
56const macBridgePortAniEID = uint16(0x2102)
57
58// ### OMCI related definitions - end
59
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000060//CallbackPairEntry to be used for OMCI send/receive correlation
61type CallbackPairEntry struct {
62 cbRespChannel chan Message
63 cbFunction func(*omci.OMCI, *gp.Packet, chan Message) error
64}
65
Holger Hildebrandtfa074992020-03-27 15:42:06 +000066//CallbackPair to be used for ReceiveCallback init
67type CallbackPair struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000068 cbKey uint16
69 cbEntry CallbackPairEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +000070}
71
72type omciTransferStructure struct {
73 txFrame []byte
74 timeout int
75 retry int
76 highPrio bool
77}
78
79//OmciCC structure holds information needed for OMCI communication (to/from OLT Adapter)
80type OmciCC struct {
81 enabled bool
82 pOnuDeviceEntry *OnuDeviceEntry
83 deviceID string
84 pBaseDeviceHandler *DeviceHandler
85 coreProxy adapterif.CoreProxy
86 adapterProxy adapterif.AdapterProxy
87 supportExtMsg bool
88 //txRequest
89 //rxResponse
90 //pendingRequest
91 txFrames, txOnuFrames uint32
92 rxFrames, rxOnuFrames, rxOnuDiscards uint32
93
94 // OMCI params
95 mutexTid sync.Mutex
96 tid uint16
97 mutexHpTid sync.Mutex
98 hpTid uint16
99 uploadSequNo uint16
100 uploadNoOfCmds uint16
101
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000102 mutexTxQueue sync.Mutex
103 txQueue *list.List
104 mutexRxSchedMap sync.Mutex
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000105 rxSchedulerMap map[uint16]CallbackPairEntry
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000106 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000107}
108
109//NewOmciCC constructor returns a new instance of a OmciCC
110//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
111func NewOmciCC(ctx context.Context, onu_device_entry *OnuDeviceEntry,
112 device_id string, device_handler *DeviceHandler,
113 core_proxy adapterif.CoreProxy, adapter_proxy adapterif.AdapterProxy) *OmciCC {
divyadesai4d299552020-08-18 07:13:49 +0000114 logger.Infow("init-omciCC", log.Fields{"device-id": device_id})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000115 var omciCC OmciCC
116 omciCC.enabled = false
117 omciCC.pOnuDeviceEntry = onu_device_entry
118 omciCC.deviceID = device_id
119 omciCC.pBaseDeviceHandler = device_handler
120 omciCC.coreProxy = core_proxy
121 omciCC.adapterProxy = adapter_proxy
122 omciCC.supportExtMsg = false
123 omciCC.txFrames = 0
124 omciCC.txOnuFrames = 0
125 omciCC.rxFrames = 0
126 omciCC.rxOnuFrames = 0
127 omciCC.rxOnuDiscards = 0
128 omciCC.tid = 0x1
129 omciCC.hpTid = 0x8000
130 omciCC.uploadSequNo = 0
131 omciCC.uploadNoOfCmds = 0
132
133 omciCC.txQueue = list.New()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000134 omciCC.rxSchedulerMap = make(map[uint16]CallbackPairEntry)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000135
136 return &omciCC
137}
138
139// Rx handler for omci messages
140func (oo *OmciCC) ReceiveOnuMessage(ctx context.Context, omciMsg *omci.OMCI) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000141 logger.Debugw("rx-onu-autonomous-message", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000142 "payload": hex.EncodeToString(omciMsg.Payload)})
143 /*
144 msgType = rxFrame.fields["message_type"] //assumed OmciOperationsValue
145 rxOnuFrames++
146
147 switch msgType {
148 case AlarmNotification:
149 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000150 logger.Info("Unhandled: received-onu-alarm-message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000151 // python code was:
152 //if msg_type == EntityOperations.AlarmNotification.value:
153 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Alarm_Notification)
154 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
155 //
156 return errors.New("RxAlarmNotification unimplemented")
157 }
158 case AttributeValueChange:
159 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000160 logger.Info("Unhandled: received-attribute-value-change")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000161 // python code was:
162 //elif msg_type == EntityOperations.AttributeValueChange.value:
163 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.AVC_Notification)
164 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
165 //
166 return errors.New("RxAttributeValueChange unimplemented")
167 }
168 case TestResult:
169 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000170 logger.Info("Unhandled: received-test-result")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000171 // python code was:
172 //elif msg_type == EntityOperations.TestResult.value:
173 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Test_Result)
174 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
175 //
176 return errors.New("RxTestResult unimplemented")
177 }
178 default:
179 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000180 logger.Errorw("rx-onu-unsupported-autonomous-message", log.Fields{"msgType": msgType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000181 rxOnuDiscards++
182 return errors.New("RxOnuMsgType unimplemented")
183 }
184 }
185 */
186 return errors.New("ReceiveOnuMessage unimplemented")
187}
188
189// Rx handler for onu messages
190// e.g. would call ReceiveOnuMessage() in case of TID=0 or Action=test ...
191func (oo *OmciCC) ReceiveMessage(ctx context.Context, rxMsg []byte) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000192 //logger.Debugw("cc-receive-omci-message", log.Fields{"RxOmciMessage-x2s": hex.EncodeToString(rxMsg)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000193 if len(rxMsg) >= 44 { // then it should normally include the BaseFormat trailer Len
194 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
195 // (am extendedFormat message could be destroyed this way!)
196 trailerLenData := rxMsg[42:44]
197 trailerLen := binary.BigEndian.Uint16(trailerLenData)
mpagenko1cc3cb42020-07-27 15:24:38 +0000198 //logger.Debugw("omci-received-trailer-len", log.Fields{"Length": trailerLen})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000199 if trailerLen != 40 { // invalid base Format entry -> autocorrect
200 binary.BigEndian.PutUint16(rxMsg[42:44], 40)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000201 logger.Debug("cc-corrected-omci-message: trailer len inserted")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000202 }
203 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000204 logger.Errorw("received omci-message to small for OmciBaseFormat - abort", log.Fields{"Length": len(rxMsg)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000205 return errors.New("RxOmciMessage to small for BaseFormat")
206 }
207
208 packet := gopacket.NewPacket(rxMsg, omci.LayerTypeOMCI, gopacket.NoCopy)
209 if packet == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000210 logger.Error("omci-message could not be decoded")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000211 return errors.New("could not decode rxMsg as OMCI")
212 }
213 omciLayer := packet.Layer(omci.LayerTypeOMCI)
214 if omciLayer == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000215 logger.Error("omci-message could not decode omci layer")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000216 return errors.New("could not decode omci layer")
217 }
218 omciMsg, ok := omciLayer.(*omci.OMCI)
219 if !ok {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000220 logger.Error("omci-message could not assign omci layer")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221 return errors.New("could not assign omci layer")
222 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000223 logger.Debugw("omci-message-decoded:", log.Fields{"omciMsgType": omciMsg.MessageType,
mpagenko3dbcdd22020-07-22 07:38:45 +0000224 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "DeviceIdent": omciMsg.DeviceIdentifier})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000225 if byte(omciMsg.MessageType) & ^me.AK == 0 {
226 // Not a response
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000227 logger.Debug("RxMsg is no Omci Response Message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000228 if omciMsg.TransactionID == 0 {
229 return oo.ReceiveOnuMessage(ctx, omciMsg)
230 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000231 logger.Errorw("Unexpected TransCorrId != 0 not accepted for autonomous messages",
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000232 log.Fields{"msgType": omciMsg.MessageType, "payload": hex.EncodeToString(omciMsg.Payload)})
233 return errors.New("Autonomous Omci Message with TranSCorrId != 0 not acccepted")
234 }
235 } else {
mpagenko1cc3cb42020-07-27 15:24:38 +0000236 //logger.Debug("RxMsg is a Omci Response Message: try to schedule it to the requester")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000237 oo.mutexRxSchedMap.Lock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000238 rxCallbackEntry, ok := oo.rxSchedulerMap[omciMsg.TransactionID]
239 if ok && rxCallbackEntry.cbFunction != nil {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000240 //disadvantage of decoupling: error verification made difficult, but anyway the question is
241 // how to react on erroneous frame reception, maybe can simply be ignored
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000242 go rxCallbackEntry.cbFunction(omciMsg, &packet, rxCallbackEntry.cbRespChannel)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000243 // having posted the response the request is regarded as 'done'
244 delete(oo.rxSchedulerMap, omciMsg.TransactionID)
245 oo.mutexRxSchedMap.Unlock()
246 } else {
247 oo.mutexRxSchedMap.Unlock()
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000248 logger.Error("omci-message-response for not registered transCorrId")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000249 return errors.New("could not find registered response handler tor transCorrId")
250 }
251 }
252
253 return nil
254 /* py code was:
255 Receive and OMCI message from the proxy channel to the OLT.
256
257 Call this from your ONU Adapter on a new OMCI Rx on the proxy channel
258 :param msg: (str) OMCI binary message (used as input to Scapy packet decoder)
259 """
260 if not self.enabled:
261 return
262
263 try:
264 now = arrow.utcnow()
265 d = None
266
267 # NOTE: Since we may need to do an independent ME map on a per-ONU basis
268 # save the current value of the entity_id_to_class_map, then
269 # replace it with our custom one before decode, and then finally
270 # restore it later. Tried other ways but really made the code messy.
271 saved_me_map = omci_entities.entity_id_to_class_map
272 omci_entities.entity_id_to_class_map = self._me_map
273
274 try:
275 rx_frame = msg if isinstance(msg, OmciFrame) else OmciFrame(msg)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000276 self.logger.debug('recv-omci-msg', omci_msg=hexlify(msg))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000277 except KeyError as e:
278 # Unknown, Unsupported, or vendor-specific ME. Key is the unknown classID
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000279 self.logger.debug('frame-decode-key-error', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000280 rx_frame = self._decode_unknown_me(msg)
281 self._rx_unknown_me += 1
282
283 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000284 self.logger.exception('frame-decode', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000285 return
286
287 finally:
288 omci_entities.entity_id_to_class_map = saved_me_map # Always restore it.
289
290 rx_tid = rx_frame.fields['transaction_id']
291 msg_type = rx_frame.fields['message_type']
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000292 self.logger.debug('Received message for rx_tid', rx_tid = rx_tid, msg_type = msg_type)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000293 # Filter the Test Result frame and route through receive onu
294 # message method.
295 if rx_tid == 0 or msg_type == EntityOperations.TestResult.value:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000296 self.logger.debug('Receive ONU message', rx_tid=0)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000297 return self._receive_onu_message(rx_frame)
298
299 # Previously unreachable if this is the very first round-trip Rx or we
300 # have been running consecutive errors
301 if self._rx_frames == 0 or self._consecutive_errors != 0:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000302 self.logger.debug('Consecutive errors for rx', err = self._consecutive_errors)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000303 self.reactor.callLater(0, self._publish_connectivity_event, True)
304
305 self._rx_frames += 1
306 self._consecutive_errors = 0
307
308 try:
309 high_priority = self._tid_is_high_priority(rx_tid)
310 index = self._get_priority_index(high_priority)
311
312 # (timestamp, defer, frame, timeout, retry, delayedCall)
313 last_tx_tuple = self._tx_request[index]
314
315 if last_tx_tuple is None or \
316 last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id') != rx_tid:
317 # Possible late Rx on a message that timed-out
318 if last_tx_tuple:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000319 self.logger.debug('Unknown message', rx_tid=rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000320 tx_id=last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id'))
321 self._rx_unknown_tid += 1
322 self._rx_late += 1
323 return
324
325 ts, d, tx_frame, timeout, retry, dc = last_tx_tuple
326 if dc is not None and not dc.cancelled and not dc.called:
327 dc.cancel()
328
329 _secs = self._update_rx_tx_stats(now, ts)
330
331 # Late arrival already serviced by a timeout?
332 if d.called:
333 self._rx_late += 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000334 self.logger.debug('Serviced by timeout. Late arrival', rx_late = self._rx_late)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000335 return
336
337 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000338 self.logger.exception('frame-match', msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000339 if d is not None:
340 return d.errback(failure.Failure(e))
341 return
342
343 # Publish Rx event to listeners in a different task
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000344 self.logger.debug('Publish rx event', rx_tid = rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000345 tx_tid = tx_frame.fields['transaction_id'])
346 reactor.callLater(0, self._publish_rx_frame, tx_frame, rx_frame)
347
348 # begin success callback chain (will cancel timeout and queue next Tx message)
349 self._rx_response[index] = rx_frame
350 d.callback(rx_frame)
351
352 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000353 self.logger.exception('rx-msg', e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000354 */
355}
356
357func (oo *OmciCC) PublishRxResponseFrame(ctx context.Context, txFrame []byte, rxFrame []byte) error {
358 return errors.New("PublishRxResponseFrame unimplemented")
359 /*
360 def _publish_rx_frame(self, tx_frame, rx_frame):
361 */
362}
363
364//Queue the OMCI Frame for a transmit to the ONU via the proxy_channel
365func (oo *OmciCC) Send(ctx context.Context, txFrame []byte, timeout int, retry int, highPrio bool,
366 receiveCallbackPair CallbackPair) error {
367
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000368 logger.Debugw("register-response-callback:", log.Fields{"for TansCorrId": receiveCallbackPair.cbKey})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000369 // it could be checked, if the callback keay is already registered - but simply overwrite may be acceptable ...
370 oo.mutexRxSchedMap.Lock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000371 oo.rxSchedulerMap[receiveCallbackPair.cbKey] = receiveCallbackPair.cbEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000372 oo.mutexRxSchedMap.Unlock()
373
374 //just use a simple list for starting - might need some more effort, especially for multi source write access
375 omciTxRequest := omciTransferStructure{
376 txFrame,
377 timeout,
378 retry,
379 highPrio,
380 }
381 oo.mutexTxQueue.Lock()
382 oo.txQueue.PushBack(omciTxRequest) // enqueue
383 oo.mutexTxQueue.Unlock()
384
385 // for first test just bypass and send directly:
386 go oo.sendNextRequest(ctx)
387 return nil
388}
389
390//Pull next tx request and send it
391func (oo *OmciCC) sendNextRequest(ctx context.Context) error {
392 // return errors.New("sendNextRequest unimplemented")
393
394 // just try to get something transferred !!
395 // avoid accessing the txQueue from parallel send requests
396 // block parallel omci send requests at least until SendIAP is 'committed'
397 // that should be feasible for an onu instance as on OMCI anyway window size 1 is assumed
398 oo.mutexTxQueue.Lock()
mpagenkodff5dda2020-08-28 11:52:01 +0000399 defer oo.mutexTxQueue.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000400 for oo.txQueue.Len() > 0 {
401 queueElement := oo.txQueue.Front() // First element
402 omciTxRequest := queueElement.Value.(omciTransferStructure)
403 /* compare olt device handler code:
404 func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000405 logger.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000406 var deviceType string
407 var deviceID string
408 var proxyDeviceID string
409
410 onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
411
412 if onuInCache, ok := dh.onus.Load(onuKey); !ok {
413
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000414 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 +0000415 ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
416 kwargs := make(map[string]interface{})
417 kwargs["onu_id"] = omciInd.OnuId
418 kwargs["parent_port_no"] = ponPort
419
420 onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
421 if err != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000422 logger.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId, "error": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000423 return
424 }
425 deviceType = onuDevice.Type
426 deviceID = onuDevice.Id
427 proxyDeviceID = onuDevice.ProxyAddress.DeviceId
428 //if not exist in cache, then add to cache.
429 dh.onus.Store(onuKey, NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID))
430 } else {
431 //found in cache
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000432 logger.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000433 deviceType = onuInCache.(*OnuDevice).deviceType
434 deviceID = onuInCache.(*OnuDevice).deviceID
435 proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID
436 }
437 */
438 /* and compare onu_adapter py code:
439 omci_msg = InterAdapterOmciMessage(
440 message=bytes(frame),
441 proxy_address=self._proxy_address,
442 connect_status=self._device.connect_status)
443
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000444 self.logger.debug('sent-omci-msg', tid=tx_tid, omci_msg=hexlify(bytes(frame)))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000445
446 yield self._adapter_proxy.send_inter_adapter_message(
447 msg=omci_msg,
448 type=InterAdapterMessageType.OMCI_REQUEST,
449 from_adapter=self._device.type,
450 to_adapter=self._proxy_address.device_type,
451 to_device_id=self._device_id,
452 proxy_device_id=self._proxy_address.device_id
453 )
454 */
455 device, err := oo.coreProxy.GetDevice(ctx,
456 oo.pBaseDeviceHandler.deviceID, oo.deviceID) //parent, child
457 if err != nil || device == nil {
458 /*TODO: needs to handle error scenarios */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000459 logger.Errorw("Failed to fetch device", log.Fields{"err": err, "ParentId": oo.pBaseDeviceHandler.deviceID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000460 "ChildId": oo.deviceID})
461 return errors.New("failed to fetch device")
462 }
463
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000464 logger.Debugw("omci-message-sending", log.Fields{"fromDeviceType": oo.pBaseDeviceHandler.DeviceType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000465 "toDeviceType": oo.pBaseDeviceHandler.ProxyAddressType,
466 "onuDeviceID": oo.deviceID, "proxyDeviceID": oo.pBaseDeviceHandler.ProxyAddressID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000467 logger.Debugw("omci-message-to-send:",
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000468 log.Fields{"TxOmciMessage": hex.EncodeToString(omciTxRequest.txFrame)})
469
470 omciMsg := &ic.InterAdapterOmciMessage{Message: omciTxRequest.txFrame}
471 if sendErr := oo.adapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
472 ic.InterAdapterMessageType_OMCI_REQUEST,
473 //fromType,toType,toDevId, ProxyDevId
474 oo.pBaseDeviceHandler.DeviceType, oo.pBaseDeviceHandler.ProxyAddressType,
475 oo.deviceID, oo.pBaseDeviceHandler.ProxyAddressID, ""); sendErr != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000476 logger.Errorw("send omci request error", log.Fields{"error": sendErr})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000477 return sendErr
478 }
479 oo.txQueue.Remove(queueElement) // Dequeue
480 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000481 return nil
482}
483
484func (oo *OmciCC) GetNextTid(highPriority bool) uint16 {
485 var next uint16
486 if highPriority {
487 oo.mutexTid.Lock()
488 next = oo.hpTid
489 oo.hpTid += 1
490 if oo.hpTid < 0x8000 {
491 oo.hpTid = 0x8000
492 }
493 oo.mutexTid.Unlock()
494 } else {
495 oo.mutexHpTid.Lock()
496 next = oo.tid
497 oo.tid += 1
498 if oo.tid >= 0x8000 {
499 oo.tid = 1
500 }
501 oo.mutexHpTid.Unlock()
502 }
503 return next
504}
505
506// ###################################################################################
507// # utility methods provided to work on OMCI messages
508func serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
509 omciLayer := &omci.OMCI{
510 TransactionID: tid,
511 MessageType: msgType,
512 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000513 return serializeOmciLayer(omciLayer, request)
514}
515
516func serializeOmciLayer(a_omciLayer *omci.OMCI, a_request gopacket.SerializableLayer) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000517 var options gopacket.SerializeOptions
518 options.FixLengths = true
519
520 buffer := gopacket.NewSerializeBuffer()
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000521 err := gopacket.SerializeLayers(buffer, options, a_omciLayer, a_request)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000522 if err != nil {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000523 logger.Errorw("Could not create goPacket Omci serial buffer", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000524 return nil, err
525 }
526 return buffer.Bytes(), nil
527}
528
529func hexEncode(omciPkt []byte) ([]byte, error) {
530 dst := make([]byte, hex.EncodedLen(len(omciPkt)))
531 hex.Encode(dst, omciPkt)
532 return dst, nil
533}
534
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000535//supply a response handler for omci response messages to be transferred to the requested FSM
536func (oo *OmciCC) receiveOmciResponse(omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000537
mpagenko3dbcdd22020-07-22 07:38:45 +0000538 logger.Debugw("omci-message-response - transfer on omciRespChannel", log.Fields{"omciMsgType": omciMsg.MessageType,
divyadesai4d299552020-08-18 07:13:49 +0000539 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000540
541 if oo.pOnuDeviceEntry == nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000542 logger.Errorw("Abort receiving OMCI response, DeviceEntryPointer is nil", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000543 "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000544 return errors.New("DeviceEntryPointer is nil")
545 }
546
547 // no further test on SeqNo is done here, assignment from rxScheduler is trusted
548 // MibSync responses are simply transferred via deviceEntry to MibSync, no specific analysis here
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000549 omciRespMsg := Message{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000550 Type: OMCI,
551 Data: OmciMessage{
552 OmciMsg: omciMsg,
553 OmciPacket: packet,
554 },
555 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000556 //logger.Debugw("Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000557 respChan <- omciRespMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000558
559 return nil
560}
561
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000562func (oo *OmciCC) sendMibReset(ctx context.Context, timeout int, highPrio bool) error {
563
divyadesai4d299552020-08-18 07:13:49 +0000564 logger.Debugw("send MibReset-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000565 request := &omci.MibResetRequest{
566 MeBasePacket: omci.MeBasePacket{
567 EntityClass: me.OnuDataClassID,
568 },
569 }
570 tid := oo.GetNextTid(highPrio)
571 pkt, err := serialize(omci.MibResetRequestType, request, tid)
572 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000573 logger.Errorw("Cannot serialize MibResetRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000574 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000575 return err
576 }
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000577 omciRxCallbackPair := CallbackPair{
578 cbKey: tid,
579 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
580 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000581 return oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
582}
583
ozgecanetsiae11479f2020-07-06 09:44:47 +0300584func (oo *OmciCC) sendReboot(ctx context.Context, timeout int, highPrio bool, responseChannel chan Message) error {
divyadesai4d299552020-08-18 07:13:49 +0000585 logger.Debugw("send Reboot-msg to:", log.Fields{"device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300586 request := &omci.RebootRequest{
587 MeBasePacket: omci.MeBasePacket{
588 EntityClass: me.OnuGClassID,
589 },
590 }
591 tid := oo.GetNextTid(highPrio)
592 pkt, err := serialize(omci.RebootRequestType, request, tid)
593 if err != nil {
594 logger.Errorw("Cannot serialize RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000595 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300596 return err
597 }
598 omciRxCallbackPair := CallbackPair{
599 cbKey: tid,
600 cbEntry: CallbackPairEntry{oo.pOnuDeviceEntry.omciRebootMessageReceivedChannel, oo.receiveOmciResponse},
601 }
602
603 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
604 if err != nil {
605 logger.Errorw("Cannot send RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000606 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300607 return err
608 }
609 err = oo.pOnuDeviceEntry.waitForRebootResponse(responseChannel)
610 if err != nil {
611 logger.Error("aborting ONU Reboot!")
612 oo.pOnuDeviceEntry.pMibDownloadFsm.pFsm.Event("reset")
613 return err
614 }
615 return nil
616}
617
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000618func (oo *OmciCC) sendMibUpload(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000619 logger.Debugw("send MibUpload-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000620 request := &omci.MibUploadRequest{
621 MeBasePacket: omci.MeBasePacket{
622 EntityClass: me.OnuDataClassID,
623 },
624 }
625 tid := oo.GetNextTid(highPrio)
626 pkt, err := serialize(omci.MibUploadRequestType, request, tid)
627 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000628 logger.Errorw("Cannot serialize MibUploadRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000629 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000630 return err
631 }
632 oo.uploadSequNo = 0
633 oo.uploadNoOfCmds = 0
634
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000635 omciRxCallbackPair := CallbackPair{
636 cbKey: tid,
637 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
638 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000639 return oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
640}
641
642func (oo *OmciCC) sendMibUploadNext(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000643 logger.Debugw("send MibUploadNext-msg to:", log.Fields{"device-id": oo.deviceID, "uploadSequNo": oo.uploadSequNo})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000644 request := &omci.MibUploadNextRequest{
645 MeBasePacket: omci.MeBasePacket{
646 EntityClass: me.OnuDataClassID,
647 },
648 CommandSequenceNumber: oo.uploadSequNo,
649 }
650 tid := oo.GetNextTid(highPrio)
651 pkt, err := serialize(omci.MibUploadNextRequestType, request, tid)
652 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000653 logger.Errorw("Cannot serialize MibUploadNextRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000654 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000655 return err
656 }
657 oo.uploadSequNo++
658
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000659 omciRxCallbackPair := CallbackPair{
660 cbKey: tid,
661 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
662 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000663 return oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
664}
665
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000666func (oo *OmciCC) sendCreateGalEthernetProfile(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
667 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000668 logger.Debugw("send GalEnetProfile-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000669 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000670
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000671 meParams := me.ParamData{
672 EntityID: galEthernetEID,
673 Attributes: me.AttributeValueMap{"MaximumGemPayloadSize": maxGemPayloadSize},
674 }
675 meInstance, omciErr := me.NewGalEthernetProfile(meParams)
676 if omciErr.GetError() == nil {
677 //all setByCreate parameters already set, no default option required ...
678 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
679 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000680 logger.Errorw("Cannot encode GalEnetProfileInstance for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000681 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000682 return nil
683 }
684
685 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
686 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000687 logger.Errorw("Cannot serialize GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000688 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000689 return nil
690 }
691
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000692 omciRxCallbackPair := CallbackPair{
693 cbKey: tid,
694 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
695 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000696 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
697 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000698 logger.Errorw("Cannot send GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000699 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000700 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000701 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000702 logger.Debug("send GalEnetProfile-Create-msg done")
703 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000704 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000705 logger.Errorw("Cannot generate GalEnetProfileInstance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000706 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000707 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000708}
709
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000710// might be needed to extend for parameter arguments, here just for setting the ConnectivityMode!!
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000711func (oo *OmciCC) sendSetOnu2g(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
712 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000713 logger.Debugw("send ONU2-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000714 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000715
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000716 // ONU-G ME-ID is defined to be 0, but we could verify, if the ONU really supports the desired
717 // connectivity mode 5 (in ConnCap)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000718 // By now we just use fix values to fire - this is anyway what the python adapter does
719 // read ONU-2G from DB ???? //TODO!!!
720 meParams := me.ParamData{
721 EntityID: 0,
722 Attributes: me.AttributeValueMap{"CurrentConnectivityMode": connectivityModeValue},
723 }
724 meInstance, omciErr := me.NewOnu2G(meParams)
725 if omciErr.GetError() == nil {
726 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
727 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000728 logger.Errorw("Cannot encode ONU2-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000729 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000730 return nil
731 }
732
733 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
734 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000735 logger.Errorw("Cannot serialize ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000736 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000737 return nil
738 }
739
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000740 omciRxCallbackPair := CallbackPair{
741 cbKey: tid,
742 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
743 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000744 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
745 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000746 logger.Errorw("Cannot send ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000747 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000748 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000749 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000750 logger.Debug("send ONU2-G-Set-msg done")
751 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000752 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000753 logger.Errorw("Cannot generate ONU2-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000754 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000755 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000756}
757
758func (oo *OmciCC) sendCreateMBServiceProfile(ctx context.Context,
759 a_pUniPort *OnuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
760 tid := oo.GetNextTid(highPrio)
761 instID := macBridgeServiceProfileEID + uint16(a_pUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000762 logger.Debugw("send MBSP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000763 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000764
765 meParams := me.ParamData{
766 EntityID: instID,
767 Attributes: me.AttributeValueMap{
768 "Priority": 0x8000,
769 "MaxAge": 20 * 256, //20s
770 "HelloTime": 2 * 256, //2s
771 "ForwardDelay": 15 * 256, //15s
772 //note: DynamicFilteringAgeingTime is taken from omci lib default as
773 // which is obviously different from default value used in python lib,
774 // where the value seems to be 0 (ONU defined) - to be considered in case of test artifacts ...
775 },
776 }
777
778 meInstance, omciErr := me.NewMacBridgeServiceProfile(meParams)
779 if omciErr.GetError() == nil {
780 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
781 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
782 omci.TransactionID(tid), omci.AddDefaults(true))
783 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000784 logger.Errorw("Cannot encode MBSP for create", 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
787 }
788
789 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
790 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000791 logger.Errorw("Cannot serialize MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000792 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000793 return nil
794 }
795
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000796 omciRxCallbackPair := CallbackPair{
797 cbKey: tid,
798 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
799 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000800 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
801 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000802 logger.Errorw("Cannot send MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000803 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000804 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000805 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000806 logger.Debug("send MBSP-Create-msg done")
807 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000808 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000809 logger.Errorw("Cannot generate MBSP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000810 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000811 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000812}
813
814func (oo *OmciCC) sendCreateMBPConfigData(ctx context.Context,
815 a_pUniPort *OnuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
816 tid := oo.GetNextTid(highPrio)
817 instID := macBridgePortAniEID + a_pUniPort.entityId
divyadesai4d299552020-08-18 07:13:49 +0000818 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000819 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000820
821 meParams := me.ParamData{
822 EntityID: instID,
823 Attributes: me.AttributeValueMap{
824 "BridgeIdPointer": macBridgeServiceProfileEID + uint16(a_pUniPort.macBpNo),
825 "PortNum": a_pUniPort.macBpNo,
826 "TpType": uint8(a_pUniPort.portType),
827 "TpPointer": a_pUniPort.entityId,
828 },
829 }
830 meInstance, omciErr := me.NewMacBridgePortConfigurationData(meParams)
831 if omciErr.GetError() == nil {
832 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
833 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
834 omci.TransactionID(tid), omci.AddDefaults(true))
835 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000836 logger.Errorw("Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000837 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000838 return nil
839 }
840
841 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
842 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000843 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000844 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000845 return nil
846 }
847
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000848 omciRxCallbackPair := CallbackPair{
849 cbKey: tid,
850 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
851 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000852 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
853 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000854 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000855 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000856 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000857 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000858 logger.Debug("send MBPCD-Create-msg done")
859 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000860 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000861 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000862 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000863 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000864}
865
866func (oo *OmciCC) sendCreateEVTOConfigData(ctx context.Context,
867 a_pUniPort *OnuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
868 tid := oo.GetNextTid(highPrio)
869 //same entityId is used as for MBSP (see there), but just arbitrary ...
870 instID := macBridgeServiceProfileEID + uint16(a_pUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000871 logger.Debugw("send EVTOCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000872 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000873
874 // compare python adapter code WA VOL-1311: this is not done here!
875 // (setting TPID values for the create would probably anyway be ignored by the omci lib)
876 // but perhaps we have to be aware of possible problems at get(Next) Request handling for EVTOOCD tables later ...
877 assType := uint8(2) // default AssociationType is PPTPEthUni
878 if a_pUniPort.portType == UniVEIP {
879 assType = uint8(10) // for VEIP
880 }
881 meParams := me.ParamData{
882 EntityID: instID,
883 Attributes: me.AttributeValueMap{
884 "AssociationType": assType,
885 "AssociatedMePointer": a_pUniPort.entityId,
886 },
887 }
888 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(meParams)
889 if omciErr.GetError() == nil {
890 //all setByCreate parameters already set, no default option required ...
891 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
892 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000893 logger.Errorw("Cannot encode EVTOCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000894 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000895 return nil
896 }
897
898 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
899 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000900 logger.Errorw("Cannot serialize EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000901 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000902 return nil
903 }
904
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000905 omciRxCallbackPair := CallbackPair{
906 cbKey: tid,
907 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
908 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000909 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
910 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000911 logger.Errorw("Cannot send EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000912 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000913 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000914 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000915 logger.Debug("send EVTOCD-Create-msg done")
916 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000917 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000918 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000919 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000920 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000921}
922
923func (oo *OmciCC) sendSetOnuGLS(ctx context.Context, timeout int,
924 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
925 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000926 logger.Debugw("send ONU-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000927 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000928
929 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
930 meParams := me.ParamData{
931 EntityID: 0,
932 Attributes: requestedAttributes,
933 }
934 meInstance, omciErr := me.NewOnuG(meParams)
935 if omciErr.GetError() == nil {
936 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
937 if err != nil {
938 logger.Errorw("Cannot encode ONU-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000939 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000940 return nil
941 }
942
943 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
944 if err != nil {
945 logger.Errorw("Cannot serialize ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000946 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000947 return nil
948 }
949
950 omciRxCallbackPair := CallbackPair{
951 cbKey: tid,
952 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
953 }
954 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
955 if err != nil {
956 logger.Errorw("Cannot send ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000957 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000958 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000959 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000960 logger.Debug("send ONU-G-Set-msg done")
961 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000962 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000963 logger.Errorw("Cannot generate ONU-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000964 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000965 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000966}
967
968func (oo *OmciCC) sendSetUniGLS(ctx context.Context, aInstNo uint16, timeout int,
969 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
970 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000971 logger.Debugw("send UNI-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000972 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000973
974 // UNI-G ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
975 meParams := me.ParamData{
976 EntityID: aInstNo,
977 Attributes: requestedAttributes,
978 }
979 meInstance, omciErr := me.NewUniG(meParams)
980 if omciErr.GetError() == nil {
981 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
982 if err != nil {
983 logger.Errorw("Cannot encode UNI-G instance for 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
988 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
989 if err != nil {
990 logger.Errorw("Cannot serialize UNI-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000991 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000992 return nil
993 }
994
995 omciRxCallbackPair := CallbackPair{
996 cbKey: tid,
997 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
998 }
999 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1000 if err != nil {
1001 logger.Errorw("Cannot send UNIG-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001002 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001003 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001004 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001005 logger.Debug("send UNI-G-Set-msg done")
1006 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001007 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001008 logger.Errorw("Cannot generate UNI-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001009 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001010 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001011}
1012
1013func (oo *OmciCC) sendSetVeipLS(ctx context.Context, aInstNo uint16, timeout int,
1014 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
1015 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001016 logger.Debugw("send VEIP-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001017 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001018
1019 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1020 meParams := me.ParamData{
1021 EntityID: aInstNo,
1022 Attributes: requestedAttributes,
1023 }
1024 meInstance, omciErr := me.NewVirtualEthernetInterfacePoint(meParams)
1025 if omciErr.GetError() == nil {
1026 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1027 if err != nil {
1028 logger.Errorw("Cannot encode VEIP instance for 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
1033 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1034 if err != nil {
1035 logger.Errorw("Cannot serialize VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001036 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001037 return nil
1038 }
1039
1040 omciRxCallbackPair := CallbackPair{
1041 cbKey: tid,
1042 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1043 }
1044 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1045 if err != nil {
1046 logger.Errorw("Cannot send VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001047 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001048 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001049 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001050 logger.Debug("send VEIP-Set-msg done")
1051 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001052 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001053 logger.Errorw("Cannot generate VEIP", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001054 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001055 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001056}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001057
1058func (oo *OmciCC) sendGetMe(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributes me.AttributeValueMap,
1059 timeout int, highPrio bool) *me.ManagedEntity {
1060
1061 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001062 logger.Debugw("send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001063 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001064
1065 meParams := me.ParamData{
1066 EntityID: entityID,
1067 Attributes: requestedAttributes,
1068 }
1069 meInstance, omciErr := me.LoadManagedEntityDefinition(classID, meParams)
1070 if omciErr.GetError() == nil {
1071 meClassIdName := meInstance.GetName()
1072 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.GetRequestType, omci.TransactionID(tid))
1073 if err != nil {
divyadesai4d299552020-08-18 07:13:49 +00001074 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 +00001075 return nil
1076 }
1077 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1078 if err != nil {
divyadesai4d299552020-08-18 07:13:49 +00001079 logger.Errorw("Cannot serialize get-request", log.Fields{"meClassIdName": meClassIdName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001080 return nil
1081 }
1082 omciRxCallbackPair := CallbackPair{
1083 cbKey: tid,
1084 cbEntry: CallbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
1085 }
1086 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1087 if err != nil {
divyadesai4d299552020-08-18 07:13:49 +00001088 logger.Errorw("Cannot send get-request-msg", log.Fields{"meClassIdName": meClassIdName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001089 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001090 }
divyadesai4d299552020-08-18 07:13:49 +00001091 logger.Debugw("send get-request-msg done", log.Fields{"meClassIdName": meClassIdName, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001092 return meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001093 }
divyadesai4d299552020-08-18 07:13:49 +00001094 logger.Errorw("Cannot generate meDefinition", log.Fields{"classID": classID, "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001095 return nil
1096}
1097
1098func (oo *OmciCC) sendCreateDot1PMapper(ctx context.Context, timeout int, highPrio bool,
1099 aInstID uint16, rxChan chan Message) *me.ManagedEntity {
1100 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001101 logger.Debugw("send .1pMapper-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001102 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
1103
1104 meParams := me.ParamData{
1105 EntityID: aInstID,
1106 Attributes: me.AttributeValueMap{},
1107 }
1108 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
1109 if omciErr.GetError() == nil {
1110 //we have to set all 'untouched' parameters to default by some additional option parameter!!
1111 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1112 omci.TransactionID(tid), omci.AddDefaults(true))
1113 if err != nil {
1114 logger.Errorw("Cannot encode .1pMapper for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001115 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001116 return nil
1117 }
1118
1119 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1120 if err != nil {
1121 logger.Errorw("Cannot serialize .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001122 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001123 return nil
1124 }
1125
1126 omciRxCallbackPair := CallbackPair{
1127 cbKey: tid,
1128 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1129 }
1130 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1131 if err != nil {
1132 logger.Errorw("Cannot send .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001133 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001134 return nil
1135 }
1136 logger.Debug("send .1pMapper-create-msg done")
1137 return meInstance
1138 }
1139 logger.Errorw("Cannot generate .1pMapper", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001140 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001141 return nil
1142}
1143
1144func (oo *OmciCC) sendCreateMBPConfigDataVar(ctx context.Context, timeout int, highPrio bool,
1145 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1146 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001147 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001148 "SequNo": strconv.FormatInt(int64(tid), 16),
1149 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1150
1151 meInstance, omciErr := me.NewMacBridgePortConfigurationData(params[0])
1152 if omciErr.GetError() == nil {
1153 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1154 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1155 omci.TransactionID(tid), omci.AddDefaults(true))
1156 if err != nil {
1157 logger.Errorw("Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001158 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001159 return nil
1160 }
1161
1162 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1163 if err != nil {
1164 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001165 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001166 return nil
1167 }
1168
1169 omciRxCallbackPair := CallbackPair{
1170 cbKey: tid,
1171 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1172 }
1173 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1174 if err != nil {
1175 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001176 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001177 return nil
1178 }
1179 logger.Debug("send MBPCD-Create-msg done")
1180 return meInstance
1181 }
1182 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001183 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001184 return nil
1185}
1186
1187func (oo *OmciCC) sendCreateGemNCTPVar(ctx context.Context, timeout int, highPrio bool,
1188 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1189 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001190 logger.Debugw("send GemNCTP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001191 "SequNo": strconv.FormatInt(int64(tid), 16),
1192 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1193
1194 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1195 if omciErr.GetError() == nil {
1196 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1197 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1198 omci.TransactionID(tid), omci.AddDefaults(true))
1199 if err != nil {
1200 logger.Errorw("Cannot encode GemNCTP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001201 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001202 return nil
1203 }
1204
1205 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1206 if err != nil {
1207 logger.Errorw("Cannot serialize GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001208 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001209 return nil
1210 }
1211
1212 omciRxCallbackPair := CallbackPair{
1213 cbKey: tid,
1214 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1215 }
1216 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1217 if err != nil {
1218 logger.Errorw("Cannot send GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001219 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001220 return nil
1221 }
1222 logger.Debug("send GemNCTP-Create-msg done")
1223 return meInstance
1224 }
1225 logger.Errorw("Cannot generate GemNCTP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001226 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001227 return nil
1228}
1229
1230func (oo *OmciCC) sendCreateGemIWTPVar(ctx context.Context, timeout int, highPrio bool,
1231 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1232 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001233 logger.Debugw("send GemIwTp-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001234 "SequNo": strconv.FormatInt(int64(tid), 16),
1235 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1236
1237 meInstance, omciErr := me.NewGemInterworkingTerminationPoint(params[0])
1238 if omciErr.GetError() == nil {
1239 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1240 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1241 omci.TransactionID(tid))
1242 if err != nil {
1243 logger.Errorw("Cannot encode GemIwTp for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001244 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001245 return nil
1246 }
1247
1248 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1249 if err != nil {
1250 logger.Errorw("Cannot serialize GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001251 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001252 return nil
1253 }
1254
1255 omciRxCallbackPair := CallbackPair{
1256 cbKey: tid,
1257 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1258 }
1259 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1260 if err != nil {
1261 logger.Errorw("Cannot send GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001262 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001263 return nil
1264 }
1265 logger.Debug("send GemIwTp-Create-msg done")
1266 return meInstance
1267 }
1268 logger.Errorw("Cannot generate GemIwTp Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001269 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001270 return nil
1271}
1272
1273func (oo *OmciCC) sendSetTcontVar(ctx context.Context, timeout int, highPrio bool,
1274 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1275 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001276 logger.Debugw("send TCont-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001277 "SequNo": strconv.FormatInt(int64(tid), 16),
1278 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1279
1280 meInstance, omciErr := me.NewTCont(params[0])
1281 if omciErr.GetError() == nil {
1282 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1283 if err != nil {
1284 logger.Errorw("Cannot encode TCont for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001285 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001286 return nil
1287 }
1288
1289 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1290 if err != nil {
1291 logger.Errorw("Cannot serialize TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001292 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001293 return nil
1294 }
1295
1296 omciRxCallbackPair := CallbackPair{
1297 cbKey: tid,
1298 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1299 }
1300 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1301 if err != nil {
1302 logger.Errorw("Cannot send TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001303 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001304 return nil
1305 }
1306 logger.Debug("send TCont-set msg done")
1307 return meInstance
1308 }
1309 logger.Errorw("Cannot generate TCont Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001310 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001311 return nil
1312}
1313
1314func (oo *OmciCC) sendSetPrioQueueVar(ctx context.Context, timeout int, highPrio bool,
1315 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1316 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001317 logger.Debugw("send PrioQueue-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001318 "SequNo": strconv.FormatInt(int64(tid), 16),
1319 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1320
1321 meInstance, omciErr := me.NewPriorityQueue(params[0])
1322 if omciErr.GetError() == nil {
1323 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1324 if err != nil {
1325 logger.Errorw("Cannot encode PrioQueue for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001326 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001327 return nil
1328 }
1329
1330 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1331 if err != nil {
1332 logger.Errorw("Cannot serialize PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001333 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001334 return nil
1335 }
1336
1337 omciRxCallbackPair := CallbackPair{
1338 cbKey: tid,
1339 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1340 }
1341 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1342 if err != nil {
1343 logger.Errorw("Cannot send PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001344 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001345 return nil
1346 }
1347 logger.Debug("send PrioQueue-set msg done")
1348 return meInstance
1349 }
1350 logger.Errorw("Cannot generate PrioQueue Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001351 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001352 return nil
1353}
1354
1355func (oo *OmciCC) sendSetDot1PMapperVar(ctx context.Context, timeout int, highPrio bool,
1356 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1357 tid := oo.GetNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001358 logger.Debugw("send 1PMapper-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001359 "SequNo": strconv.FormatInt(int64(tid), 16),
1360 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1361
1362 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(params[0])
1363 if omciErr.GetError() == nil {
1364 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1365 if err != nil {
1366 logger.Errorw("Cannot encode 1PMapper for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001367 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001368 return nil
1369 }
1370
1371 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1372 if err != nil {
1373 logger.Errorw("Cannot serialize 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001374 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001375 return nil
1376 }
1377
1378 omciRxCallbackPair := CallbackPair{
1379 cbKey: tid,
1380 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1381 }
1382 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1383 if err != nil {
1384 logger.Errorw("Cannot send 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001385 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001386 return nil
1387 }
1388 logger.Debug("send 1PMapper-set msg done")
1389 return meInstance
1390 }
1391 logger.Errorw("Cannot generate 1PMapper Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001392 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001393 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001394}
mpagenkodff5dda2020-08-28 11:52:01 +00001395
1396func (oo *OmciCC) sendCreateVtfdVar(ctx context.Context, timeout int, highPrio bool,
1397 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1398 tid := oo.GetNextTid(highPrio)
1399 logger.Debugw("send VTFD-Create-msg:", log.Fields{"device-id": oo.deviceID,
1400 "SequNo": strconv.FormatInt(int64(tid), 16),
1401 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1402
1403 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1404 if omciErr.GetError() == nil {
1405 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1406 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1407 omci.TransactionID(tid))
1408 if err != nil {
1409 logger.Errorw("Cannot encode VTFD for create", log.Fields{
1410 "Err": err, "device-id": oo.deviceID})
1411 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1412 // return (dual format) error code that can be used at caller for immediate error treatment
1413 // (relevant to all used sendXX() methods and their error conditions)
1414 return nil
1415 }
1416
1417 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1418 if err != nil {
1419 logger.Errorw("Cannot serialize VTFD create", log.Fields{
1420 "Err": err, "device-id": oo.deviceID})
1421 return nil
1422 }
1423
1424 omciRxCallbackPair := CallbackPair{
1425 cbKey: tid,
1426 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1427 }
1428 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1429 if err != nil {
1430 logger.Errorw("Cannot send VTFD create", log.Fields{
1431 "Err": err, "device-id": oo.deviceID})
1432 return nil
1433 }
1434 logger.Debug("send VTFD-Create-msg done")
1435 return meInstance
1436 }
1437 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1438 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1439 return nil
1440}
1441
1442func (oo *OmciCC) sendSetEvtocdVar(ctx context.Context, timeout int, highPrio bool,
1443 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1444 tid := oo.GetNextTid(highPrio)
1445 logger.Debugw("send EVTOCD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1446 "SequNo": strconv.FormatInt(int64(tid), 16),
1447 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1448
1449 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(params[0])
1450 if omciErr.GetError() == nil {
1451 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1452 if err != nil {
1453 logger.Errorw("Cannot encode EVTOCD for set", log.Fields{
1454 "Err": err, "device-id": oo.deviceID})
1455 return nil
1456 }
1457
1458 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1459 if err != nil {
1460 logger.Errorw("Cannot serialize EVTOCD set", log.Fields{
1461 "Err": err, "device-id": oo.deviceID})
1462 return nil
1463 }
1464
1465 omciRxCallbackPair := CallbackPair{
1466 cbKey: tid,
1467 cbEntry: CallbackPairEntry{rxChan, oo.receiveOmciResponse},
1468 }
1469 err = oo.Send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1470 if err != nil {
1471 logger.Errorw("Cannot send EVTOCD set", log.Fields{
1472 "Err": err, "device-id": oo.deviceID})
1473 return nil
1474 }
1475 logger.Debug("send EVTOCD-set msg done")
1476 return meInstance
1477 }
1478 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
1479 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1480 return nil
1481}