blob: d74ef923642de6e53921908e613af44a94a036c3 [file] [log] [blame]
Shad Ansari2eac6a42018-11-14 22:35:39 -08001/*
2 * Copyright 2018-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
17package core
18
Shad Ansari45806172018-11-19 17:13:08 -080019import (
Shad Ansaria5c79892018-11-29 16:32:59 -080020 "bytes"
21 "encoding/binary"
22
Keita NISHIMOTO2b694202018-12-18 07:30:55 +090023 "context"
24 "errors"
Shad Ansaria3384b02019-01-03 15:11:11 -080025 "time"
26
27 "gerrit.opencord.org/voltha-bbsim/common/logger"
28 "gerrit.opencord.org/voltha-bbsim/device"
29 "gerrit.opencord.org/voltha-bbsim/protos"
Shad Ansari45806172018-11-19 17:13:08 -080030)
31
Shad Ansaria5c79892018-11-29 16:32:59 -080032//
33// OMCI definitions
34//
35
36// OmciMsgType represents a OMCI message-type
37type OmciMsgType byte
38
39const (
40 // Message Types
41 _ = iota
42 Create OmciMsgType = 4
43 Delete OmciMsgType = 6
44 Set OmciMsgType = 8
45 Get OmciMsgType = 9
46 GetAllAlarms OmciMsgType = 11
47 GetAllAlarmsNext OmciMsgType = 12
48 MibUpload OmciMsgType = 13
49 MibUploadNext OmciMsgType = 14
50 MibReset OmciMsgType = 15
51 AlarmNotification OmciMsgType = 16
52 AttributeValueChange OmciMsgType = 17
53 Test OmciMsgType = 18
54 StartSoftwareDownload OmciMsgType = 19
55 DownloadSection OmciMsgType = 20
56 EndSoftwareDownload OmciMsgType = 21
57 ActivateSoftware OmciMsgType = 22
58 CommitSoftware OmciMsgType = 23
59 SynchronizeTime OmciMsgType = 24
60 Reboot OmciMsgType = 25
61 GetNext OmciMsgType = 26
62 TestResult OmciMsgType = 27
63 GetCurrentData OmciMsgType = 28
64 SetTable OmciMsgType = 29 // Defined in Extended Message Set Only
65)
66
67const (
68 // Managed Entity Class values
69 GEMPortNetworkCTP OmciClass = 268
70)
71
72// OMCI Managed Entity Class
73type OmciClass uint16
74
75// OMCI Message Identifier
76type OmciMessageIdentifier struct {
77 Class OmciClass
78 Instance uint16
79}
80
81type OmciContent [32]byte
82
83type OmciMessage struct {
84 TransactionId uint16
85 MessageType OmciMsgType
86 DeviceId uint8
87 MessageId OmciMessageIdentifier
88 Content OmciContent
Shad Ansari2eac6a42018-11-14 22:35:39 -080089}
90
Shad Ansaria3384b02019-01-03 15:11:11 -080091const NumMibUploads byte = 18
Shad Ansari45806172018-11-19 17:13:08 -080092
93type OnuKey struct {
94 IntfId, OnuId uint32
95}
96
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +090097type OnuOmciState struct {
Shad Ansaria5c79892018-11-29 16:32:59 -080098 gemPortId uint16
Shad Ansari45806172018-11-19 17:13:08 -080099 mibUploadCtr uint16
100 uniGInstance uint8
101 pptpInstance uint8
Shad Ansaria3384b02019-01-03 15:11:11 -0800102 init istate
Shad Ansari45806172018-11-19 17:13:08 -0800103}
104
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900105type istate int
106
107const (
108 INCOMPLETE istate = iota
109 DONE
110)
111
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900112type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
Shad Ansari8213c532018-12-11 13:53:34 -0800113
114var Handlers = map[OmciMsgType]OmciMsgHandler{
115 MibReset: mibReset,
116 MibUpload: mibUpload,
117 MibUploadNext: mibUploadNext,
118 Set: set,
119 Create: create,
120 Get: get,
121 GetAllAlarms: getAllAlarms,
122}
123
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900124var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
Shad Ansari45806172018-11-19 17:13:08 -0800125
Shad Ansaria3384b02019-01-03 15:11:11 -0800126func OmciRun(ctx context.Context, omciOut chan openolt.OmciMsg, omciIn chan openolt.OmciIndication, onumap map[uint32][]*device.Onu, errch chan error) {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900127 go func() { //For monitoring the OMCI states
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900128 t := time.NewTicker(1 * time.Second)
129 defer t.Stop()
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900130 for {
Shad Ansaria3384b02019-01-03 15:11:11 -0800131 select {
132 case <-t.C:
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900133 logger.Debug("Monitor omci init state")
134 if isAllOmciInitDone(onumap) {
135 logger.Info("OmciRun - All the omci initialization wes done")
136 close(errch)
137 return
138 }
Shad Ansaria3384b02019-01-03 15:11:11 -0800139 case <-ctx.Done():
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900140 logger.Debug("Omci Monitoring process was done")
141 return
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900142 }
Shad Ansari45806172018-11-19 17:13:08 -0800143 }
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900144 }()
Shad Ansari8213c532018-12-11 13:53:34 -0800145
Shad Ansaria3384b02019-01-03 15:11:11 -0800146 go func() {
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900147 defer logger.Debug("Omci response process was done")
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900148 for {
149 var resp openolt.OmciIndication
Shad Ansaria3384b02019-01-03 15:11:11 -0800150 select {
151 case m := <-omciOut:
152 transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt)
153 if err != nil {
154 errch <- err
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900155 return
Shad Ansaria3384b02019-01-03 15:11:11 -0800156 }
157
158 logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
159 transactionId, msgType, class, instance)
160
161 key := OnuKey{m.IntfId, m.OnuId}
162 if _, ok := OnuOmciStateMap[key]; !ok {
163 OnuOmciStateMap[key] = NewOnuOmciState()
164 }
165
166 if _, ok := Handlers[msgType]; !ok {
167 logger.Warn("Ignore omci msg (msgType %d not handled)", msgType)
168 continue
169 }
170
171 resp.Pkt, err = Handlers[msgType](class, content, key)
172 if err != nil {
173 errch <- err
174 return
175 }
176 resp.Pkt[0] = byte(transactionId >> 8)
177 resp.Pkt[1] = byte(transactionId & 0xFF)
178 resp.Pkt[2] = 0x2<<4 | byte(msgType)
179 resp.Pkt[3] = deviceId
180 resp.IntfId = m.IntfId
181 resp.OnuId = m.OnuId
182 omciIn <- resp
183 case <-ctx.Done():
184 return
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900185 }
Shad Ansari45806172018-11-19 17:13:08 -0800186 }
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900187 }()
Shad Ansari2eac6a42018-11-14 22:35:39 -0800188}
Shad Ansari45806172018-11-19 17:13:08 -0800189
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900190func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) {
Shad Ansaria5c79892018-11-29 16:32:59 -0800191 var m OmciMessage
192
193 r := bytes.NewReader(HexDecode(pkt))
194
195 if err := binary.Read(r, binary.BigEndian, &m); err != nil {
196 logger.Error("binary.Read failed: %s", err)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900197 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
Shad Ansaria5c79892018-11-29 16:32:59 -0800198 }
199 logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
200 m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900201 return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
Shad Ansaria5c79892018-11-29 16:32:59 -0800202}
203
204func HexDecode(pkt []byte) []byte {
205 // Convert the hex encoding to binary
206 // TODO - Change openolt adapter to send raw binary instead of hex encoded
Shad Ansari45806172018-11-19 17:13:08 -0800207 p := make([]byte, len(pkt)/2)
208 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
Shad Ansaria5c79892018-11-29 16:32:59 -0800209 // Go figure this ;)
Shad Ansari45806172018-11-19 17:13:08 -0800210 u := (pkt[i] & 15) + (pkt[i]>>6)*9
211 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
212 p[j] = u<<4 + l
213 }
214 logger.Debug("Omci decoded: %x.", p)
Shad Ansaria5c79892018-11-29 16:32:59 -0800215 return p
Shad Ansari45806172018-11-19 17:13:08 -0800216}
217
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900218func NewOnuOmciState() *OnuOmciState {
219 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, pptpInstance: 1}
Shad Ansari45806172018-11-19 17:13:08 -0800220}
221
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900222func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800223 var pkt []byte
224
225 logger.Debug("Omci MibReset")
226
227 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800228 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900234 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800235}
236
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900237func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800238 var pkt []byte
239
240 logger.Debug("Omci MibUpload")
241
242 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800243 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800249
250 pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds
251
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900252 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800253}
254
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900255func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800256 var pkt []byte
257
258 logger.Debug("Omci MibUploadNext")
259
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900260 state := OnuOmciStateMap[key]
Shad Ansari8213c532018-12-11 13:53:34 -0800261
Shad Ansari45806172018-11-19 17:13:08 -0800262 switch state.mibUploadCtr {
263 case 0:
Shad Ansaria3384b02019-01-03 15:11:11 -0800264 // ONT Data (2)
265 pkt = []byte{
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
267 0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
272 case 1:
273 // Circuit Pack (6) - #1
274 pkt = []byte{
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
276 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04,
277 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
281 case 2:
282 // Circuit Pack (6) - #2
283 pkt = []byte{
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
285 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52,
286 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
290 case 3:
291 // Circuit Pack (6) - #3
292 pkt = []byte{
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
294 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20,
295 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
296 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
297 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
299 case 4:
300 // Circuit Pack (6) - #4
301 pkt = []byte{
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
303 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
308 case 5:
309 // Circuit Pack (6) - #5
310 pkt = []byte{
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
312 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01,
313 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
317 case 6:
318 // Circuit Pack (6) - #6
319 pkt = []byte{
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
321 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52,
322 0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
326 case 7:
327 // Circuit Pack (6) - #7
328 pkt = []byte{
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
330 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20,
331 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
332 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
333 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00,
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
335 case 8:
336 // Circuit Pack (6) - #8
337 pkt = []byte{
338 0x00, 0x0f, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
339 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00,
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
344 case 9:
Shad Ansari45806172018-11-19 17:13:08 -0800345 // ANI-G
346 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800347 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800348 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00,
349 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00,
350 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c,
351 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansaria3384b02019-01-03 15:11:11 -0800353 case 10, 11, 12, 13:
Shad Ansari45806172018-11-19 17:13:08 -0800354 // UNI-G
355 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800356 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800357 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00,
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800362 pkt[11] = state.uniGInstance // ME Instance
363 state.uniGInstance++
Shad Ansaria3384b02019-01-03 15:11:11 -0800364 case 14, 15, 16, 17:
Shad Ansari45806172018-11-19 17:13:08 -0800365 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800366 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800367 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f,
368 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00,
369 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800372 pkt[11] = state.pptpInstance // ME Instance
373 state.pptpInstance++
374 default:
375 logger.Error("Invalid MibUpload request %d", state.mibUploadCtr)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900376 return nil, errors.New("Invalid MibUpload request")
Shad Ansari45806172018-11-19 17:13:08 -0800377 }
378
379 state.mibUploadCtr++
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900380 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800381}
382
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900383func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800384 var pkt []byte
385
386 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800387 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800393
394 logger.Debug("Omci Set")
395
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900396 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800397}
398
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900399func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800400 var pkt []byte
401
Shad Ansaria5c79892018-11-29 16:32:59 -0800402 if class == GEMPortNetworkCTP {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900403 if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
Shad Ansaria5c79892018-11-29 16:32:59 -0800404 logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900405 return nil, errors.New("ONU Key Error")
Shad Ansaria5c79892018-11-29 16:32:59 -0800406 } else {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900407 onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
408 logger.Debug("Gem Port Id %d", onuOmciState.gemPortId)
409 OnuOmciStateMap[key].init = DONE
Shad Ansaria5c79892018-11-29 16:32:59 -0800410 }
411 }
412
Shad Ansari45806172018-11-19 17:13:08 -0800413 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800414 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01,
Shad Ansari45806172018-11-19 17:13:08 -0800415 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800420
421 logger.Debug("Omci Create")
422
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900423 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800424}
425
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900426func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800427 var pkt []byte
428
429 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800430 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01,
Shad Ansari45806172018-11-19 17:13:08 -0800431 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800436
437 logger.Debug("Omci Get")
438
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900439 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800440}
Shad Ansaria5c79892018-11-29 16:32:59 -0800441
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900442func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansaria5c79892018-11-29 16:32:59 -0800443 var pkt []byte
444
445 pkt = []byte{
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
447 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
450 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
451 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
452
453 logger.Debug("Omci GetAllAlarms")
454
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900455 return pkt, nil
Shad Ansaria5c79892018-11-29 16:32:59 -0800456}
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900457
Shad Ansaria3384b02019-01-03 15:11:11 -0800458func isAllOmciInitDone(onumap map[uint32][]*device.Onu) bool {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900459 for _, onus := range onumap {
Shad Ansaria3384b02019-01-03 15:11:11 -0800460 for _, onu := range onus {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900461 key := OnuKey{onu.IntfID, onu.OnuID}
462 state := OnuOmciStateMap[key]
Shad Ansaria3384b02019-01-03 15:11:11 -0800463 if state.init == INCOMPLETE {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900464 return false
465 }
466 }
467 }
468 return true
469}