blob: 63b18af83eb7b938726005f70f35daf1bc91718f [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
Shad Ansari53935c02019-01-17 16:41:45 -080019import "log"
Zdravko Bozakov3d762142019-07-15 16:57:17 +020020import logs "gerrit.opencord.org/voltha-bbsim/common/logger"
21
22var logger = logs.DefaultLogger
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 {
Zdravko Bozakov3d762142019-07-15 16:57:17 +020029 logger.Error("ONU {intfid:%d, onuid:%d} - Cannot parse omci msg", intfId, onuId)
Shad Ansari1106b022019-01-16 22:22:35 -080030 return resp, &OmciError{"Cannot parse omci msg"}
31 }
32
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080033 log.Printf("ONU {intfid:%d, onuid:%d} - OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
34 intfId, onuId, transactionId, msgType, class, instance)
Shad Ansari1106b022019-01-16 22:22:35 -080035
36 key := OnuKey{intfId, onuId}
37 if _, ok := OnuOmciStateMap[key]; !ok {
38 OnuOmciStateMap[key] = NewOnuOmciState()
39 }
40
41 if _, ok := Handlers[msgType]; !ok {
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080042 log.Printf("ONU {intfid:%d, onuid:%d} - Ignore omci msg (msgType %d not handled)", intfId, onuId, msgType)
Shad Ansari1106b022019-01-16 22:22:35 -080043 return resp, &OmciError{"Unimplemented omci msg"}
44 }
45
46 resp, err = Handlers[msgType](class, content, key)
47 if err != nil {
Zdravko Bozakov3d762142019-07-15 16:57:17 +020048 log.Printf("ONU {intfid:%d, onuid:%d} - Unable to send a successful response, error:%s", intfId, onuId, err)
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090049 return resp, nil
Shad Ansari1106b022019-01-16 22:22:35 -080050 }
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090051
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020052 // In the OMCI message, first 2-bytes is the Transaction Correlation ID
Shad Ansari1106b022019-01-16 22:22:35 -080053 resp[0] = byte(transactionId >> 8)
54 resp[1] = byte(transactionId & 0xFF)
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020055 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 -080056 resp[3] = deviceId
57
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020058 // for create, get and set
59 if ((msgType & 0xFF) != MibUploadNext) && ((msgType & 0xFF) != MibReset) && ((msgType & 0xFF) != MibUpload) {
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020060 // Common fields for create, get, and set
61 resp[4] = byte(class >> 8)
62 resp[5] = byte(class & 0xFF)
63 resp[6] = byte(instance >> 8)
64 resp[7] = byte(instance & 0xFF)
65 resp[8] = 0 // Result: Command Processed Successfully
66
67 // Hardcoding class specific values for Get
68 if (class == 0x82) && ((msgType & 0x0F) == Get) {
69 resp[9] = 0
70 resp[10] = 0x78
71
72 } else if (class == 0x2F) && ((msgType & 0x0F) == Get) {
73 resp[9] = 0x0F
74 resp[10] = 0xB8
75 } else if (class == 0x138) && ((msgType & 0x0F) == Get) {
76 resp[9] = content[0] // 0xBE
77 resp[10] = 0x00
78 }
79 }
80
81 log.Printf("OMCI-SIM Response %+x\n", resp)
82
Shad Ansari1106b022019-01-16 22:22:35 -080083 return resp, nil
84}