blob: c9860c2d72c88339a2eb30b2c4abcb9a741075ad [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 Ansarifd298442019-01-08 16:19:35 -080091const NumMibUploads byte = 26
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 Ansarifd298442019-01-08 16:19:35 -080098 gemPortId uint16
99 mibUploadCtr uint16
100 uniGInstance uint8
101 tcontInstance uint8
102 pptpInstance uint8
103 init istate
Shad Ansari45806172018-11-19 17:13:08 -0800104}
105
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900106type istate int
107
108const (
109 INCOMPLETE istate = iota
110 DONE
111)
112
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900113type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
Shad Ansari8213c532018-12-11 13:53:34 -0800114
115var Handlers = map[OmciMsgType]OmciMsgHandler{
116 MibReset: mibReset,
117 MibUpload: mibUpload,
118 MibUploadNext: mibUploadNext,
119 Set: set,
120 Create: create,
121 Get: get,
122 GetAllAlarms: getAllAlarms,
123}
124
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900125var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
Shad Ansari45806172018-11-19 17:13:08 -0800126
Shad Ansaria3384b02019-01-03 15:11:11 -0800127func 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 +0900128 go func() { //For monitoring the OMCI states
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900129 t := time.NewTicker(1 * time.Second)
130 defer t.Stop()
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900131 for {
Shad Ansaria3384b02019-01-03 15:11:11 -0800132 select {
133 case <-t.C:
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900134 logger.Debug("Monitor omci init state")
135 if isAllOmciInitDone(onumap) {
136 logger.Info("OmciRun - All the omci initialization wes done")
137 close(errch)
138 return
139 }
Shad Ansaria3384b02019-01-03 15:11:11 -0800140 case <-ctx.Done():
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900141 logger.Debug("Omci Monitoring process was done")
142 return
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900143 }
Shad Ansari45806172018-11-19 17:13:08 -0800144 }
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900145 }()
Shad Ansari8213c532018-12-11 13:53:34 -0800146
Shad Ansaria3384b02019-01-03 15:11:11 -0800147 go func() {
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900148 defer logger.Debug("Omci response process was done")
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900149 for {
150 var resp openolt.OmciIndication
Shad Ansaria3384b02019-01-03 15:11:11 -0800151 select {
152 case m := <-omciOut:
153 transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt)
154 if err != nil {
155 errch <- err
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900156 return
Shad Ansaria3384b02019-01-03 15:11:11 -0800157 }
158
159 logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
160 transactionId, msgType, class, instance)
161
162 key := OnuKey{m.IntfId, m.OnuId}
163 if _, ok := OnuOmciStateMap[key]; !ok {
164 OnuOmciStateMap[key] = NewOnuOmciState()
165 }
166
167 if _, ok := Handlers[msgType]; !ok {
168 logger.Warn("Ignore omci msg (msgType %d not handled)", msgType)
169 continue
170 }
171
172 resp.Pkt, err = Handlers[msgType](class, content, key)
173 if err != nil {
174 errch <- err
175 return
176 }
177 resp.Pkt[0] = byte(transactionId >> 8)
178 resp.Pkt[1] = byte(transactionId & 0xFF)
179 resp.Pkt[2] = 0x2<<4 | byte(msgType)
180 resp.Pkt[3] = deviceId
181 resp.IntfId = m.IntfId
182 resp.OnuId = m.OnuId
183 omciIn <- resp
184 case <-ctx.Done():
185 return
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900186 }
Shad Ansari45806172018-11-19 17:13:08 -0800187 }
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900188 }()
Shad Ansari2eac6a42018-11-14 22:35:39 -0800189}
Shad Ansari45806172018-11-19 17:13:08 -0800190
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900191func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) {
Shad Ansaria5c79892018-11-29 16:32:59 -0800192 var m OmciMessage
193
194 r := bytes.NewReader(HexDecode(pkt))
195
196 if err := binary.Read(r, binary.BigEndian, &m); err != nil {
197 logger.Error("binary.Read failed: %s", err)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900198 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
Shad Ansaria5c79892018-11-29 16:32:59 -0800199 }
200 logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
201 m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900202 return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
Shad Ansaria5c79892018-11-29 16:32:59 -0800203}
204
205func HexDecode(pkt []byte) []byte {
206 // Convert the hex encoding to binary
207 // TODO - Change openolt adapter to send raw binary instead of hex encoded
Shad Ansari45806172018-11-19 17:13:08 -0800208 p := make([]byte, len(pkt)/2)
209 for i, j := 0, 0; i < len(pkt); i, j = i+2, j+1 {
Shad Ansaria5c79892018-11-29 16:32:59 -0800210 // Go figure this ;)
Shad Ansari45806172018-11-19 17:13:08 -0800211 u := (pkt[i] & 15) + (pkt[i]>>6)*9
212 l := (pkt[i+1] & 15) + (pkt[i+1]>>6)*9
213 p[j] = u<<4 + l
214 }
215 logger.Debug("Omci decoded: %x.", p)
Shad Ansaria5c79892018-11-29 16:32:59 -0800216 return p
Shad Ansari45806172018-11-19 17:13:08 -0800217}
218
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900219func NewOnuOmciState() *OnuOmciState {
Shad Ansarifd298442019-01-08 16:19:35 -0800220 return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
Shad Ansari45806172018-11-19 17:13:08 -0800221}
222
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900223func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800224 var pkt []byte
225
226 logger.Debug("Omci MibReset")
227
228 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800229 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800230 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,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900235 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800236}
237
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900238func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800239 var pkt []byte
240
241 logger.Debug("Omci MibUpload")
242
243 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800244 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800245 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,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800250
251 pkt[9] = NumMibUploads // Number of subsequent MibUploadNext cmds
252
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900253 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800254}
255
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900256func mibUploadNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800257 var pkt []byte
258
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900259 state := OnuOmciStateMap[key]
Shad Ansari8213c532018-12-11 13:53:34 -0800260
Shad Ansarifd298442019-01-08 16:19:35 -0800261 logger.Debug("Omci MibUploadNext %d", state.mibUploadCtr)
262
Shad Ansari45806172018-11-19 17:13:08 -0800263 switch state.mibUploadCtr {
264 case 0:
Shad Ansaria3384b02019-01-03 15:11:11 -0800265 // ONT Data (2)
266 pkt = []byte{
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
268 0x00, 0x02, 0x00, 0x00, 0x80, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
273 case 1:
274 // Circuit Pack (6) - #1
275 pkt = []byte{
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
277 0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04,
278 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
282 case 2:
283 // Circuit Pack (6) - #2
284 pkt = []byte{
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
286 0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52,
287 0x43, 0x4d, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
291 case 3:
292 // Circuit Pack (6) - #3
293 pkt = []byte{
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
295 0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20,
296 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
297 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
298 0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
300 case 4:
301 // Circuit Pack (6) - #4
302 pkt = []byte{
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
304 0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
309 case 5:
310 // Circuit Pack (6) - #5
311 pkt = []byte{
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
313 0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01,
314 0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
318 case 6:
319 // Circuit Pack (6) - #6
320 pkt = []byte{
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
322 0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52,
323 0x43, 0x4d, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
327 case 7:
328 // Circuit Pack (6) - #7
329 pkt = []byte{
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
331 0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20,
332 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
333 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
334 0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00,
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
336 case 8:
337 // Circuit Pack (6) - #8
338 pkt = []byte{
Shad Ansarifd298442019-01-08 16:19:35 -0800339 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansaria3384b02019-01-03 15:11:11 -0800340 0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansarifd298442019-01-08 16:19:35 -0800345 case 9, 10, 11, 12:
346 // PPTP (11)
Shad Ansari45806172018-11-19 17:13:08 -0800347 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800348 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800349 0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f,
350 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0xee, 0x00,
351 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800354 pkt[11] = state.pptpInstance // ME Instance
355 state.pptpInstance++
Shad Ansarifd298442019-01-08 16:19:35 -0800356 case 13, 14, 15, 16, 17, 18, 19, 20:
357 // T-CONT (262)
358 pkt = []byte{
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
360 0x01, 0x06, 0x80, 0x00, 0xe0, 0x00, 0xff, 0xff,
361 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
365 pkt[11] = state.tcontInstance // TCONT ME Instance
366 state.tcontInstance++
367 case 21:
368 // ANI-G (263)
369 pkt = []byte{
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
371 0x01, 0x07, 0x80, 0x01, 0xff, 0xff, 0x01, 0x00,
372 0x08, 0x00, 0x30, 0x00, 0x00, 0x05, 0x09, 0x00,
373 0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c,
374 0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
376 case 22, 23, 24, 25:
377 // UNI-G (264)
378 pkt = []byte{
379 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
380 0x01, 0x08, 0x01, 0x01, 0xf8, 0x00, 0x00, 0x00,
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
385 pkt[11] = state.uniGInstance // UNI-G ME Instance
386 state.uniGInstance++
Shad Ansari45806172018-11-19 17:13:08 -0800387 default:
388 logger.Error("Invalid MibUpload request %d", state.mibUploadCtr)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900389 return nil, errors.New("Invalid MibUpload request")
Shad Ansari45806172018-11-19 17:13:08 -0800390 }
391
392 state.mibUploadCtr++
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900393 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800394}
395
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900396func set(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800397 var pkt []byte
398
399 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800400 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
Shad Ansari45806172018-11-19 17:13:08 -0800401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800406
407 logger.Debug("Omci Set")
408
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900409 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800410}
411
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900412func create(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800413 var pkt []byte
414
Shad Ansaria5c79892018-11-29 16:32:59 -0800415 if class == GEMPortNetworkCTP {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900416 if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
Shad Ansaria5c79892018-11-29 16:32:59 -0800417 logger.Error("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId)
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900418 return nil, errors.New("ONU Key Error")
Shad Ansaria5c79892018-11-29 16:32:59 -0800419 } else {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900420 onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
421 logger.Debug("Gem Port Id %d", onuOmciState.gemPortId)
422 OnuOmciStateMap[key].init = DONE
Shad Ansaria5c79892018-11-29 16:32:59 -0800423 }
424 }
425
Shad Ansari45806172018-11-19 17:13:08 -0800426 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800427 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01,
Shad Ansari45806172018-11-19 17:13:08 -0800428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800433
434 logger.Debug("Omci Create")
435
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900436 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800437}
438
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900439func get(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansari45806172018-11-19 17:13:08 -0800440 var pkt []byte
441
442 pkt = []byte{
Shad Ansaria5c79892018-11-29 16:32:59 -0800443 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x01,
Shad Ansari45806172018-11-19 17:13:08 -0800444 0x00, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Shad Ansaria5c79892018-11-29 16:32:59 -0800448 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Shad Ansari45806172018-11-19 17:13:08 -0800449
450 logger.Debug("Omci Get")
451
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900452 return pkt, nil
Shad Ansari45806172018-11-19 17:13:08 -0800453}
Shad Ansaria5c79892018-11-29 16:32:59 -0800454
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900455func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
Shad Ansaria5c79892018-11-29 16:32:59 -0800456 var pkt []byte
457
458 pkt = []byte{
459 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
460 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
463 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
464 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
465
466 logger.Debug("Omci GetAllAlarms")
467
Keita NISHIMOTO2b694202018-12-18 07:30:55 +0900468 return pkt, nil
Shad Ansaria5c79892018-11-29 16:32:59 -0800469}
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900470
Shad Ansaria3384b02019-01-03 15:11:11 -0800471func isAllOmciInitDone(onumap map[uint32][]*device.Onu) bool {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900472 for _, onus := range onumap {
Shad Ansaria3384b02019-01-03 15:11:11 -0800473 for _, onu := range onus {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900474 key := OnuKey{onu.IntfID, onu.OnuID}
475 state := OnuOmciStateMap[key]
Shad Ansaria3384b02019-01-03 15:11:11 -0800476 if state.init == INCOMPLETE {
Keita NISHIMOTO3af86da2018-12-12 10:34:43 +0900477 return false
478 }
479 }
480 }
481 return true
482}