blob: 5980db136a7ba02631f61af7ed33b3165df40aba [file] [log] [blame]
Shad Ansari1106b022019-01-16 22:22:35 -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
Matteo Scandoloa0026812019-08-20 11:01:32 -070019import (
20 "fmt"
21 log "github.com/sirupsen/logrus"
22)
Shad Ansari1106b022019-01-16 22:22:35 -080023
24func OmciSim(intfId uint32, onuId uint32, request []byte) ([]byte, error) {
25 var resp []byte
26
27 transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request)
28 if err != nil {
Matteo Scandoloa0026812019-08-20 11:01:32 -070029 log.WithFields(log.Fields{
30 "IntfId": intfId,
31 "OnuId": onuId,
32 }).Errorf("Cannot parse OMCI msg")
33 return resp, &OmciError{"Cannot parse OMCI msg"}
Shad Ansari1106b022019-01-16 22:22:35 -080034 }
35
Matteo Scandoloa0026812019-08-20 11:01:32 -070036 log.WithFields(log.Fields{
37 "IntfId": intfId,
38 "OnuId": onuId,
39 "TransactionId": transactionId,
40 "MessageType": msgType.PrettyPrint(),
41 "MeClass": class,
42 "MeInstance": instance,
43 //"Conent": content,
44 "omciMsg": fmt.Sprintf("%x", content),
45 }).Debugf("Processing OMCI pakcet")
Shad Ansari1106b022019-01-16 22:22:35 -080046
47 key := OnuKey{intfId, onuId}
48 if _, ok := OnuOmciStateMap[key]; !ok {
49 OnuOmciStateMap[key] = NewOnuOmciState()
50 }
51
52 if _, ok := Handlers[msgType]; !ok {
Matteo Scandoloa0026812019-08-20 11:01:32 -070053 log.WithFields(log.Fields{
54 "IntfId": intfId,
55 "OnuId": onuId,
56 "msgType": msgType,
57 }).Errorf("Ignoring omci msg (msgType %d not handled)", msgType)
Shad Ansari1106b022019-01-16 22:22:35 -080058 return resp, &OmciError{"Unimplemented omci msg"}
59 }
60
61 resp, err = Handlers[msgType](class, content, key)
62 if err != nil {
Matteo Scandoloa0026812019-08-20 11:01:32 -070063 log.WithFields(log.Fields{
64 "IntfId": intfId,
65 "OnuId": onuId,
66 "msgType": msgType,
67 }).Errorf("Unable to send a successful response, error: %s", err)
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090068 return resp, nil
Shad Ansari1106b022019-01-16 22:22:35 -080069 }
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090070
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020071 // In the OMCI message, first 2-bytes is the Transaction Correlation ID
Shad Ansari1106b022019-01-16 22:22:35 -080072 resp[0] = byte(transactionId >> 8)
73 resp[1] = byte(transactionId & 0xFF)
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020074 resp[2] = 0x2<<4 | byte(msgType) // Upper nibble 0x2 is fixed (0010), Lower nibbles defines the msg type (i.e., mib-upload, mib-upload-next, etc)
Shad Ansari1106b022019-01-16 22:22:35 -080075 resp[3] = deviceId
76
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020077 // for create, get and set
78 if ((msgType & 0xFF) != MibUploadNext) && ((msgType & 0xFF) != MibReset) && ((msgType & 0xFF) != MibUpload) {
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020079 // Common fields for create, get, and set
80 resp[4] = byte(class >> 8)
81 resp[5] = byte(class & 0xFF)
82 resp[6] = byte(instance >> 8)
83 resp[7] = byte(instance & 0xFF)
84 resp[8] = 0 // Result: Command Processed Successfully
85
86 // Hardcoding class specific values for Get
87 if (class == 0x82) && ((msgType & 0x0F) == Get) {
88 resp[9] = 0
89 resp[10] = 0x78
90
91 } else if (class == 0x2F) && ((msgType & 0x0F) == Get) {
92 resp[9] = 0x0F
93 resp[10] = 0xB8
94 } else if (class == 0x138) && ((msgType & 0x0F) == Get) {
95 resp[9] = content[0] // 0xBE
96 resp[10] = 0x00
97 }
98 }
99
Matteo Scandoloa0026812019-08-20 11:01:32 -0700100 log.WithFields(log.Fields{
101 "IntfId": intfId,
102 "OnuId": onuId,
103 "msgType": msgType.PrettyPrint(),
104 "omciMsg": fmt.Sprintf("%x", resp),
105 }).Debugf("OMCI-SIM Response")
Zdravko Bozakovf56cca42019-04-29 10:06:47 +0200106
Shad Ansari1106b022019-01-16 22:22:35 -0800107 return resp, nil
Matteo Scandoloa0026812019-08-20 11:01:32 -0700108}