blob: 50335f2dff68f8f13382fa6d50b8c3f6ddd98f61 [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 +020020
Shad Ansari1106b022019-01-16 22:22:35 -080021
22func OmciSim(intfId uint32, onuId uint32, request []byte) ([]byte, error) {
23 var resp []byte
24
25 transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request)
26 if err != nil {
Kailash65400672019-07-17 09:46:53 -070027 log.Printf("ONU {intfid:%d, onuid:%d} - Cannot parse omci msg", intfId, onuId)
Shad Ansari1106b022019-01-16 22:22:35 -080028 return resp, &OmciError{"Cannot parse omci msg"}
29 }
30
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080031 log.Printf("ONU {intfid:%d, onuid:%d} - OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
32 intfId, onuId, transactionId, msgType, class, instance)
Shad Ansari1106b022019-01-16 22:22:35 -080033
34 key := OnuKey{intfId, onuId}
35 if _, ok := OnuOmciStateMap[key]; !ok {
36 OnuOmciStateMap[key] = NewOnuOmciState()
37 }
38
39 if _, ok := Handlers[msgType]; !ok {
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080040 log.Printf("ONU {intfid:%d, onuid:%d} - Ignore omci msg (msgType %d not handled)", intfId, onuId, msgType)
Shad Ansari1106b022019-01-16 22:22:35 -080041 return resp, &OmciError{"Unimplemented omci msg"}
42 }
43
44 resp, err = Handlers[msgType](class, content, key)
45 if err != nil {
Zdravko Bozakov3d762142019-07-15 16:57:17 +020046 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 +090047 return resp, nil
Shad Ansari1106b022019-01-16 22:22:35 -080048 }
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090049
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020050 // In the OMCI message, first 2-bytes is the Transaction Correlation ID
Shad Ansari1106b022019-01-16 22:22:35 -080051 resp[0] = byte(transactionId >> 8)
52 resp[1] = byte(transactionId & 0xFF)
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020053 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 -080054 resp[3] = deviceId
55
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020056 // for create, get and set
57 if ((msgType & 0xFF) != MibUploadNext) && ((msgType & 0xFF) != MibReset) && ((msgType & 0xFF) != MibUpload) {
Zdravko Bozakovf56cca42019-04-29 10:06:47 +020058 // Common fields for create, get, and set
59 resp[4] = byte(class >> 8)
60 resp[5] = byte(class & 0xFF)
61 resp[6] = byte(instance >> 8)
62 resp[7] = byte(instance & 0xFF)
63 resp[8] = 0 // Result: Command Processed Successfully
64
65 // Hardcoding class specific values for Get
66 if (class == 0x82) && ((msgType & 0x0F) == Get) {
67 resp[9] = 0
68 resp[10] = 0x78
69
70 } else if (class == 0x2F) && ((msgType & 0x0F) == Get) {
71 resp[9] = 0x0F
72 resp[10] = 0xB8
73 } else if (class == 0x138) && ((msgType & 0x0F) == Get) {
74 resp[9] = content[0] // 0xBE
75 resp[10] = 0x00
76 }
77 }
78
79 log.Printf("OMCI-SIM Response %+x\n", resp)
80
Shad Ansari1106b022019-01-16 22:22:35 -080081 return resp, nil
82}