blob: 8a02b4488c5ff6fbc0f83488e049016f5bc0f3ae [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
2 * Copyright 2020-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "container/list"
22 "context"
23 "encoding/binary"
24 "encoding/hex"
25 "errors"
Andrea Campanella6515c582020-10-05 11:25:00 +020026 "fmt"
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000027 "strconv"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028 "sync"
mpagenkodff5dda2020-08-28 11:52:01 +000029
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030 //"time"
31
32 "github.com/google/gopacket"
33 // TODO!!! Some references could be resolved auto, but some need specific context ....
34 gp "github.com/google/gopacket"
35
36 "github.com/opencord/omci-lib-go"
37 me "github.com/opencord/omci-lib-go/generated"
38 "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
39
40 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
41 "github.com/opencord/voltha-lib-go/v3/pkg/log"
42 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
43 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
44 //"github.com/opencord/voltha-protos/v3/go/voltha"
45)
46
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000047// ### OMCI related definitions - retrieved from Python adapter code/trace ####
Himani Chawla6d2ae152020-09-02 13:11:20 +053048
49//ConstDefaultOmciTimeout - Default OMCI Timeout
Holger Hildebrandtfa074992020-03-27 15:42:06 +000050const ConstDefaultOmciTimeout = 10 // ( 3 ?) Seconds
51
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000052const galEthernetEID = uint16(1)
53const maxGemPayloadSize = uint16(48)
54const connectivityModeValue = uint8(5)
Himani Chawla4d908332020-08-31 12:30:20 +053055
56//const defaultTPID = uint16(0x8100)
57//const broadComDefaultVID = uint16(4091)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +000058const macBridgeServiceProfileEID = uint16(0x201) // TODO: most all these need better definition or tuning
59const ieeeMapperServiceProfileEID = uint16(0x8001)
60const macBridgePortAniEID = uint16(0x2102)
61
62// ### OMCI related definitions - end
63
Himani Chawla6d2ae152020-09-02 13:11:20 +053064//callbackPairEntry to be used for OMCI send/receive correlation
65type callbackPairEntry struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000066 cbRespChannel chan Message
67 cbFunction func(*omci.OMCI, *gp.Packet, chan Message) error
68}
69
Himani Chawla6d2ae152020-09-02 13:11:20 +053070//callbackPair to be used for ReceiveCallback init
71type callbackPair struct {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000072 cbKey uint16
Himani Chawla6d2ae152020-09-02 13:11:20 +053073 cbEntry callbackPairEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +000074}
75
76type omciTransferStructure struct {
77 txFrame []byte
78 timeout int
79 retry int
80 highPrio bool
81}
82
Himani Chawla6d2ae152020-09-02 13:11:20 +053083//omciCC structure holds information needed for OMCI communication (to/from OLT Adapter)
84type omciCC struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085 enabled bool
86 pOnuDeviceEntry *OnuDeviceEntry
87 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053088 pBaseDeviceHandler *deviceHandler
Holger Hildebrandtfa074992020-03-27 15:42:06 +000089 coreProxy adapterif.CoreProxy
90 adapterProxy adapterif.AdapterProxy
91 supportExtMsg bool
92 //txRequest
93 //rxResponse
94 //pendingRequest
95 txFrames, txOnuFrames uint32
96 rxFrames, rxOnuFrames, rxOnuDiscards uint32
97
98 // OMCI params
99 mutexTid sync.Mutex
100 tid uint16
101 mutexHpTid sync.Mutex
102 hpTid uint16
103 uploadSequNo uint16
104 uploadNoOfCmds uint16
105
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000106 mutexTxQueue sync.Mutex
107 txQueue *list.List
108 mutexRxSchedMap sync.Mutex
Himani Chawla6d2ae152020-09-02 13:11:20 +0530109 rxSchedulerMap map[uint16]callbackPairEntry
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000110 pLastTxMeInstance *me.ManagedEntity
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111}
112
Himani Chawla6d2ae152020-09-02 13:11:20 +0530113//newOmciCC constructor returns a new instance of a OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000114//mib_db (as well as not inluded alarm_db not really used in this code? VERIFY!!)
Himani Chawla6d2ae152020-09-02 13:11:20 +0530115func newOmciCC(ctx context.Context, onuDeviceEntry *OnuDeviceEntry,
116 deviceID string, deviceHandler *deviceHandler,
117 coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy) *omciCC {
Himani Chawla4d908332020-08-31 12:30:20 +0530118 logger.Infow("init-omciCC", log.Fields{"device-id": deviceID})
Himani Chawla6d2ae152020-09-02 13:11:20 +0530119 var omciCC omciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 omciCC.enabled = false
Himani Chawla4d908332020-08-31 12:30:20 +0530121 omciCC.pOnuDeviceEntry = onuDeviceEntry
122 omciCC.deviceID = deviceID
123 omciCC.pBaseDeviceHandler = deviceHandler
124 omciCC.coreProxy = coreProxy
125 omciCC.adapterProxy = adapterProxy
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 omciCC.supportExtMsg = false
127 omciCC.txFrames = 0
128 omciCC.txOnuFrames = 0
129 omciCC.rxFrames = 0
130 omciCC.rxOnuFrames = 0
131 omciCC.rxOnuDiscards = 0
132 omciCC.tid = 0x1
133 omciCC.hpTid = 0x8000
134 omciCC.uploadSequNo = 0
135 omciCC.uploadNoOfCmds = 0
136
137 omciCC.txQueue = list.New()
Himani Chawla6d2ae152020-09-02 13:11:20 +0530138 omciCC.rxSchedulerMap = make(map[uint16]callbackPairEntry)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000139
140 return &omciCC
141}
142
143// Rx handler for omci messages
Himani Chawla6d2ae152020-09-02 13:11:20 +0530144func (oo *omciCC) receiveOnuMessage(ctx context.Context, omciMsg *omci.OMCI) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000145 logger.Debugw("rx-onu-autonomous-message", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000146 "payload": hex.EncodeToString(omciMsg.Payload)})
147 /*
148 msgType = rxFrame.fields["message_type"] //assumed OmciOperationsValue
149 rxOnuFrames++
150
151 switch msgType {
152 case AlarmNotification:
153 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000154 logger.Info("Unhandled: received-onu-alarm-message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000155 // python code was:
156 //if msg_type == EntityOperations.AlarmNotification.value:
157 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Alarm_Notification)
158 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
159 //
160 return errors.New("RxAlarmNotification unimplemented")
161 }
162 case AttributeValueChange:
163 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000164 logger.Info("Unhandled: received-attribute-value-change")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000165 // python code was:
166 //elif msg_type == EntityOperations.AttributeValueChange.value:
167 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.AVC_Notification)
168 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
169 //
170 return errors.New("RxAttributeValueChange unimplemented")
171 }
172 case TestResult:
173 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000174 logger.Info("Unhandled: received-test-result")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000175 // python code was:
176 //elif msg_type == EntityOperations.TestResult.value:
177 // topic = OMCI_CC.event_bus_topic(self._device_id, RxEvent.Test_Result)
178 // self.reactor.callLater(0, self.event_bus.publish, topic, msg)
179 //
180 return errors.New("RxTestResult unimplemented")
181 }
182 default:
183 {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000184 logger.Errorw("rx-onu-unsupported-autonomous-message", log.Fields{"msgType": msgType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000185 rxOnuDiscards++
186 return errors.New("RxOnuMsgType unimplemented")
187 }
188 }
189 */
Himani Chawla4d908332020-08-31 12:30:20 +0530190 return errors.New("receiveOnuMessage unimplemented")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000191}
192
193// Rx handler for onu messages
194// e.g. would call ReceiveOnuMessage() in case of TID=0 or Action=test ...
Himani Chawla6d2ae152020-09-02 13:11:20 +0530195func (oo *omciCC) receiveMessage(ctx context.Context, rxMsg []byte) error {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000196 //logger.Debugw("cc-receive-omci-message", log.Fields{"RxOmciMessage-x2s": hex.EncodeToString(rxMsg)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000197 if len(rxMsg) >= 44 { // then it should normally include the BaseFormat trailer Len
198 // NOTE: autocorrection only valid for OmciBaseFormat, which is not specifically verified here!!!
199 // (am extendedFormat message could be destroyed this way!)
200 trailerLenData := rxMsg[42:44]
201 trailerLen := binary.BigEndian.Uint16(trailerLenData)
mpagenko1cc3cb42020-07-27 15:24:38 +0000202 //logger.Debugw("omci-received-trailer-len", log.Fields{"Length": trailerLen})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000203 if trailerLen != 40 { // invalid base Format entry -> autocorrect
204 binary.BigEndian.PutUint16(rxMsg[42:44], 40)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000205 logger.Debug("cc-corrected-omci-message: trailer len inserted")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000206 }
207 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530208 logger.Errorw("received omci-message too small for OmciBaseFormat - abort", log.Fields{"Length": len(rxMsg)})
Andrea Campanella6515c582020-10-05 11:25:00 +0200209 return fmt.Errorf("rxOmciMessage too small for BaseFormat %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000210 }
211
212 packet := gopacket.NewPacket(rxMsg, omci.LayerTypeOMCI, gopacket.NoCopy)
213 if packet == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200214 logger.Errorw("omci-message could not be decoded", log.Fields{"deviceID": oo.deviceID})
215 return fmt.Errorf("could not decode rxMsg as OMCI %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000216 }
217 omciLayer := packet.Layer(omci.LayerTypeOMCI)
218 if omciLayer == nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200219 logger.Errorw("omci-message could not decode omci layer", log.Fields{"deviceID": oo.deviceID})
220 return fmt.Errorf("could not decode omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000221 }
222 omciMsg, ok := omciLayer.(*omci.OMCI)
223 if !ok {
Andrea Campanella6515c582020-10-05 11:25:00 +0200224 logger.Errorw("omci-message could not assign omci layer", log.Fields{"deviceID": oo.deviceID})
225 return fmt.Errorf("could not assign omci layer %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000226 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000227 logger.Debugw("omci-message-decoded:", log.Fields{"omciMsgType": omciMsg.MessageType,
mpagenko3dbcdd22020-07-22 07:38:45 +0000228 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "DeviceIdent": omciMsg.DeviceIdentifier})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000229 if byte(omciMsg.MessageType) & ^me.AK == 0 {
230 // Not a response
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000231 logger.Debug("RxMsg is no Omci Response Message")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000232 if omciMsg.TransactionID == 0 {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530233 return oo.receiveOnuMessage(ctx, omciMsg)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000234 }
Himani Chawla4d908332020-08-31 12:30:20 +0530235 logger.Errorw("Unexpected TransCorrId != 0 not accepted for autonomous messages",
Andrea Campanella6515c582020-10-05 11:25:00 +0200236 log.Fields{"msgType": omciMsg.MessageType, "payload": hex.EncodeToString(omciMsg.Payload),
237 "deviceID": oo.deviceID})
238 return fmt.Errorf("autonomous Omci Message with TranSCorrId != 0 not acccepted %s", oo.deviceID)
Himani Chawla4d908332020-08-31 12:30:20 +0530239
240 }
241 //logger.Debug("RxMsg is a Omci Response Message: try to schedule it to the requester")
242 oo.mutexRxSchedMap.Lock()
243 rxCallbackEntry, ok := oo.rxSchedulerMap[omciMsg.TransactionID]
244 if ok && rxCallbackEntry.cbFunction != nil {
245 //disadvantage of decoupling: error verification made difficult, but anyway the question is
246 // how to react on erroneous frame reception, maybe can simply be ignored
247 go rxCallbackEntry.cbFunction(omciMsg, &packet, rxCallbackEntry.cbRespChannel)
248 // having posted the response the request is regarded as 'done'
249 delete(oo.rxSchedulerMap, omciMsg.TransactionID)
250 oo.mutexRxSchedMap.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000251 } else {
Himani Chawla4d908332020-08-31 12:30:20 +0530252 oo.mutexRxSchedMap.Unlock()
Andrea Campanella6515c582020-10-05 11:25:00 +0200253 logger.Errorw("omci-message-response for not registered transCorrId", log.Fields{"deviceID": oo.deviceID})
254 return fmt.Errorf("could not find registered response handler tor transCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000255 }
256
257 return nil
258 /* py code was:
259 Receive and OMCI message from the proxy channel to the OLT.
260
261 Call this from your ONU Adapter on a new OMCI Rx on the proxy channel
262 :param msg: (str) OMCI binary message (used as input to Scapy packet decoder)
263 """
264 if not self.enabled:
265 return
266
267 try:
268 now = arrow.utcnow()
269 d = None
270
271 # NOTE: Since we may need to do an independent ME map on a per-ONU basis
272 # save the current value of the entity_id_to_class_map, then
273 # replace it with our custom one before decode, and then finally
274 # restore it later. Tried other ways but really made the code messy.
275 saved_me_map = omci_entities.entity_id_to_class_map
276 omci_entities.entity_id_to_class_map = self._me_map
277
278 try:
279 rx_frame = msg if isinstance(msg, OmciFrame) else OmciFrame(msg)
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000280 self.logger.debug('recv-omci-msg', omci_msg=hexlify(msg))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000281 except KeyError as e:
282 # Unknown, Unsupported, or vendor-specific ME. Key is the unknown classID
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000283 self.logger.debug('frame-decode-key-error', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000284 rx_frame = self._decode_unknown_me(msg)
285 self._rx_unknown_me += 1
286
287 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000288 self.logger.exception('frame-decode', omci_msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000289 return
290
291 finally:
292 omci_entities.entity_id_to_class_map = saved_me_map # Always restore it.
293
294 rx_tid = rx_frame.fields['transaction_id']
295 msg_type = rx_frame.fields['message_type']
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000296 self.logger.debug('Received message for rx_tid', rx_tid = rx_tid, msg_type = msg_type)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000297 # Filter the Test Result frame and route through receive onu
298 # message method.
299 if rx_tid == 0 or msg_type == EntityOperations.TestResult.value:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000300 self.logger.debug('Receive ONU message', rx_tid=0)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000301 return self._receive_onu_message(rx_frame)
302
303 # Previously unreachable if this is the very first round-trip Rx or we
304 # have been running consecutive errors
305 if self._rx_frames == 0 or self._consecutive_errors != 0:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000306 self.logger.debug('Consecutive errors for rx', err = self._consecutive_errors)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000307 self.reactor.callLater(0, self._publish_connectivity_event, True)
308
309 self._rx_frames += 1
310 self._consecutive_errors = 0
311
312 try:
313 high_priority = self._tid_is_high_priority(rx_tid)
314 index = self._get_priority_index(high_priority)
315
316 # (timestamp, defer, frame, timeout, retry, delayedCall)
317 last_tx_tuple = self._tx_request[index]
318
319 if last_tx_tuple is None or \
320 last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id') != rx_tid:
321 # Possible late Rx on a message that timed-out
322 if last_tx_tuple:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000323 self.logger.debug('Unknown message', rx_tid=rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000324 tx_id=last_tx_tuple[OMCI_CC.REQUEST_FRAME].fields.get('transaction_id'))
325 self._rx_unknown_tid += 1
326 self._rx_late += 1
327 return
328
329 ts, d, tx_frame, timeout, retry, dc = last_tx_tuple
330 if dc is not None and not dc.cancelled and not dc.called:
331 dc.cancel()
332
333 _secs = self._update_rx_tx_stats(now, ts)
334
335 # Late arrival already serviced by a timeout?
336 if d.called:
337 self._rx_late += 1
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000338 self.logger.debug('Serviced by timeout. Late arrival', rx_late = self._rx_late)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000339 return
340
341 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000342 self.logger.exception('frame-match', msg=hexlify(msg), e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000343 if d is not None:
344 return d.errback(failure.Failure(e))
345 return
346
347 # Publish Rx event to listeners in a different task
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000348 self.logger.debug('Publish rx event', rx_tid = rx_tid,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000349 tx_tid = tx_frame.fields['transaction_id'])
350 reactor.callLater(0, self._publish_rx_frame, tx_frame, rx_frame)
351
352 # begin success callback chain (will cancel timeout and queue next Tx message)
353 self._rx_response[index] = rx_frame
354 d.callback(rx_frame)
355
356 except Exception as e:
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000357 self.logger.exception('rx-msg', e=e)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000358 */
359}
360
Himani Chawla6d2ae152020-09-02 13:11:20 +0530361/*
362func (oo *omciCC) publishRxResponseFrame(ctx context.Context, txFrame []byte, rxFrame []byte) error {
Himani Chawla4d908332020-08-31 12:30:20 +0530363 return errors.New("publishRxResponseFrame unimplemented")
Himani Chawla6d2ae152020-09-02 13:11:20 +0530364 //def _publish_rx_frame(self, tx_frame, rx_frame):
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000365}
Himani Chawla6d2ae152020-09-02 13:11:20 +0530366*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000367
368//Queue the OMCI Frame for a transmit to the ONU via the proxy_channel
Himani Chawla6d2ae152020-09-02 13:11:20 +0530369func (oo *omciCC) send(ctx context.Context, txFrame []byte, timeout int, retry int, highPrio bool,
370 receiveCallbackPair callbackPair) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000371
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000372 logger.Debugw("register-response-callback:", log.Fields{"for TansCorrId": receiveCallbackPair.cbKey})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000373 // it could be checked, if the callback keay is already registered - but simply overwrite may be acceptable ...
374 oo.mutexRxSchedMap.Lock()
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000375 oo.rxSchedulerMap[receiveCallbackPair.cbKey] = receiveCallbackPair.cbEntry
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000376 oo.mutexRxSchedMap.Unlock()
377
378 //just use a simple list for starting - might need some more effort, especially for multi source write access
379 omciTxRequest := omciTransferStructure{
380 txFrame,
381 timeout,
382 retry,
383 highPrio,
384 }
385 oo.mutexTxQueue.Lock()
386 oo.txQueue.PushBack(omciTxRequest) // enqueue
387 oo.mutexTxQueue.Unlock()
388
389 // for first test just bypass and send directly:
390 go oo.sendNextRequest(ctx)
391 return nil
392}
393
394//Pull next tx request and send it
Himani Chawla6d2ae152020-09-02 13:11:20 +0530395func (oo *omciCC) sendNextRequest(ctx context.Context) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000396 // return errors.New("sendNextRequest unimplemented")
397
398 // just try to get something transferred !!
399 // avoid accessing the txQueue from parallel send requests
400 // block parallel omci send requests at least until SendIAP is 'committed'
401 // that should be feasible for an onu instance as on OMCI anyway window size 1 is assumed
402 oo.mutexTxQueue.Lock()
mpagenkodff5dda2020-08-28 11:52:01 +0000403 defer oo.mutexTxQueue.Unlock()
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000404 for oo.txQueue.Len() > 0 {
405 queueElement := oo.txQueue.Front() // First element
406 omciTxRequest := queueElement.Value.(omciTransferStructure)
407 /* compare olt device handler code:
408 func (dh *DeviceHandler) omciIndication(omciInd *oop.OmciIndication) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000409 logger.Debugw("omci indication", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000410 var deviceType string
411 var deviceID string
412 var proxyDeviceID string
413
414 onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
415
416 if onuInCache, ok := dh.onus.Load(onuKey); !ok {
417
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000418 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 +0000419 ponPort := IntfIDToPortNo(omciInd.GetIntfId(), voltha.Port_PON_OLT)
420 kwargs := make(map[string]interface{})
421 kwargs["onu_id"] = omciInd.OnuId
422 kwargs["parent_port_no"] = ponPort
423
424 onuDevice, err := dh.coreProxy.GetChildDevice(context.TODO(), dh.device.Id, kwargs)
425 if err != nil {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000426 logger.Errorw("onu not found", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId, "error": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000427 return
428 }
429 deviceType = onuDevice.Type
430 deviceID = onuDevice.Id
431 proxyDeviceID = onuDevice.ProxyAddress.DeviceId
432 //if not exist in cache, then add to cache.
433 dh.onus.Store(onuKey, NewOnuDevice(deviceID, deviceType, onuDevice.SerialNumber, omciInd.OnuId, omciInd.IntfId, proxyDeviceID))
434 } else {
435 //found in cache
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000436 logger.Debugw("omci indication for a device in cache.", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000437 deviceType = onuInCache.(*OnuDevice).deviceType
438 deviceID = onuInCache.(*OnuDevice).deviceID
439 proxyDeviceID = onuInCache.(*OnuDevice).proxyDeviceID
440 }
441 */
442 /* and compare onu_adapter py code:
443 omci_msg = InterAdapterOmciMessage(
444 message=bytes(frame),
445 proxy_address=self._proxy_address,
446 connect_status=self._device.connect_status)
447
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000448 self.logger.debug('sent-omci-msg', tid=tx_tid, omci_msg=hexlify(bytes(frame)))
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000449
450 yield self._adapter_proxy.send_inter_adapter_message(
451 msg=omci_msg,
452 type=InterAdapterMessageType.OMCI_REQUEST,
453 from_adapter=self._device.type,
454 to_adapter=self._proxy_address.device_type,
455 to_device_id=self._device_id,
456 proxy_device_id=self._proxy_address.device_id
457 )
458 */
459 device, err := oo.coreProxy.GetDevice(ctx,
460 oo.pBaseDeviceHandler.deviceID, oo.deviceID) //parent, child
461 if err != nil || device == nil {
462 /*TODO: needs to handle error scenarios */
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000463 logger.Errorw("Failed to fetch device", log.Fields{"err": err, "ParentId": oo.pBaseDeviceHandler.deviceID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000464 "ChildId": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200465 return fmt.Errorf("failed to fetch device %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000466 }
467
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000468 logger.Debugw("omci-message-sending", log.Fields{"fromDeviceType": oo.pBaseDeviceHandler.DeviceType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000469 "toDeviceType": oo.pBaseDeviceHandler.ProxyAddressType,
470 "onuDeviceID": oo.deviceID, "proxyDeviceID": oo.pBaseDeviceHandler.ProxyAddressID})
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000471 logger.Debugw("omci-message-to-send:",
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000472 log.Fields{"TxOmciMessage": hex.EncodeToString(omciTxRequest.txFrame)})
473
474 omciMsg := &ic.InterAdapterOmciMessage{Message: omciTxRequest.txFrame}
475 if sendErr := oo.adapterProxy.SendInterAdapterMessage(context.Background(), omciMsg,
476 ic.InterAdapterMessageType_OMCI_REQUEST,
477 //fromType,toType,toDevId, ProxyDevId
478 oo.pBaseDeviceHandler.DeviceType, oo.pBaseDeviceHandler.ProxyAddressType,
479 oo.deviceID, oo.pBaseDeviceHandler.ProxyAddressID, ""); sendErr != nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200480 logger.Errorw("send omci request error", log.Fields{"ChildId": oo.deviceID, "error": sendErr})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000481 return sendErr
482 }
483 oo.txQueue.Remove(queueElement) // Dequeue
484 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000485 return nil
486}
487
Himani Chawla6d2ae152020-09-02 13:11:20 +0530488func (oo *omciCC) getNextTid(highPriority bool) uint16 {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000489 var next uint16
490 if highPriority {
491 oo.mutexTid.Lock()
492 next = oo.hpTid
Himani Chawla4d908332020-08-31 12:30:20 +0530493 oo.hpTid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000494 if oo.hpTid < 0x8000 {
495 oo.hpTid = 0x8000
496 }
497 oo.mutexTid.Unlock()
498 } else {
499 oo.mutexHpTid.Lock()
500 next = oo.tid
Himani Chawla4d908332020-08-31 12:30:20 +0530501 oo.tid++
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000502 if oo.tid >= 0x8000 {
503 oo.tid = 1
504 }
505 oo.mutexHpTid.Unlock()
506 }
507 return next
508}
509
510// ###################################################################################
511// # utility methods provided to work on OMCI messages
512func serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) {
513 omciLayer := &omci.OMCI{
514 TransactionID: tid,
515 MessageType: msgType,
516 }
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000517 return serializeOmciLayer(omciLayer, request)
518}
519
Himani Chawla4d908332020-08-31 12:30:20 +0530520func serializeOmciLayer(aOmciLayer *omci.OMCI, aRequest gopacket.SerializableLayer) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000521 var options gopacket.SerializeOptions
522 options.FixLengths = true
523
524 buffer := gopacket.NewSerializeBuffer()
Himani Chawla4d908332020-08-31 12:30:20 +0530525 err := gopacket.SerializeLayers(buffer, options, aOmciLayer, aRequest)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000526 if err != nil {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000527 logger.Errorw("Could not create goPacket Omci serial buffer", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000528 return nil, err
529 }
530 return buffer.Bytes(), nil
531}
532
Himani Chawla4d908332020-08-31 12:30:20 +0530533/*
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000534func hexEncode(omciPkt []byte) ([]byte, error) {
535 dst := make([]byte, hex.EncodedLen(len(omciPkt)))
536 hex.Encode(dst, omciPkt)
537 return dst, nil
538}
Himani Chawla4d908332020-08-31 12:30:20 +0530539*/
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000540
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000541//supply a response handler for omci response messages to be transferred to the requested FSM
Himani Chawla6d2ae152020-09-02 13:11:20 +0530542func (oo *omciCC) receiveOmciResponse(omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000543
mpagenko3dbcdd22020-07-22 07:38:45 +0000544 logger.Debugw("omci-message-response - transfer on omciRespChannel", log.Fields{"omciMsgType": omciMsg.MessageType,
divyadesai4d299552020-08-18 07:13:49 +0000545 "transCorrId": strconv.FormatInt(int64(omciMsg.TransactionID), 16), "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000546
547 if oo.pOnuDeviceEntry == nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000548 logger.Errorw("Abort receiving OMCI response, DeviceEntryPointer is nil", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000549 "device-id": oo.deviceID})
Andrea Campanella6515c582020-10-05 11:25:00 +0200550 return fmt.Errorf("deviceEntryPointer is nil %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000551 }
552
553 // no further test on SeqNo is done here, assignment from rxScheduler is trusted
554 // MibSync responses are simply transferred via deviceEntry to MibSync, no specific analysis here
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000555 omciRespMsg := Message{
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000556 Type: OMCI,
557 Data: OmciMessage{
558 OmciMsg: omciMsg,
559 OmciPacket: packet,
560 },
561 }
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000562 //logger.Debugw("Message to be sent into channel:", log.Fields{"mibSyncMsg": mibSyncMsg})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000563 respChan <- omciRespMsg
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000564
565 return nil
566}
567
Himani Chawla6d2ae152020-09-02 13:11:20 +0530568func (oo *omciCC) sendMibReset(ctx context.Context, timeout int, highPrio bool) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000569
divyadesai4d299552020-08-18 07:13:49 +0000570 logger.Debugw("send MibReset-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000571 request := &omci.MibResetRequest{
572 MeBasePacket: omci.MeBasePacket{
573 EntityClass: me.OnuDataClassID,
574 },
575 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530576 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000577 pkt, err := serialize(omci.MibResetRequestType, request, tid)
578 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000579 logger.Errorw("Cannot serialize MibResetRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000580 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000581 return err
582 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530583 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000584 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530585 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000586 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530587 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000588}
589
Himani Chawla6d2ae152020-09-02 13:11:20 +0530590func (oo *omciCC) sendReboot(ctx context.Context, timeout int, highPrio bool, responseChannel chan Message) error {
divyadesai4d299552020-08-18 07:13:49 +0000591 logger.Debugw("send Reboot-msg to:", log.Fields{"device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300592 request := &omci.RebootRequest{
593 MeBasePacket: omci.MeBasePacket{
594 EntityClass: me.OnuGClassID,
595 },
596 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530597 tid := oo.getNextTid(highPrio)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300598 pkt, err := serialize(omci.RebootRequestType, request, tid)
599 if err != nil {
600 logger.Errorw("Cannot serialize RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000601 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300602 return err
603 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530604 omciRxCallbackPair := callbackPair{
ozgecanetsiae11479f2020-07-06 09:44:47 +0300605 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530606 cbEntry: callbackPairEntry{oo.pOnuDeviceEntry.omciRebootMessageReceivedChannel, oo.receiveOmciResponse},
ozgecanetsiae11479f2020-07-06 09:44:47 +0300607 }
608
Himani Chawla6d2ae152020-09-02 13:11:20 +0530609 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
ozgecanetsiae11479f2020-07-06 09:44:47 +0300610 if err != nil {
611 logger.Errorw("Cannot send RebootRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000612 "Err": err, "device-id": oo.deviceID})
ozgecanetsiae11479f2020-07-06 09:44:47 +0300613 return err
614 }
615 err = oo.pOnuDeviceEntry.waitForRebootResponse(responseChannel)
616 if err != nil {
Andrea Campanella6515c582020-10-05 11:25:00 +0200617 logger.Errorw("aborting ONU Reboot!", log.Fields{
618 "Err": err, "device-id": oo.deviceID})
Himani Chawla4d908332020-08-31 12:30:20 +0530619 _ = oo.pOnuDeviceEntry.pMibDownloadFsm.pFsm.Event("reset")
ozgecanetsiae11479f2020-07-06 09:44:47 +0300620 return err
621 }
622 return nil
623}
624
Himani Chawla6d2ae152020-09-02 13:11:20 +0530625func (oo *omciCC) sendMibUpload(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000626 logger.Debugw("send MibUpload-msg to:", log.Fields{"device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000627 request := &omci.MibUploadRequest{
628 MeBasePacket: omci.MeBasePacket{
629 EntityClass: me.OnuDataClassID,
630 },
631 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530632 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000633 pkt, err := serialize(omci.MibUploadRequestType, request, tid)
634 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000635 logger.Errorw("Cannot serialize MibUploadRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000636 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000637 return err
638 }
639 oo.uploadSequNo = 0
640 oo.uploadNoOfCmds = 0
641
Himani Chawla6d2ae152020-09-02 13:11:20 +0530642 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000643 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530644 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000645 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530646 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000647}
648
Himani Chawla6d2ae152020-09-02 13:11:20 +0530649func (oo *omciCC) sendMibUploadNext(ctx context.Context, timeout int, highPrio bool) error {
divyadesai4d299552020-08-18 07:13:49 +0000650 logger.Debugw("send MibUploadNext-msg to:", log.Fields{"device-id": oo.deviceID, "uploadSequNo": oo.uploadSequNo})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000651 request := &omci.MibUploadNextRequest{
652 MeBasePacket: omci.MeBasePacket{
653 EntityClass: me.OnuDataClassID,
654 },
655 CommandSequenceNumber: oo.uploadSequNo,
656 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530657 tid := oo.getNextTid(highPrio)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000658 pkt, err := serialize(omci.MibUploadNextRequestType, request, tid)
659 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000660 logger.Errorw("Cannot serialize MibUploadNextRequest", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000661 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000662 return err
663 }
664 oo.uploadSequNo++
665
Himani Chawla6d2ae152020-09-02 13:11:20 +0530666 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000667 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530668 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000669 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530670 return oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000671}
672
Himani Chawla6d2ae152020-09-02 13:11:20 +0530673func (oo *omciCC) sendCreateGalEthernetProfile(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
674 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000675 logger.Debugw("send GalEnetProfile-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000676 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000677
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000678 meParams := me.ParamData{
679 EntityID: galEthernetEID,
680 Attributes: me.AttributeValueMap{"MaximumGemPayloadSize": maxGemPayloadSize},
681 }
682 meInstance, omciErr := me.NewGalEthernetProfile(meParams)
683 if omciErr.GetError() == nil {
684 //all setByCreate parameters already set, no default option required ...
685 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
686 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000687 logger.Errorw("Cannot encode GalEnetProfileInstance for 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
692 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
693 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000694 logger.Errorw("Cannot serialize GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000695 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000696 return nil
697 }
698
Himani Chawla6d2ae152020-09-02 13:11:20 +0530699 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000700 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530701 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000702 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530703 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000704 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000705 logger.Errorw("Cannot send GalEnetProfile create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000706 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000707 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000708 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000709 logger.Debug("send GalEnetProfile-Create-msg done")
710 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000711 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000712 logger.Errorw("Cannot generate GalEnetProfileInstance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000713 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000714 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000715}
716
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000717// might be needed to extend for parameter arguments, here just for setting the ConnectivityMode!!
Himani Chawla6d2ae152020-09-02 13:11:20 +0530718func (oo *omciCC) sendSetOnu2g(ctx context.Context, timeout int, highPrio bool) *me.ManagedEntity {
719 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000720 logger.Debugw("send ONU2-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000721 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000722
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000723 // ONU-G ME-ID is defined to be 0, but we could verify, if the ONU really supports the desired
724 // connectivity mode 5 (in ConnCap)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000725 // By now we just use fix values to fire - this is anyway what the python adapter does
726 // read ONU-2G from DB ???? //TODO!!!
727 meParams := me.ParamData{
728 EntityID: 0,
729 Attributes: me.AttributeValueMap{"CurrentConnectivityMode": connectivityModeValue},
730 }
731 meInstance, omciErr := me.NewOnu2G(meParams)
732 if omciErr.GetError() == nil {
733 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
734 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000735 logger.Errorw("Cannot encode ONU2-G instance for 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
740 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
741 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000742 logger.Errorw("Cannot serialize ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000743 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000744 return nil
745 }
746
Himani Chawla6d2ae152020-09-02 13:11:20 +0530747 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000748 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530749 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000750 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530751 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000752 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000753 logger.Errorw("Cannot send ONU2-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000754 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000755 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000756 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000757 logger.Debug("send ONU2-G-Set-msg done")
758 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000759 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000760 logger.Errorw("Cannot generate ONU2-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000761 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000762 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000763}
764
Himani Chawla6d2ae152020-09-02 13:11:20 +0530765func (oo *omciCC) sendCreateMBServiceProfile(ctx context.Context,
766 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
767 tid := oo.getNextTid(highPrio)
Himani Chawla4d908332020-08-31 12:30:20 +0530768 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000769 logger.Debugw("send MBSP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000770 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000771
772 meParams := me.ParamData{
773 EntityID: instID,
774 Attributes: me.AttributeValueMap{
775 "Priority": 0x8000,
776 "MaxAge": 20 * 256, //20s
777 "HelloTime": 2 * 256, //2s
778 "ForwardDelay": 15 * 256, //15s
779 //note: DynamicFilteringAgeingTime is taken from omci lib default as
780 // which is obviously different from default value used in python lib,
781 // where the value seems to be 0 (ONU defined) - to be considered in case of test artifacts ...
782 },
783 }
784
785 meInstance, omciErr := me.NewMacBridgeServiceProfile(meParams)
786 if omciErr.GetError() == nil {
787 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
788 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
789 omci.TransactionID(tid), omci.AddDefaults(true))
790 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000791 logger.Errorw("Cannot encode MBSP for 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
796 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
797 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000798 logger.Errorw("Cannot serialize MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000799 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000800 return nil
801 }
802
Himani Chawla6d2ae152020-09-02 13:11:20 +0530803 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000804 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530805 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000806 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530807 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000808 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000809 logger.Errorw("Cannot send MBSP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000810 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000811 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000812 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000813 logger.Debug("send MBSP-Create-msg done")
814 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000815 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000816 logger.Errorw("Cannot generate MBSP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000817 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000818 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000819}
820
Himani Chawla6d2ae152020-09-02 13:11:20 +0530821func (oo *omciCC) sendCreateMBPConfigData(ctx context.Context,
822 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
823 tid := oo.getNextTid(highPrio)
Himani Chawla26e555c2020-08-31 12:30:20 +0530824 instID := macBridgePortAniEID + aPUniPort.entityID
divyadesai4d299552020-08-18 07:13:49 +0000825 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000826 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000827
828 meParams := me.ParamData{
829 EntityID: instID,
830 Attributes: me.AttributeValueMap{
Himani Chawla4d908332020-08-31 12:30:20 +0530831 "BridgeIdPointer": macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo),
832 "PortNum": aPUniPort.macBpNo,
833 "TpType": uint8(aPUniPort.portType),
Himani Chawla26e555c2020-08-31 12:30:20 +0530834 "TpPointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000835 },
836 }
837 meInstance, omciErr := me.NewMacBridgePortConfigurationData(meParams)
838 if omciErr.GetError() == nil {
839 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
840 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
841 omci.TransactionID(tid), omci.AddDefaults(true))
842 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000843 logger.Errorw("Cannot encode MBPCD for 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
848 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
849 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000850 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000851 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000852 return nil
853 }
854
Himani Chawla6d2ae152020-09-02 13:11:20 +0530855 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000856 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530857 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000858 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530859 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000860 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000861 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000862 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000863 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000864 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000865 logger.Debug("send MBPCD-Create-msg done")
866 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000867 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000868 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000869 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000870 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000871}
872
Himani Chawla6d2ae152020-09-02 13:11:20 +0530873func (oo *omciCC) sendCreateEVTOConfigData(ctx context.Context,
874 aPUniPort *onuUniPort, timeout int, highPrio bool) *me.ManagedEntity {
875 tid := oo.getNextTid(highPrio)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000876 //same entityId is used as for MBSP (see there), but just arbitrary ...
Himani Chawla4d908332020-08-31 12:30:20 +0530877 instID := macBridgeServiceProfileEID + uint16(aPUniPort.macBpNo)
divyadesai4d299552020-08-18 07:13:49 +0000878 logger.Debugw("send EVTOCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000879 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(instID), 16)})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000880
881 // compare python adapter code WA VOL-1311: this is not done here!
882 // (setting TPID values for the create would probably anyway be ignored by the omci lib)
883 // but perhaps we have to be aware of possible problems at get(Next) Request handling for EVTOOCD tables later ...
884 assType := uint8(2) // default AssociationType is PPTPEthUni
Himani Chawla6d2ae152020-09-02 13:11:20 +0530885 if aPUniPort.portType == uniVEIP {
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000886 assType = uint8(10) // for VEIP
887 }
888 meParams := me.ParamData{
889 EntityID: instID,
890 Attributes: me.AttributeValueMap{
891 "AssociationType": assType,
Himani Chawla26e555c2020-08-31 12:30:20 +0530892 "AssociatedMePointer": aPUniPort.entityID,
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000893 },
894 }
895 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(meParams)
896 if omciErr.GetError() == nil {
897 //all setByCreate parameters already set, no default option required ...
898 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType, omci.TransactionID(tid))
899 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000900 logger.Errorw("Cannot encode EVTOCD for 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
905 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
906 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000907 logger.Errorw("Cannot serialize EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000908 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000909 return nil
910 }
911
Himani Chawla6d2ae152020-09-02 13:11:20 +0530912 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000913 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530914 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibDownloadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000915 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530916 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000917 if err != nil {
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000918 logger.Errorw("Cannot send EVTOCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000919 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000920 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +0000921 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000922 logger.Debug("send EVTOCD-Create-msg done")
923 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000924 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000925 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000926 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000927 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000928}
929
Himani Chawla6d2ae152020-09-02 13:11:20 +0530930func (oo *omciCC) sendSetOnuGLS(ctx context.Context, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000931 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530932 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000933 logger.Debugw("send ONU-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000934 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000935
936 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
937 meParams := me.ParamData{
938 EntityID: 0,
939 Attributes: requestedAttributes,
940 }
941 meInstance, omciErr := me.NewOnuG(meParams)
942 if omciErr.GetError() == nil {
943 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
944 if err != nil {
945 logger.Errorw("Cannot encode ONU-G instance for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
951 if err != nil {
952 logger.Errorw("Cannot serialize ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000953 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000954 return nil
955 }
956
Himani Chawla6d2ae152020-09-02 13:11:20 +0530957 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000958 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +0530959 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000960 }
Himani Chawla6d2ae152020-09-02 13:11:20 +0530961 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000962 if err != nil {
963 logger.Errorw("Cannot send ONU-G set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000964 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000965 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000966 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000967 logger.Debug("send ONU-G-Set-msg done")
968 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000969 }
mpagenko3dbcdd22020-07-22 07:38:45 +0000970 logger.Errorw("Cannot generate ONU-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000971 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +0000972 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000973}
974
Himani Chawla6d2ae152020-09-02 13:11:20 +0530975func (oo *omciCC) sendSetUniGLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000976 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +0530977 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +0000978 logger.Debugw("send UNI-G-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +0000979 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000980
981 // UNI-G ME-ID is taken from Mib Upload stored OnuUniPort instance (argument)
982 meParams := me.ParamData{
983 EntityID: aInstNo,
984 Attributes: requestedAttributes,
985 }
986 meInstance, omciErr := me.NewUniG(meParams)
987 if omciErr.GetError() == nil {
988 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
989 if err != nil {
990 logger.Errorw("Cannot encode UNI-G instance for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
996 if err != nil {
997 logger.Errorw("Cannot serialize UNI-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +0000998 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000999 return nil
1000 }
1001
Himani Chawla6d2ae152020-09-02 13:11:20 +05301002 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001003 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301004 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001005 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301006 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001007 if err != nil {
1008 logger.Errorw("Cannot send UNIG-G-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001009 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001010 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001011 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001012 logger.Debug("send UNI-G-Set-msg done")
1013 return meInstance
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001014 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001015 logger.Errorw("Cannot generate UNI-G", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001016 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001017 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001018}
1019
Himani Chawla6d2ae152020-09-02 13:11:20 +05301020func (oo *omciCC) sendSetVeipLS(ctx context.Context, aInstNo uint16, timeout int,
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001021 highPrio bool, requestedAttributes me.AttributeValueMap, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301022 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001023 logger.Debugw("send VEIP-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001024 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001025
1026 // ONU-G ME-ID is defined to be 0, no need to perform a DB lookup
1027 meParams := me.ParamData{
1028 EntityID: aInstNo,
1029 Attributes: requestedAttributes,
1030 }
1031 meInstance, omciErr := me.NewVirtualEthernetInterfacePoint(meParams)
1032 if omciErr.GetError() == nil {
1033 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1034 if err != nil {
1035 logger.Errorw("Cannot encode VEIP instance for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1041 if err != nil {
1042 logger.Errorw("Cannot serialize VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001043 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001044 return nil
1045 }
1046
Himani Chawla6d2ae152020-09-02 13:11:20 +05301047 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001048 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301049 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001050 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301051 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001052 if err != nil {
1053 logger.Errorw("Cannot send VEIP-Set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001054 "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001055 return nil
Holger Hildebrandtccd390c2020-05-29 13:49:04 +00001056 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001057 logger.Debug("send VEIP-Set-msg done")
1058 return meInstance
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001059 }
mpagenko3dbcdd22020-07-22 07:38:45 +00001060 logger.Errorw("Cannot generate VEIP", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001061 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001062 return nil
Holger Hildebrandtdd23cc22020-05-19 13:32:18 +00001063}
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001064
Himani Chawla6d2ae152020-09-02 13:11:20 +05301065func (oo *omciCC) sendGetMe(ctx context.Context, classID me.ClassID, entityID uint16, requestedAttributes me.AttributeValueMap,
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001066 timeout int, highPrio bool) *me.ManagedEntity {
1067
Himani Chawla6d2ae152020-09-02 13:11:20 +05301068 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001069 logger.Debugw("send get-request-msg", log.Fields{"classID": classID, "device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001070 "SequNo": strconv.FormatInt(int64(tid), 16)})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001071
1072 meParams := me.ParamData{
1073 EntityID: entityID,
1074 Attributes: requestedAttributes,
1075 }
1076 meInstance, omciErr := me.LoadManagedEntityDefinition(classID, meParams)
1077 if omciErr.GetError() == nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301078 meClassIDName := meInstance.GetName()
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001079 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.GetRequestType, omci.TransactionID(tid))
1080 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301081 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 +00001082 return nil
1083 }
1084 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1085 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301086 logger.Errorw("Cannot serialize get-request", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001087 return nil
1088 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301089 omciRxCallbackPair := callbackPair{
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001090 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301091 cbEntry: callbackPairEntry{(*oo.pOnuDeviceEntry).pMibUploadFsm.commChan, oo.receiveOmciResponse},
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001092 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301093 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001094 if err != nil {
Himani Chawla4d908332020-08-31 12:30:20 +05301095 logger.Errorw("Cannot send get-request-msg", log.Fields{"meClassIDName": meClassIDName, "Err": err, "device-id": oo.deviceID})
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001096 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001097 }
Himani Chawla4d908332020-08-31 12:30:20 +05301098 logger.Debugw("send get-request-msg done", log.Fields{"meClassIDName": meClassIDName, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001099 return meInstance
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001100 }
divyadesai4d299552020-08-18 07:13:49 +00001101 logger.Errorw("Cannot generate meDefinition", log.Fields{"classID": classID, "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001102 return nil
1103}
1104
Himani Chawla6d2ae152020-09-02 13:11:20 +05301105func (oo *omciCC) sendCreateDot1PMapper(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001106 aInstID uint16, rxChan chan Message) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301107 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001108 logger.Debugw("send .1pMapper-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001109 "SequNo": strconv.FormatInt(int64(tid), 16), "InstId": strconv.FormatInt(int64(aInstID), 16)})
1110
1111 meParams := me.ParamData{
1112 EntityID: aInstID,
1113 Attributes: me.AttributeValueMap{},
1114 }
1115 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(meParams)
1116 if omciErr.GetError() == nil {
1117 //we have to set all 'untouched' parameters to default by some additional option parameter!!
1118 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1119 omci.TransactionID(tid), omci.AddDefaults(true))
1120 if err != nil {
1121 logger.Errorw("Cannot encode .1pMapper for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1127 if err != nil {
1128 logger.Errorw("Cannot serialize .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001129 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001130 return nil
1131 }
1132
Himani Chawla6d2ae152020-09-02 13:11:20 +05301133 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001134 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301135 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001136 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301137 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001138 if err != nil {
1139 logger.Errorw("Cannot send .1pMapper create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001140 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001141 return nil
1142 }
1143 logger.Debug("send .1pMapper-create-msg done")
1144 return meInstance
1145 }
1146 logger.Errorw("Cannot generate .1pMapper", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001147 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001148 return nil
1149}
1150
Himani Chawla6d2ae152020-09-02 13:11:20 +05301151func (oo *omciCC) sendCreateMBPConfigDataVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001152 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301153 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001154 logger.Debugw("send MBPCD-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001155 "SequNo": strconv.FormatInt(int64(tid), 16),
1156 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1157
1158 meInstance, omciErr := me.NewMacBridgePortConfigurationData(params[0])
1159 if omciErr.GetError() == nil {
1160 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1161 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1162 omci.TransactionID(tid), omci.AddDefaults(true))
1163 if err != nil {
1164 logger.Errorw("Cannot encode MBPCD for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1170 if err != nil {
1171 logger.Errorw("Cannot serialize MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001172 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001173 return nil
1174 }
1175
Himani Chawla6d2ae152020-09-02 13:11:20 +05301176 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001177 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301178 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001179 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301180 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001181 if err != nil {
1182 logger.Errorw("Cannot send MBPCD create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001183 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001184 return nil
1185 }
1186 logger.Debug("send MBPCD-Create-msg done")
1187 return meInstance
1188 }
1189 logger.Errorw("Cannot generate MBPCD Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001190 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001191 return nil
1192}
1193
Himani Chawla6d2ae152020-09-02 13:11:20 +05301194func (oo *omciCC) sendCreateGemNCTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001195 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301196 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001197 logger.Debugw("send GemNCTP-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001198 "SequNo": strconv.FormatInt(int64(tid), 16),
1199 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1200
1201 meInstance, omciErr := me.NewGemPortNetworkCtp(params[0])
1202 if omciErr.GetError() == nil {
1203 //obviously we have to set all 'untouched' parameters to default by some additional option parameter!!
1204 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1205 omci.TransactionID(tid), omci.AddDefaults(true))
1206 if err != nil {
1207 logger.Errorw("Cannot encode GemNCTP for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1213 if err != nil {
1214 logger.Errorw("Cannot serialize GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001215 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001216 return nil
1217 }
1218
Himani Chawla6d2ae152020-09-02 13:11:20 +05301219 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001220 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301221 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001222 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301223 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001224 if err != nil {
1225 logger.Errorw("Cannot send GemNCTP create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001226 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001227 return nil
1228 }
1229 logger.Debug("send GemNCTP-Create-msg done")
1230 return meInstance
1231 }
1232 logger.Errorw("Cannot generate GemNCTP Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001233 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001234 return nil
1235}
1236
Himani Chawla6d2ae152020-09-02 13:11:20 +05301237func (oo *omciCC) sendCreateGemIWTPVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001238 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301239 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001240 logger.Debugw("send GemIwTp-Create-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001241 "SequNo": strconv.FormatInt(int64(tid), 16),
1242 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1243
1244 meInstance, omciErr := me.NewGemInterworkingTerminationPoint(params[0])
1245 if omciErr.GetError() == nil {
1246 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1247 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1248 omci.TransactionID(tid))
1249 if err != nil {
1250 logger.Errorw("Cannot encode GemIwTp for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1256 if err != nil {
1257 logger.Errorw("Cannot serialize GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001258 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001259 return nil
1260 }
1261
Himani Chawla6d2ae152020-09-02 13:11:20 +05301262 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001263 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301264 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001265 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301266 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001267 if err != nil {
1268 logger.Errorw("Cannot send GemIwTp create", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001269 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001270 return nil
1271 }
1272 logger.Debug("send GemIwTp-Create-msg done")
1273 return meInstance
1274 }
1275 logger.Errorw("Cannot generate GemIwTp Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001276 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001277 return nil
1278}
1279
Himani Chawla6d2ae152020-09-02 13:11:20 +05301280func (oo *omciCC) sendSetTcontVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001281 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301282 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001283 logger.Debugw("send TCont-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001284 "SequNo": strconv.FormatInt(int64(tid), 16),
1285 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1286
1287 meInstance, omciErr := me.NewTCont(params[0])
1288 if omciErr.GetError() == nil {
1289 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1290 if err != nil {
1291 logger.Errorw("Cannot encode TCont for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1297 if err != nil {
1298 logger.Errorw("Cannot serialize TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001299 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001300 return nil
1301 }
1302
Himani Chawla6d2ae152020-09-02 13:11:20 +05301303 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001304 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301305 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001306 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301307 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001308 if err != nil {
1309 logger.Errorw("Cannot send TCont set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001310 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001311 return nil
1312 }
1313 logger.Debug("send TCont-set msg done")
1314 return meInstance
1315 }
1316 logger.Errorw("Cannot generate TCont Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001317 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001318 return nil
1319}
1320
Himani Chawla6d2ae152020-09-02 13:11:20 +05301321func (oo *omciCC) sendSetPrioQueueVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001322 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301323 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001324 logger.Debugw("send PrioQueue-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001325 "SequNo": strconv.FormatInt(int64(tid), 16),
1326 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1327
1328 meInstance, omciErr := me.NewPriorityQueue(params[0])
1329 if omciErr.GetError() == nil {
1330 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1331 if err != nil {
1332 logger.Errorw("Cannot encode PrioQueue for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1338 if err != nil {
1339 logger.Errorw("Cannot serialize PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001340 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001341 return nil
1342 }
1343
Himani Chawla6d2ae152020-09-02 13:11:20 +05301344 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001345 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301346 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001347 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301348 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001349 if err != nil {
1350 logger.Errorw("Cannot send PrioQueue set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001351 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001352 return nil
1353 }
1354 logger.Debug("send PrioQueue-set msg done")
1355 return meInstance
1356 }
1357 logger.Errorw("Cannot generate PrioQueue Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001358 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001359 return nil
1360}
1361
Himani Chawla6d2ae152020-09-02 13:11:20 +05301362func (oo *omciCC) sendSetDot1PMapperVar(ctx context.Context, timeout int, highPrio bool,
mpagenko3dbcdd22020-07-22 07:38:45 +00001363 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301364 tid := oo.getNextTid(highPrio)
divyadesai4d299552020-08-18 07:13:49 +00001365 logger.Debugw("send 1PMapper-Set-msg:", log.Fields{"device-id": oo.deviceID,
mpagenko3dbcdd22020-07-22 07:38:45 +00001366 "SequNo": strconv.FormatInt(int64(tid), 16),
1367 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1368
1369 meInstance, omciErr := me.NewIeee8021PMapperServiceProfile(params[0])
1370 if omciErr.GetError() == nil {
1371 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1372 if err != nil {
1373 logger.Errorw("Cannot encode 1PMapper for 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 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1379 if err != nil {
1380 logger.Errorw("Cannot serialize 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001381 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001382 return nil
1383 }
1384
Himani Chawla6d2ae152020-09-02 13:11:20 +05301385 omciRxCallbackPair := callbackPair{
mpagenko3dbcdd22020-07-22 07:38:45 +00001386 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301387 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenko3dbcdd22020-07-22 07:38:45 +00001388 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301389 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenko3dbcdd22020-07-22 07:38:45 +00001390 if err != nil {
1391 logger.Errorw("Cannot send 1PMapper set", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001392 "Err": err, "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001393 return nil
1394 }
1395 logger.Debug("send 1PMapper-set msg done")
1396 return meInstance
1397 }
1398 logger.Errorw("Cannot generate 1PMapper Instance", log.Fields{
divyadesai4d299552020-08-18 07:13:49 +00001399 "Err": omciErr.GetError(), "device-id": oo.deviceID})
mpagenko3dbcdd22020-07-22 07:38:45 +00001400 return nil
Holger Hildebrandtc54939a2020-06-17 08:14:27 +00001401}
mpagenkodff5dda2020-08-28 11:52:01 +00001402
Himani Chawla6d2ae152020-09-02 13:11:20 +05301403func (oo *omciCC) sendCreateVtfdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001404 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301405 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001406 logger.Debugw("send VTFD-Create-msg:", log.Fields{"device-id": oo.deviceID,
1407 "SequNo": strconv.FormatInt(int64(tid), 16),
1408 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1409
1410 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1411 if omciErr.GetError() == nil {
1412 //all SetByCreate Parameters (assumed to be) set here, for optimisation no 'AddDefaults'
1413 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.CreateRequestType,
1414 omci.TransactionID(tid))
1415 if err != nil {
1416 logger.Errorw("Cannot encode VTFD for create", log.Fields{
1417 "Err": err, "device-id": oo.deviceID})
1418 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1419 // return (dual format) error code that can be used at caller for immediate error treatment
1420 // (relevant to all used sendXX() methods and their error conditions)
1421 return nil
1422 }
1423
1424 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1425 if err != nil {
1426 logger.Errorw("Cannot serialize VTFD create", log.Fields{
1427 "Err": err, "device-id": oo.deviceID})
1428 return nil
1429 }
1430
Himani Chawla6d2ae152020-09-02 13:11:20 +05301431 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001432 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301433 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001434 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301435 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001436 if err != nil {
1437 logger.Errorw("Cannot send VTFD create", log.Fields{
1438 "Err": err, "device-id": oo.deviceID})
1439 return nil
1440 }
1441 logger.Debug("send VTFD-Create-msg done")
1442 return meInstance
1443 }
1444 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1445 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1446 return nil
1447}
1448
Holger Hildebrandt394c5522020-09-11 11:23:01 +00001449func (oo *omciCC) sendSetVtfdVar(ctx context.Context, timeout int, highPrio bool,
1450 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
1451 tid := oo.getNextTid(highPrio)
1452 logger.Debugw("send VTFD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1453 "SequNo": strconv.FormatInt(int64(tid), 16),
1454 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1455
1456 meInstance, omciErr := me.NewVlanTaggingFilterData(params[0])
1457 if omciErr.GetError() == nil {
1458 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType,
1459 omci.TransactionID(tid))
1460 if err != nil {
1461 logger.Errorw("Cannot encode VTFD for set", log.Fields{
1462 "Err": err, "device-id": oo.deviceID})
1463 //TODO!!: refactoring improvement requested, here as an example for [VOL-3457]:
1464 // return (dual format) error code that can be used at caller for immediate error treatment
1465 // (relevant to all used sendXX() methods and their error conditions)
1466 return nil
1467 }
1468
1469 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1470 if err != nil {
1471 logger.Errorw("Cannot serialize VTFD set", log.Fields{
1472 "Err": err, "device-id": oo.deviceID})
1473 return nil
1474 }
1475
1476 omciRxCallbackPair := callbackPair{
1477 cbKey: tid,
1478 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
1479 }
1480 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
1481 if err != nil {
1482 logger.Errorw("Cannot send VTFD set", log.Fields{
1483 "Err": err, "device-id": oo.deviceID})
1484 return nil
1485 }
1486 logger.Debug("send VTFD-Set-msg done")
1487 return meInstance
1488 }
1489 logger.Errorw("Cannot generate VTFD Instance", log.Fields{
1490 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1491 return nil
1492}
1493
Himani Chawla6d2ae152020-09-02 13:11:20 +05301494func (oo *omciCC) sendSetEvtocdVar(ctx context.Context, timeout int, highPrio bool,
mpagenkodff5dda2020-08-28 11:52:01 +00001495 rxChan chan Message, params ...me.ParamData) *me.ManagedEntity {
Himani Chawla6d2ae152020-09-02 13:11:20 +05301496 tid := oo.getNextTid(highPrio)
mpagenkodff5dda2020-08-28 11:52:01 +00001497 logger.Debugw("send EVTOCD-Set-msg:", log.Fields{"device-id": oo.deviceID,
1498 "SequNo": strconv.FormatInt(int64(tid), 16),
1499 "InstId": strconv.FormatInt(int64(params[0].EntityID), 16)})
1500
1501 meInstance, omciErr := me.NewExtendedVlanTaggingOperationConfigurationData(params[0])
1502 if omciErr.GetError() == nil {
1503 omciLayer, msgLayer, err := omci.EncodeFrame(meInstance, omci.SetRequestType, omci.TransactionID(tid))
1504 if err != nil {
1505 logger.Errorw("Cannot encode EVTOCD for set", log.Fields{
1506 "Err": err, "device-id": oo.deviceID})
1507 return nil
1508 }
1509
1510 pkt, err := serializeOmciLayer(omciLayer, msgLayer)
1511 if err != nil {
1512 logger.Errorw("Cannot serialize EVTOCD set", log.Fields{
1513 "Err": err, "device-id": oo.deviceID})
1514 return nil
1515 }
1516
Himani Chawla6d2ae152020-09-02 13:11:20 +05301517 omciRxCallbackPair := callbackPair{
mpagenkodff5dda2020-08-28 11:52:01 +00001518 cbKey: tid,
Himani Chawla6d2ae152020-09-02 13:11:20 +05301519 cbEntry: callbackPairEntry{rxChan, oo.receiveOmciResponse},
mpagenkodff5dda2020-08-28 11:52:01 +00001520 }
Himani Chawla6d2ae152020-09-02 13:11:20 +05301521 err = oo.send(ctx, pkt, timeout, 0, highPrio, omciRxCallbackPair)
mpagenkodff5dda2020-08-28 11:52:01 +00001522 if err != nil {
1523 logger.Errorw("Cannot send EVTOCD set", log.Fields{
1524 "Err": err, "device-id": oo.deviceID})
1525 return nil
1526 }
1527 logger.Debug("send EVTOCD-set msg done")
1528 return meInstance
1529 }
1530 logger.Errorw("Cannot generate EVTOCD Instance", log.Fields{
1531 "Err": omciErr.GetError(), "device-id": oo.deviceID})
1532 return nil
1533}