blob: f49a3704a352c08b4cfd681beceb41c05da252ad [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 ####
Himani Chawla6d2ae152020-09-02 13:11:20 +053047
48//ConstDefaultOmciTimeout - Default OMCI Timeout
Holger Hildebrandtfa074992020-03-27 15:42:06 +000049const ConstDefaultOmciTimeout = 10 // ( 3 ?) Seconds
50
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000051const galEthernetEID = uint16(1)
52const maxGemPayloadSize = uint16(48)
53const connectivityModeValue = uint8(5)
Himani Chawla4d908332020-08-31 12:30:20 +053054
55//const defaultTPID = uint16(0x8100)
56//const broadComDefaultVID = uint16(4091)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000057const macBridgeServiceProfileEID = uint16(0x201) // TODO: most all these need better definition or tuning
58const ieeeMapperServiceProfileEID = uint16(0x8001)
59const macBridgePortAniEID = uint16(0x2102)
60
61// ### OMCI related definitions - end
62
Himani Chawla6d2ae152020-09-02 13:11:20 +053063//callbackPairEntry to be used for OMCI send/receive correlation
64type callbackPairEntry struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000065 cbRespChannel chan Message
66 cbFunction func(*omci.OMCI, *gp.Packet, chan Message) error
67}
68
Himani Chawla6d2ae152020-09-02 13:11:20 +053069//callbackPair to be used for ReceiveCallback init
70type callbackPair struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000071 cbKey uint16
Himani Chawla6d2ae152020-09-02 13:11:20 +053072 cbEntry callbackPairEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +000073}
74
75type omciTransferStructure struct {
76 txFrame []byte
77 timeout int
78 retry int
79 highPrio bool
80}
81
Himani Chawla6d2ae152020-09-02 13:11:20 +053082//omciCC structure holds information needed for OMCI communication (to/from OLT Adapter)
83type omciCC struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000084 enabled bool
85 pOnuDeviceEntry *OnuDeviceEntry
86 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053087 pBaseDeviceHandler *deviceHandler
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088 coreProxy adapterif.CoreProxy
89 adapterProxy adapterif.AdapterProxy
90 supportExtMsg bool
91 //txRequest
92 //rxResponse
93 //pendingRequest
94 txFrames, txOnuFrames uint32
95 rxFrames, rxOnuFrames, rxOnuDiscards uint32
96
97 // OMCI params
98 mutexTid sync.Mutex
99 tid uint16
100 mutexHpTid sync.Mutex
101 hpTid uint16
102 uploadSequNo uint16
103 uploadNoOfCmds uint16
104
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000105 mutexTxQueue sync.Mutex
106 txQueue *list.List
107 mutexRxSchedMap sync.Mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530108 rxSchedulerMap map[uint16]callbackPairEntry
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000109 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000110}
111
Himani Chawla6d2ae152020-09-02 13:11:20 +0530112//newOmciCC constructor returns a new instance of a OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530114func newOmciCC(ctx context.Context, onuDeviceEntry *OnuDeviceEntry,
115 deviceID string, deviceHandler *deviceHandler,
116 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy) *omciCC {
Himani Chawla4d908332020-08-31 12:30:20 +0530117 logger.Infow("init-omciCC", log.Fields{"device-id": deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530118 var omciCC omciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119 omciCC.enabled = false
Himani Chawla4d908332020-08-31 12:30:20 +0530120 omciCC.pOnuDeviceEntry = onuDeviceEntry
121 omciCC.deviceID = deviceID
122 omciCC.pBaseDeviceHandler = deviceHandler
123 omciCC.coreProxy = coreProxy
124 omciCC.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 omciCC.supportExtMsg = false
126 omciCC.txFrames = 0
127 omciCC.txOnuFrames = 0
128 omciCC.rxFrames = 0
129 omciCC.rxOnuFrames = 0
130 omciCC.rxOnuDiscards = 0
131 omciCC.tid = 0x1
132 omciCC.hpTid = 0x8000
133 omciCC.uploadSequNo = 0
134 omciCC.uploadNoOfCmds = 0
135
136 omciCC.txQueue = list.New()
Himani Chawla6d2ae152020-09-02 13:11:20 +0530137 omciCC.rxSchedulerMap = make(map[uint16]callbackPairEntry)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000138
139 return &omciCC
140}
141
142// Rx handler for omci messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530143func (oo *omciCC) receiveOnuMessage(ctx context.Context, omciMsg *omci.OMCI) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000144 logger.Debugw("rx-onu-autonomous-message", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000145 "payload": hex.EncodeToString(omciMsg.Payload)})
146 /*
147 msgType = rxFrame.fields["message_type"] //assumed OmciOperationsValue
148 rxOnuFrames++
149
150 switch msgType {
151 case AlarmNotification:
152 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000153 logger.Info("Unhandled: received-onu-alarm-message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000154 // python code was:
155 //if msg_type == EntityOperations.AlarmNotification.value:
156 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Alarm_Notification)
157 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
158 //
159 return errors.New("RxAlarmNotification unimplemented")
160 }
161 case AttributeValueChange:
162 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000163 logger.Info("Unhandled: received-attribute-value-change")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000164 // python code was:
165 //elif msg_type == EntityOperations.AttributeValueChange.value:
166 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.AVC_Notification)
167 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
168 //
169 return errors.New("RxAttributeValueChange unimplemented")
170 }
171 case TestResult:
172 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000173 logger.Info("Unhandled: received-test-result")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000174 // python code was:
175 //elif msg_type == EntityOperations.TestResult.value:
176 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Test_Result)
177 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
178 //
179 return errors.New("RxTestResult unimplemented")
180 }
181 default:
182 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000183 logger.Errorw("rx-onu-unsupported-autonomous-message", log.Fields{"msgType": msgType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000184 rxOnuDiscards++
185 return errors.New("RxOnuMsgType unimplemented")
186 }
187 }
188 */
Himani Chawla4d908332020-08-31 12:30:20 +0530189 return errors.New("receiveOnuMessage unimplemented")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000190}
191
192// Rx handler for onu messages
193// e.g. would call ReceiveOnuMessage() in case of TID=0 or Action=test ...
Himani Chawla6d2ae152020-09-02 13:11:20 +0530194func (oo *omciCC) receiveMessage(ctx context.Context, rxMsg []byte) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000195 //logger.Debugw("cc-receive-omci-message", log.Fields{"RxOmciMessage-x2s": hex.EncodeToString(rxMsg)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000196 if len(rxMsg) >= 44 { // then it should normally include the BaseFormat trailer Len
197 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
198 // (am extendedFormat message could be destroyed this way!)
199 trailerLenData := rxMsg[42:44]
200 trailerLen := binary.BigEndian.Uint16(trailerLenData)
mpagenko1cc3cb42020-07-27 15:24:38 +0000201 //logger.Debugw("omci-received-trailer-len", log.Fields{"Length": trailerLen})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000202 if trailerLen != 40 { // invalid base Format entry -> autocorrect
203 binary.BigEndian.PutUint16(rxMsg[42:44], 40)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000204 logger.Debug("cc-corrected-omci-message: trailer len inserted")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000205 }
206 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530207 logger.Errorw("received omci-message too small for OmciBaseFormat - abort", log.Fields{"Length": len(rxMsg)})
208 return errors.New("rxOmciMessage too small for BaseFormat")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000209 }
210
211 packet := gopacket.NewPacket(rxMsg, omci.LayerTypeOMCI, gopacket.NoCopy)
212 if packet == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000213 logger.Error("omci-message could not be decoded")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000214 return errors.New("could not decode rxMsg as OMCI")
215 }
216 omciLayer := packet.Layer(omci.LayerTypeOMCI)
217 if omciLayer == nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000218 logger.Error("omci-message could not decode omci layer")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000219 return errors.New("could not decode omci layer")
220 }
221 omciMsg, ok := omciLayer.(*omci.OMCI)
222 if !ok {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000223 logger.Error("omci-message could not assign omci layer")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000224 return errors.New("could not assign omci layer")
225 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000226 logger.Debugw("omci-message-decoded:", log.Fields{"omciMsgType": omciMsg.MessageType,
mpagenko3dbcdd22020-07-22 07:38:45 +0000227 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "DeviceIdent": omciMsg.DeviceIdentifier})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000228 if byte(omciMsg.MessageType) & ^me.AK == 0 {
229 // Not a response
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000230 logger.Debug("RxMsg is no Omci Response Message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000231 if omciMsg.TransactionID == 0 {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530232 return oo.receiveOnuMessage(ctx, omciMsg)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000233 }
Himani Chawla4d908332020-08-31 12:30:20 +0530234 logger.Errorw("Unexpected TransCorrId != 0 not accepted for autonomous messages",
235 log.Fields{"msgType": omciMsg.MessageType, "payload": hex.EncodeToString(omciMsg.Payload)})
236 return errors.New("autonomous Omci Message with TranSCorrId != 0 not acccepted")
237
238 }
239 //logger.Debug("RxMsg is a Omci Response Message: try to schedule it to the requester")
240 oo.mutexRxSchedMap.Lock()
241 rxCallbackEntry, ok := oo.rxSchedulerMap[omciMsg.TransactionID]
242 if ok && rxCallbackEntry.cbFunction != nil {
243 //disadvantage of decoupling: error verification made difficult, but anyway the question is
244 // how to react on erroneous frame reception, maybe can simply be ignored
245 go rxCallbackEntry.cbFunction(omciMsg, &packet, rxCallbackEntry.cbRespChannel)
246 // having posted the response the request is regarded as 'done'
247 delete(oo.rxSchedulerMap, omciMsg.TransactionID)
248 oo.mutexRxSchedMap.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000249 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530250 oo.mutexRxSchedMap.Unlock()
251 logger.Error("omci-message-response for not registered transCorrId")
252 return errors.New("could not find registered response handler tor transCorrId")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000253 }
254
255 return nil
256 /* py code was:
257 Receive and OMCI message from the proxy channel to the OLT.
258
259 Call this from your ONU Adapter on a new OMCI Rx on the proxy channel
260 :param msg: (str) OMCI binary message (used as input to Scapy packet decoder)
261 """
262 if not self.enabled:
263 return
264
265 try:
266 now = arrow.utcnow()
267 d = None
268
269 # NOTE: Since we may need to do an independent ME map on a per-ONU basis
270 # save the current value of the entity_id_to_class_map, then
271 # replace it with our custom one before decode, and then finally
272 # restore it later. Tried other ways but really made the code messy.
273 saved_me_map = omci_entities.entity_id_to_class_map
274 omci_entities.entity_id_to_class_map = self._me_map
275
276 try:
277 rx_frame = msg if isinstance(msg, OmciFrame) else OmciFrame(msg)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000278 self.logger.debug('recv-omci-msg', omci_msg=hexlify(msg))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000279 except KeyError as e:
280 # Unknown, Unsupported, or vendor-specific ME. Key is the unknown classID
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000281 self.logger.debug('frame-decode-key-error', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000282 rx_frame = self._decode_unknown_me(msg)
283 self._rx_unknown_me += 1
284
285 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000286 self.logger.exception('frame-decode', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000287 return
288
289 finally:
290 omci_entities.entity_id_to_class_map = saved_me_map # Always restore it.
291
292 rx_tid = rx_frame.fields['transaction_id']
293 msg_type = rx_frame.fields['message_type']
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000294 self.logger.debug('Received message for rx_tid', rx_tid = rx_tid, msg_type = msg_type)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000295 # Filter the Test Result frame and route through receive onu
296 # message method.
297 if rx_tid == 0 or msg_type == EntityOperations.TestResult.value:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000298 self.logger.debug('Receive ONU message', rx_tid=0)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000299 return self._receive_onu_message(rx_frame)
300
301 # Previously unreachable if this is the very first round-trip Rx or we
302 # have been running consecutive errors
303 if self._rx_frames == 0 or self._consecutive_errors != 0:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000304 self.logger.debug('Consecutive errors for rx', err = self._consecutive_errors)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000305 self.reactor.callLater(0, self._publish_connectivity_event, True)
306
307 self._rx_frames += 1
308 self._consecutive_errors = 0
309
310 try:
311 high_priority = self._tid_is_high_priority(rx_tid)
312 index = self._get_priority_index(high_priority)
313
314 # (timestamp, defer, frame, timeout, retry, delayedCall)
315 last_tx_tuple = self._tx_request[index]
316
317 if last_tx_tuple is None or \
318 last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id') != rx_tid:
319 # Possible late Rx on a message that timed-out
320 if last_tx_tuple:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000321 self.logger.debug('Unknown message', rx_tid=rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000322 tx_id=last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id'))
323 self._rx_unknown_tid += 1
324 self._rx_late += 1
325 return
326
327 ts, d, tx_frame, timeout, retry, dc = last_tx_tuple
328 if dc is not None and not dc.cancelled and not dc.called:
329 dc.cancel()
330
331 _secs = self._update_rx_tx_stats(now, ts)
332
333 # Late arrival already serviced by a timeout?
334 if d.called:
335 self._rx_late += 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000336 self.logger.debug('Serviced by timeout. Late arrival', rx_late = self._rx_late)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000337 return
338
339 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000340 self.logger.exception('frame-match', msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000341 if d is not None:
342 return d.errback(failure.Failure(e))
343 return
344
345 # Publish Rx event to listeners in a different task
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000346 self.logger.debug('Publish rx event', rx_tid = rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000347 tx_tid = tx_frame.fields['transaction_id'])
348 reactor.callLater(0, self._publish_rx_frame, tx_frame, rx_frame)
349
350 # begin success callback chain (will cancel timeout and queue next Tx message)
351 self._rx_response[index] = rx_frame
352 d.callback(rx_frame)
353
354 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000355 self.logger.exception('rx-msg', e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000356 */
357}
358
Himani Chawla6d2ae152020-09-02 13:11:20 +0530359/*
360func (oo *omciCC) publishRxResponseFrame(ctx context.Context, txFrame []byte, rxFrame []byte) error {
Himani Chawla4d908332020-08-31 12:30:20 +0530361 return errors.New("publishRxResponseFrame unimplemented")
Himani Chawla6d2ae152020-09-02 13:11:20 +0530362 //def _publish_rx_frame(self, tx_frame, rx_frame):
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000363}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530364*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000365
366//Queue the OMCI Frame for a transmit to the ONU via the proxy_channel
Himani Chawla6d2ae152020-09-02 13:11:20 +0530367func (oo *omciCC) send(ctx context.Context, txFrame []byte, timeout int, retry int, highPrio bool,
368 receiveCallbackPair callbackPair) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000369
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000370 logger.Debugw("register-response-callback:", log.Fields{"for TansCorrId": receiveCallbackPair.cbKey})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000371 // it could be checked, if the callback keay is already registered - but simply overwrite may be acceptable ...
372 oo.mutexRxSchedMap.Lock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000373 oo.rxSchedulerMap[receiveCallbackPair.cbKey] = receiveCallbackPair.cbEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000374 oo.mutexRxSchedMap.Unlock()
375
376 //just use a simple list for starting - might need some more effort, especially for multi source write access
377 omciTxRequest := omciTransferStructure{
378 txFrame,
379 timeout,
380 retry,
381 highPrio,
382 }
383 oo.mutexTxQueue.Lock()
384 oo.txQueue.PushBack(omciTxRequest) // enqueue
385 oo.mutexTxQueue.Unlock()
386
387 // for first test just bypass and send directly:
388 go oo.sendNextRequest(ctx)
389 return nil
390}
391
392//Pull next tx request and send it
Himani Chawla6d2ae152020-09-02 13:11:20 +0530393func (oo *omciCC) sendNextRequest(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000394 // return errors.New("sendNextRequest unimplemented")
395
396 // just try to get something transferred !!
397 // avoid accessing the txQueue from parallel send requests
398 // block parallel omci send requests at least until SendIAP is 'committed'
399 // that should be feasible for an onu instance as on OMCI anyway window size 1 is assumed
400 oo.mutexTxQueue.Lock()
mpagenkodff5dda2020-08-28 11:52:01 +0000401 defer oo.mutexTxQueue.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000402 for oo.txQueue.Len() > 0 {
403 queueElement := oo.txQueue.Front() // First element
404 omciTxRequest := queueElement.Value.(omciTransferStructure)
405 /* compare olt device handler code:
406 func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000407 logger.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000408 var deviceType string
409 var deviceID string
410 var proxyDeviceID string
411
412 onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
413
414 if onuInCache, ok := dh.onus.Load(onuKey); !ok {
415
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000416 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 +0000417 ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
418 kwargs := make(map[string]interface{})
419 kwargs["onu_id"] = omciInd.OnuId
420 kwargs["parent_port_no"] = ponPort
421
422 onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
423 if err != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000424 logger.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId, "error": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000425 return
426 }
427 deviceType = onuDevice.Type
428 deviceID = onuDevice.Id
429 proxyDeviceID = onuDevice.ProxyAddress.DeviceId
430 //if not exist in cache, then add to cache.
431 dh.onus.Store(onuKey, NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID))
432 } else {
433 //found in cache
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000434 logger.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000435 deviceType = onuInCache.(*OnuDevice).deviceType
436 deviceID = onuInCache.(*OnuDevice).deviceID
437 proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID
438 }
439 */
440 /* and compare onu_adapter py code:
441 omci_msg = InterAdapterOmciMessage(
442 message=bytes(frame),
443 proxy_address=self._proxy_address,
444 connect_status=self._device.connect_status)
445
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000446 self.logger.debug('sent-omci-msg', tid=tx_tid, omci_msg=hexlify(bytes(frame)))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000447
448 yield self._adapter_proxy.send_inter_adapter_message(
449 msg=omci_msg,
450 type=InterAdapterMessageType.OMCI_REQUEST,
451 from_adapter=self._device.type,
452 to_adapter=self._proxy_address.device_type,
453 to_device_id=self._device_id,
454 proxy_device_id=self._proxy_address.device_id
455 )
456 */
457 device, err := oo.coreProxy.GetDevice(ctx,
458 oo.pBaseDeviceHandler.deviceID, oo.deviceID) //parent, child
459 if err != nil || device == nil {
460 /*TODO: needs to handle error scenarios */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000461 logger.Errorw("Failed to fetch device", log.Fields{"err": err, "ParentId": oo.pBaseDeviceHandler.deviceID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000462 "ChildId": oo.deviceID})
463 return errors.New("failed to fetch device")
464 }
465
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000466 logger.Debugw("omci-message-sending", log.Fields{"fromDeviceType": oo.pBaseDeviceHandler.DeviceType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000467 "toDeviceType": oo.pBaseDeviceHandler.ProxyAddressType,
468 "onuDeviceID": oo.deviceID, "proxyDeviceID": oo.pBaseDeviceHandler.ProxyAddressID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000469 logger.Debugw("omci-message-to-send:",
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000470 log.Fields{"TxOmciMessage": hex.EncodeToString(omciTxRequest.txFrame)})
471
472 omciMsg := &ic.InterAdapterOmciMessage{Message: omciTxRequest.txFrame}
473 if sendErr := oo.adapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
474 ic.InterAdapterMessageType_OMCI_REQUEST,
475 //fromType,toType,toDevId, ProxyDevId
476 oo.pBaseDeviceHandler.DeviceType, oo.pBaseDeviceHandler.ProxyAddressType,
477 oo.deviceID, oo.pBaseDeviceHandler.ProxyAddressID, ""); sendErr != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000478 logger.Errorw("send omci request error", log.Fields{"error": sendErr})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000479 return sendErr
480 }
481 oo.txQueue.Remove(queueElement) // Dequeue
482 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000483 return nil
484}
485
Himani Chawla6d2ae152020-09-02 13:11:20 +0530486func (oo *omciCC) getNextTid(highPriority bool) uint16 {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000487 var next uint16
488 if highPriority {
489 oo.mutexTid.Lock()
490 next = oo.hpTid
Himani Chawla4d908332020-08-31 12:30:20 +0530491 oo.hpTid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000492 if oo.hpTid < 0x8000 {
493 oo.hpTid = 0x8000
494 }
495 oo.mutexTid.Unlock()
496 } else {
497 oo.mutexHpTid.Lock()
498 next = oo.tid
Himani Chawla4d908332020-08-31 12:30:20 +0530499 oo.tid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000500 if oo.tid >= 0x8000 {
501 oo.tid = 1
502 }
503 oo.mutexHpTid.Unlock()
504 }
505 return next
506}
507
508// ###################################################################################
509// # utility methods provided to work on OMCI messages
510func serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
511 omciLayer := &omci.OMCI{
512 TransactionID: tid,
513 MessageType: msgType,
514 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000515 return serializeOmciLayer(omciLayer, request)
516}
517
Himani Chawla4d908332020-08-31 12:30:20 +0530518func serializeOmciLayer(aOmciLayer *omci.OMCI, aRequest gopacket.SerializableLayer) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000519 var options gopacket.SerializeOptions
520 options.FixLengths = true
521
522 buffer := gopacket.NewSerializeBuffer()
Himani Chawla4d908332020-08-31 12:30:20 +0530523 err := gopacket.SerializeLayers(buffer, options, aOmciLayer, aRequest)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000524 if err != nil {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000525 logger.Errorw("Could not create goPacket Omci serial buffer", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000526 return nil, err
527 }
528 return buffer.Bytes(), nil
529}
530
Himani Chawla4d908332020-08-31 12:30:20 +0530531/*
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000532func hexEncode(omciPkt []byte) ([]byte, error) {
533 dst := make([]byte, hex.EncodedLen(len(omciPkt)))
534 hex.Encode(dst, omciPkt)
535 return dst, nil
536}
Himani Chawla4d908332020-08-31 12:30:20 +0530537*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000538
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000539//supply a response handler for omci response messages to be transferred to the requested FSM
Himani Chawla6d2ae152020-09-02 13:11:20 +0530540func (oo *omciCC) receiveOmciResponse(omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000541
mpagenko3dbcdd22020-07-22 07:38:45 +0000542 logger.Debugw("omci-message-response - transfer on omciRespChannel", log.Fields{"omciMsgType": omciMsg.MessageType,
divyadesai4d299552020-08-18 07:13:49 +0000543 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000544
545 if oo.pOnuDeviceEntry == nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000546 logger.Errorw("Abort receiving OMCI response, DeviceEntryPointer is nil", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000547 "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530548 return errors.New("deviceEntryPointer is nil")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000549 }
550
551 // no further test on SeqNo is done here, assignment from rxScheduler is trusted
552 // MibSync responses are simply transferred via deviceEntry to MibSync, no specific analysis here
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000553 omciRespMsg := Message{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000554 Type: OMCI,
555 Data: OmciMessage{
556 OmciMsg: omciMsg,
557 OmciPacket: packet,
558 },
559 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000560 //logger.Debugw("Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000561 respChan <- omciRespMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000562
563 return nil
564}
565
Himani Chawla6d2ae152020-09-02 13:11:20 +0530566func (oo *omciCC) sendMibReset(ctx context.Context, timeout int, highPrio bool) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000567
divyadesai4d299552020-08-18 07:13:49 +0000568 logger.Debugw("send MibReset-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000569 request := &omci.MibResetRequest{
570 MeBasePacket: omci.MeBasePacket{
571 EntityClass: me.OnuDataClassID,
572 },
573 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530574 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000575 pkt, err := serialize(omci.MibResetRequestType, request, tid)
576 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000577 logger.Errorw("Cannot serialize MibResetRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000578 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000579 return err
580 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530581 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000582 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530583 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000584 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530585 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000586}
587
Himani Chawla6d2ae152020-09-02 13:11:20 +0530588func (oo *omciCC) sendReboot(ctx context.Context, timeout int, highPrio bool, responseChannel chan Message) error {
divyadesai4d299552020-08-18 07:13:49 +0000589 logger.Debugw("send Reboot-msg to:", log.Fields{"device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300590 request := &omci.RebootRequest{
591 MeBasePacket: omci.MeBasePacket{
592 EntityClass: me.OnuGClassID,
593 },
594 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530595 tid := oo.getNextTid(highPrio)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300596 pkt, err := serialize(omci.RebootRequestType, request, tid)
597 if err != nil {
598 logger.Errorw("Cannot serialize RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000599 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300600 return err
601 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530602 omciRxCallbackPair := callbackPair{
ozgecanetsiae11479f2020-07-06 09:44:47 +0300603 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530604 cbEntry: callbackPairEntry{oo.pOnuDeviceEntry.omciRebootMessageReceivedChannel, oo.receiveOmciResponse},
ozgecanetsiae11479f2020-07-06 09:44:47 +0300605 }
606
Himani Chawla6d2ae152020-09-02 13:11:20 +0530607 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300608 if err != nil {
609 logger.Errorw("Cannot send RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000610 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300611 return err
612 }
613 err = oo.pOnuDeviceEntry.waitForRebootResponse(responseChannel)
614 if err != nil {
615 logger.Error("aborting ONU Reboot!")
Himani Chawla4d908332020-08-31 12:30:20 +0530616 _ = oo.pOnuDeviceEntry.pMibDownloadFsm.pFsm.Event("reset")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300617 return err
618 }
619 return nil
620}
621
Himani Chawla6d2ae152020-09-02 13:11:20 +0530622func (oo *omciCC) sendMibUpload(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000623 logger.Debugw("send MibUpload-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000624 request := &omci.MibUploadRequest{
625 MeBasePacket: omci.MeBasePacket{
626 EntityClass: me.OnuDataClassID,
627 },
628 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530629 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000630 pkt, err := serialize(omci.MibUploadRequestType, request, tid)
631 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000632 logger.Errorw("Cannot serialize MibUploadRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000633 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000634 return err
635 }
636 oo.uploadSequNo = 0
637 oo.uploadNoOfCmds = 0
638
Himani Chawla6d2ae152020-09-02 13:11:20 +0530639 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000640 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530641 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000642 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530643 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000644}
645
Himani Chawla6d2ae152020-09-02 13:11:20 +0530646func (oo *omciCC) sendMibUploadNext(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000647 logger.Debugw("send MibUploadNext-msg to:", log.Fields{"device-id": oo.deviceID, "uploadSequNo": oo.uploadSequNo})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000648 request := &omci.MibUploadNextRequest{
649 MeBasePacket: omci.MeBasePacket{
650 EntityClass: me.OnuDataClassID,
651 },
652 CommandSequenceNumber: oo.uploadSequNo,
653 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530654 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000655 pkt, err := serialize(omci.MibUploadNextRequestType, request, tid)
656 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000657 logger.Errorw("Cannot serialize MibUploadNextRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000658 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000659 return err
660 }
661 oo.uploadSequNo++
662
Himani Chawla6d2ae152020-09-02 13:11:20 +0530663 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000664 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530665 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000666 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530667 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000668}
669
Himani Chawla6d2ae152020-09-02 13:11:20 +0530670func (oo *omciCC) sendCreateGalEthernetProfile(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
671 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000672 logger.Debugw("send GalEnetProfile-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000673 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000674
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000675 meParams := me.ParamData{
676 EntityID: galEthernetEID,
677 Attributes: me.AttributeValueMap{"MaximumGemPayloadSize": maxGemPayloadSize},
678 }
679 meInstance, omciErr := me.NewGalEthernetProfile(meParams)
680 if omciErr.GetError() == nil {
681 //all setByCreate parameters already set, no default option required ...
682 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
683 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000684 logger.Errorw("Cannot encode GalEnetProfileInstance for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000685 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000686 return nil
687 }
688
689 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
690 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000691 logger.Errorw("Cannot serialize GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000692 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000693 return nil
694 }
695
Himani Chawla6d2ae152020-09-02 13:11:20 +0530696 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000697 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530698 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000699 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530700 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000701 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000702 logger.Errorw("Cannot send GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000703 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000704 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000705 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000706 logger.Debug("send GalEnetProfile-Create-msg done")
707 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000708 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000709 logger.Errorw("Cannot generate GalEnetProfileInstance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000710 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000711 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000712}
713
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000714// might be needed to extend for parameter arguments, here just for setting the ConnectivityMode!!
Himani Chawla6d2ae152020-09-02 13:11:20 +0530715func (oo *omciCC) sendSetOnu2g(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
716 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000717 logger.Debugw("send ONU2-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000718 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000719
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000720 // ONU-G ME-ID is defined to be 0, but we could verify, if the ONU really supports the desired
721 // connectivity mode 5 (in ConnCap)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000722 // By now we just use fix values to fire - this is anyway what the python adapter does
723 // read ONU-2G from DB ???? //TODO!!!
724 meParams := me.ParamData{
725 EntityID: 0,
726 Attributes: me.AttributeValueMap{"CurrentConnectivityMode": connectivityModeValue},
727 }
728 meInstance, omciErr := me.NewOnu2G(meParams)
729 if omciErr.GetError() == nil {
730 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
731 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000732 logger.Errorw("Cannot encode ONU2-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000733 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000734 return nil
735 }
736
737 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
738 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000739 logger.Errorw("Cannot serialize ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000740 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000741 return nil
742 }
743
Himani Chawla6d2ae152020-09-02 13:11:20 +0530744 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000745 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530746 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000747 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530748 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000749 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000750 logger.Errorw("Cannot send ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000751 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000752 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000753 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000754 logger.Debug("send ONU2-G-Set-msg done")
755 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000756 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000757 logger.Errorw("Cannot generate ONU2-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000758 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000759 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000760}
761
Himani Chawla6d2ae152020-09-02 13:11:20 +0530762func (oo *omciCC) sendCreateMBServiceProfile(ctx context.Context,
763 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
764 tid := oo.getNextTid(highPrio)
Himani Chawla4d908332020-08-31 12:30:20 +0530765 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000766 logger.Debugw("send MBSP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000767 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000768
769 meParams := me.ParamData{
770 EntityID: instID,
771 Attributes: me.AttributeValueMap{
772 "Priority": 0x8000,
773 "MaxAge": 20 * 256, //20s
774 "HelloTime": 2 * 256, //2s
775 "ForwardDelay": 15 * 256, //15s
776 //note: DynamicFilteringAgeingTime is taken from omci lib default as
777 // which is obviously different from default value used in python lib,
778 // where the value seems to be 0 (ONU defined) - to be considered in case of test artifacts ...
779 },
780 }
781
782 meInstance, omciErr := me.NewMacBridgeServiceProfile(meParams)
783 if omciErr.GetError() == nil {
784 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
785 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
786 omci.TransactionID(tid), omci.AddDefaults(true))
787 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000788 logger.Errorw("Cannot encode MBSP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000789 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000790 return nil
791 }
792
793 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
794 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000795 logger.Errorw("Cannot serialize MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000796 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000797 return nil
798 }
799
Himani Chawla6d2ae152020-09-02 13:11:20 +0530800 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000801 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530802 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000803 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530804 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000805 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000806 logger.Errorw("Cannot send MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000807 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000808 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000809 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000810 logger.Debug("send MBSP-Create-msg done")
811 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000812 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000813 logger.Errorw("Cannot generate MBSP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000814 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000815 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000816}
817
Himani Chawla6d2ae152020-09-02 13:11:20 +0530818func (oo *omciCC) sendCreateMBPConfigData(ctx context.Context,
819 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
820 tid := oo.getNextTid(highPrio)
Himani Chawla26e555c2020-08-31 12:30:20 +0530821 instID := macBridgePortAniEID + aPUniPort.entityID
divyadesai4d299552020-08-18 07:13:49 +0000822 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000823 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000824
825 meParams := me.ParamData{
826 EntityID: instID,
827 Attributes: me.AttributeValueMap{
Himani Chawla4d908332020-08-31 12:30:20 +0530828 "BridgeIdPointer": macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo),
829 "PortNum": aPUniPort.macBpNo,
830 "TpType": uint8(aPUniPort.portType),
Himani Chawla26e555c2020-08-31 12:30:20 +0530831 "TpPointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000832 },
833 }
834 meInstance, omciErr := me.NewMacBridgePortConfigurationData(meParams)
835 if omciErr.GetError() == nil {
836 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
837 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
838 omci.TransactionID(tid), omci.AddDefaults(true))
839 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000840 logger.Errorw("Cannot encode MBPCD for 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
843 }
844
845 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
846 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000847 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000848 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000849 return nil
850 }
851
Himani Chawla6d2ae152020-09-02 13:11:20 +0530852 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000853 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530854 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000855 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530856 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000857 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000858 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000859 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000860 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000861 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000862 logger.Debug("send MBPCD-Create-msg done")
863 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000864 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000865 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000866 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000867 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000868}
869
Himani Chawla6d2ae152020-09-02 13:11:20 +0530870func (oo *omciCC) sendCreateEVTOConfigData(ctx context.Context,
871 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
872 tid := oo.getNextTid(highPrio)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000873 //same entityId is used as for MBSP (see there), but just arbitrary ...
Himani Chawla4d908332020-08-31 12:30:20 +0530874 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000875 logger.Debugw("send EVTOCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000876 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000877
878 // compare python adapter code WA VOL-1311: this is not done here!
879 // (setting TPID values for the create would probably anyway be ignored by the omci lib)
880 // but perhaps we have to be aware of possible problems at get(Next) Request handling for EVTOOCD tables later ...
881 assType := uint8(2) // default AssociationType is PPTPEthUni
Himani Chawla6d2ae152020-09-02 13:11:20 +0530882 if aPUniPort.portType == uniVEIP {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000883 assType = uint8(10) // for VEIP
884 }
885 meParams := me.ParamData{
886 EntityID: instID,
887 Attributes: me.AttributeValueMap{
888 "AssociationType": assType,
Himani Chawla26e555c2020-08-31 12:30:20 +0530889 "AssociatedMePointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000890 },
891 }
892 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(meParams)
893 if omciErr.GetError() == nil {
894 //all setByCreate parameters already set, no default option required ...
895 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
896 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000897 logger.Errorw("Cannot encode EVTOCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000898 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000899 return nil
900 }
901
902 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
903 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000904 logger.Errorw("Cannot serialize EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000905 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000906 return nil
907 }
908
Himani Chawla6d2ae152020-09-02 13:11:20 +0530909 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000910 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530911 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000912 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530913 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000914 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000915 logger.Errorw("Cannot send EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000916 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000917 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000918 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000919 logger.Debug("send EVTOCD-Create-msg done")
920 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000921 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000922 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000923 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000924 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000925}
926
Himani Chawla6d2ae152020-09-02 13:11:20 +0530927func (oo *omciCC) sendSetOnuGLS(ctx context.Context, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000928 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530929 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000930 logger.Debugw("send ONU-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000931 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000932
933 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
934 meParams := me.ParamData{
935 EntityID: 0,
936 Attributes: requestedAttributes,
937 }
938 meInstance, omciErr := me.NewOnuG(meParams)
939 if omciErr.GetError() == nil {
940 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
941 if err != nil {
942 logger.Errorw("Cannot encode ONU-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000943 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000944 return nil
945 }
946
947 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
948 if err != nil {
949 logger.Errorw("Cannot serialize ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000950 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000951 return nil
952 }
953
Himani Chawla6d2ae152020-09-02 13:11:20 +0530954 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000955 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530956 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000957 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530958 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000959 if err != nil {
960 logger.Errorw("Cannot send ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000961 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000962 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000963 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000964 logger.Debug("send ONU-G-Set-msg done")
965 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000966 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000967 logger.Errorw("Cannot generate ONU-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000968 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000969 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000970}
971
Himani Chawla6d2ae152020-09-02 13:11:20 +0530972func (oo *omciCC) sendSetUniGLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000973 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530974 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000975 logger.Debugw("send UNI-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000976 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000977
978 // UNI-G ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
979 meParams := me.ParamData{
980 EntityID: aInstNo,
981 Attributes: requestedAttributes,
982 }
983 meInstance, omciErr := me.NewUniG(meParams)
984 if omciErr.GetError() == nil {
985 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
986 if err != nil {
987 logger.Errorw("Cannot encode UNI-G instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000988 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000989 return nil
990 }
991
992 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
993 if err != nil {
994 logger.Errorw("Cannot serialize UNI-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
997 }
998
Himani Chawla6d2ae152020-09-02 13:11:20 +0530999 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001000 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301001 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001002 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301003 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001004 if err != nil {
1005 logger.Errorw("Cannot send UNIG-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001006 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001007 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001008 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001009 logger.Debug("send UNI-G-Set-msg done")
1010 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001011 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001012 logger.Errorw("Cannot generate UNI-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001013 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001014 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001015}
1016
Himani Chawla6d2ae152020-09-02 13:11:20 +05301017func (oo *omciCC) sendSetVeipLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001018 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301019 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001020 logger.Debugw("send VEIP-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001021 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001022
1023 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1024 meParams := me.ParamData{
1025 EntityID: aInstNo,
1026 Attributes: requestedAttributes,
1027 }
1028 meInstance, omciErr := me.NewVirtualEthernetInterfacePoint(meParams)
1029 if omciErr.GetError() == nil {
1030 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1031 if err != nil {
1032 logger.Errorw("Cannot encode VEIP instance for set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001033 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001034 return nil
1035 }
1036
1037 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1038 if err != nil {
1039 logger.Errorw("Cannot serialize VEIP-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
1042 }
1043
Himani Chawla6d2ae152020-09-02 13:11:20 +05301044 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001045 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301046 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001047 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301048 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001049 if err != nil {
1050 logger.Errorw("Cannot send VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001051 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001052 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001053 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001054 logger.Debug("send VEIP-Set-msg done")
1055 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001056 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001057 logger.Errorw("Cannot generate VEIP", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001058 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001059 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001060}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001061
Himani Chawla6d2ae152020-09-02 13:11:20 +05301062func (oo *omciCC) sendGetMe(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributes me.AttributeValueMap,
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001063 timeout int, highPrio bool) *me.ManagedEntity {
1064
Himani Chawla6d2ae152020-09-02 13:11:20 +05301065 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001066 logger.Debugw("send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001067 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001068
1069 meParams := me.ParamData{
1070 EntityID: entityID,
1071 Attributes: requestedAttributes,
1072 }
1073 meInstance, omciErr := me.LoadManagedEntityDefinition(classID, meParams)
1074 if omciErr.GetError() == nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301075 meClassIDName := meInstance.GetName()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001076 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.GetRequestType, omci.TransactionID(tid))
1077 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301078 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 +00001079 return nil
1080 }
1081 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1082 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301083 logger.Errorw("Cannot serialize get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001084 return nil
1085 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301086 omciRxCallbackPair := callbackPair{
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001087 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301088 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001089 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301090 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001091 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301092 logger.Errorw("Cannot send get-request-msg", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001093 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001094 }
Himani Chawla4d908332020-08-31 12:30:20 +05301095 logger.Debugw("send get-request-msg done", log.Fields{"meClassIDName": meClassIDName, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001096 return meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001097 }
divyadesai4d299552020-08-18 07:13:49 +00001098 logger.Errorw("Cannot generate meDefinition", log.Fields{"classID": classID, "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001099 return nil
1100}
1101
Himani Chawla6d2ae152020-09-02 13:11:20 +05301102func (oo *omciCC) sendCreateDot1PMapper(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001103 aInstID uint16, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301104 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001105 logger.Debugw("send .1pMapper-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001106 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
1107
1108 meParams := me.ParamData{
1109 EntityID: aInstID,
1110 Attributes: me.AttributeValueMap{},
1111 }
1112 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
1113 if omciErr.GetError() == nil {
1114 //we have to set all 'untouched' parameters to default by some additional option parameter!!
1115 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1116 omci.TransactionID(tid), omci.AddDefaults(true))
1117 if err != nil {
1118 logger.Errorw("Cannot encode .1pMapper for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001119 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001120 return nil
1121 }
1122
1123 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1124 if err != nil {
1125 logger.Errorw("Cannot serialize .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001126 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001127 return nil
1128 }
1129
Himani Chawla6d2ae152020-09-02 13:11:20 +05301130 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001131 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301132 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001133 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301134 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001135 if err != nil {
1136 logger.Errorw("Cannot send .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001137 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001138 return nil
1139 }
1140 logger.Debug("send .1pMapper-create-msg done")
1141 return meInstance
1142 }
1143 logger.Errorw("Cannot generate .1pMapper", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001144 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001145 return nil
1146}
1147
Himani Chawla6d2ae152020-09-02 13:11:20 +05301148func (oo *omciCC) sendCreateMBPConfigDataVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001149 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301150 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001151 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001152 "SequNo": strconv.FormatInt(int64(tid), 16),
1153 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1154
1155 meInstance, omciErr := me.NewMacBridgePortConfigurationData(params[0])
1156 if omciErr.GetError() == nil {
1157 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1158 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1159 omci.TransactionID(tid), omci.AddDefaults(true))
1160 if err != nil {
1161 logger.Errorw("Cannot encode MBPCD for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001162 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001163 return nil
1164 }
1165
1166 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1167 if err != nil {
1168 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001169 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001170 return nil
1171 }
1172
Himani Chawla6d2ae152020-09-02 13:11:20 +05301173 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001174 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301175 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001176 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301177 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001178 if err != nil {
1179 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001180 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001181 return nil
1182 }
1183 logger.Debug("send MBPCD-Create-msg done")
1184 return meInstance
1185 }
1186 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001187 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001188 return nil
1189}
1190
Himani Chawla6d2ae152020-09-02 13:11:20 +05301191func (oo *omciCC) sendCreateGemNCTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001192 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301193 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001194 logger.Debugw("send GemNCTP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001195 "SequNo": strconv.FormatInt(int64(tid), 16),
1196 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1197
1198 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1199 if omciErr.GetError() == nil {
1200 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1201 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1202 omci.TransactionID(tid), omci.AddDefaults(true))
1203 if err != nil {
1204 logger.Errorw("Cannot encode GemNCTP for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001205 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001206 return nil
1207 }
1208
1209 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1210 if err != nil {
1211 logger.Errorw("Cannot serialize GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001212 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001213 return nil
1214 }
1215
Himani Chawla6d2ae152020-09-02 13:11:20 +05301216 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001217 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301218 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001219 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301220 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001221 if err != nil {
1222 logger.Errorw("Cannot send GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001223 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001224 return nil
1225 }
1226 logger.Debug("send GemNCTP-Create-msg done")
1227 return meInstance
1228 }
1229 logger.Errorw("Cannot generate GemNCTP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001230 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001231 return nil
1232}
1233
Himani Chawla6d2ae152020-09-02 13:11:20 +05301234func (oo *omciCC) sendCreateGemIWTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001235 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301236 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001237 logger.Debugw("send GemIwTp-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001238 "SequNo": strconv.FormatInt(int64(tid), 16),
1239 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1240
1241 meInstance, omciErr := me.NewGemInterworkingTerminationPoint(params[0])
1242 if omciErr.GetError() == nil {
1243 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1244 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1245 omci.TransactionID(tid))
1246 if err != nil {
1247 logger.Errorw("Cannot encode GemIwTp for create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001248 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001249 return nil
1250 }
1251
1252 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1253 if err != nil {
1254 logger.Errorw("Cannot serialize GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001255 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001256 return nil
1257 }
1258
Himani Chawla6d2ae152020-09-02 13:11:20 +05301259 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001260 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301261 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001262 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301263 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001264 if err != nil {
1265 logger.Errorw("Cannot send GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001266 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001267 return nil
1268 }
1269 logger.Debug("send GemIwTp-Create-msg done")
1270 return meInstance
1271 }
1272 logger.Errorw("Cannot generate GemIwTp Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001273 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001274 return nil
1275}
1276
Himani Chawla6d2ae152020-09-02 13:11:20 +05301277func (oo *omciCC) sendSetTcontVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001278 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301279 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001280 logger.Debugw("send TCont-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001281 "SequNo": strconv.FormatInt(int64(tid), 16),
1282 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1283
1284 meInstance, omciErr := me.NewTCont(params[0])
1285 if omciErr.GetError() == nil {
1286 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1287 if err != nil {
1288 logger.Errorw("Cannot encode TCont for set", 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
1293 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1294 if err != nil {
1295 logger.Errorw("Cannot serialize TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001296 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001297 return nil
1298 }
1299
Himani Chawla6d2ae152020-09-02 13:11:20 +05301300 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001301 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301302 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001303 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301304 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001305 if err != nil {
1306 logger.Errorw("Cannot send TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001307 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001308 return nil
1309 }
1310 logger.Debug("send TCont-set msg done")
1311 return meInstance
1312 }
1313 logger.Errorw("Cannot generate TCont Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001314 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001315 return nil
1316}
1317
Himani Chawla6d2ae152020-09-02 13:11:20 +05301318func (oo *omciCC) sendSetPrioQueueVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001319 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301320 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001321 logger.Debugw("send PrioQueue-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001322 "SequNo": strconv.FormatInt(int64(tid), 16),
1323 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1324
1325 meInstance, omciErr := me.NewPriorityQueue(params[0])
1326 if omciErr.GetError() == nil {
1327 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1328 if err != nil {
1329 logger.Errorw("Cannot encode PrioQueue for 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
1334 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1335 if err != nil {
1336 logger.Errorw("Cannot serialize PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001337 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001338 return nil
1339 }
1340
Himani Chawla6d2ae152020-09-02 13:11:20 +05301341 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001342 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301343 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001344 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301345 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001346 if err != nil {
1347 logger.Errorw("Cannot send PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001348 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001349 return nil
1350 }
1351 logger.Debug("send PrioQueue-set msg done")
1352 return meInstance
1353 }
1354 logger.Errorw("Cannot generate PrioQueue Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001355 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001356 return nil
1357}
1358
Himani Chawla6d2ae152020-09-02 13:11:20 +05301359func (oo *omciCC) sendSetDot1PMapperVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001360 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301361 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001362 logger.Debugw("send 1PMapper-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001363 "SequNo": strconv.FormatInt(int64(tid), 16),
1364 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1365
1366 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(params[0])
1367 if omciErr.GetError() == nil {
1368 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1369 if err != nil {
1370 logger.Errorw("Cannot encode 1PMapper for 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
1375 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1376 if err != nil {
1377 logger.Errorw("Cannot serialize 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001378 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001379 return nil
1380 }
1381
Himani Chawla6d2ae152020-09-02 13:11:20 +05301382 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001383 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301384 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001385 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301386 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001387 if err != nil {
1388 logger.Errorw("Cannot send 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001389 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001390 return nil
1391 }
1392 logger.Debug("send 1PMapper-set msg done")
1393 return meInstance
1394 }
1395 logger.Errorw("Cannot generate 1PMapper Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001396 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001397 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001398}
mpagenkodff5dda2020-08-28 11:52:01 +00001399
Himani Chawla6d2ae152020-09-02 13:11:20 +05301400func (oo *omciCC) sendCreateVtfdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001401 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301402 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001403 logger.Debugw("send VTFD-Create-msg:", log.Fields{"device-id": oo.deviceID,
1404 "SequNo": strconv.FormatInt(int64(tid), 16),
1405 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1406
1407 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1408 if omciErr.GetError() == nil {
1409 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1410 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1411 omci.TransactionID(tid))
1412 if err != nil {
1413 logger.Errorw("Cannot encode VTFD for create", log.Fields{
1414 "Err": err, "device-id": oo.deviceID})
1415 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1416 // return (dual format) error code that can be used at caller for immediate error treatment
1417 // (relevant to all used sendXX() methods and their error conditions)
1418 return nil
1419 }
1420
1421 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1422 if err != nil {
1423 logger.Errorw("Cannot serialize VTFD create", log.Fields{
1424 "Err": err, "device-id": oo.deviceID})
1425 return nil
1426 }
1427
Himani Chawla6d2ae152020-09-02 13:11:20 +05301428 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001429 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301430 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001431 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301432 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001433 if err != nil {
1434 logger.Errorw("Cannot send VTFD create", log.Fields{
1435 "Err": err, "device-id": oo.deviceID})
1436 return nil
1437 }
1438 logger.Debug("send VTFD-Create-msg done")
1439 return meInstance
1440 }
1441 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1442 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1443 return nil
1444}
1445
Himani Chawla6d2ae152020-09-02 13:11:20 +05301446func (oo *omciCC) sendSetEvtocdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001447 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301448 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001449 logger.Debugw("send EVTOCD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1450 "SequNo": strconv.FormatInt(int64(tid), 16),
1451 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1452
1453 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(params[0])
1454 if omciErr.GetError() == nil {
1455 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1456 if err != nil {
1457 logger.Errorw("Cannot encode EVTOCD for set", log.Fields{
1458 "Err": err, "device-id": oo.deviceID})
1459 return nil
1460 }
1461
1462 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1463 if err != nil {
1464 logger.Errorw("Cannot serialize EVTOCD set", log.Fields{
1465 "Err": err, "device-id": oo.deviceID})
1466 return nil
1467 }
1468
Himani Chawla6d2ae152020-09-02 13:11:20 +05301469 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001470 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301471 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001472 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301473 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001474 if err != nil {
1475 logger.Errorw("Cannot send EVTOCD set", log.Fields{
1476 "Err": err, "device-id": oo.deviceID})
1477 return nil
1478 }
1479 logger.Debug("send EVTOCD-set msg done")
1480 return meInstance
1481 }
1482 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
1483 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1484 return nil
1485}