Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 19 | import "log" |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 20 | |
| 21 | func OmciSim(intfId uint32, onuId uint32, request []byte) ([]byte, error) { |
| 22 | var resp []byte |
| 23 | |
| 24 | transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request) |
| 25 | if err != nil { |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 26 | log.Printf("ONU {intfid:%d, onuid:%d} - Cannot parse omci msg", intfId, onuId) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 27 | return resp, &OmciError{"Cannot parse omci msg"} |
| 28 | } |
| 29 | |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 30 | log.Printf("ONU {intfid:%d, onuid:%d} - OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
| 31 | intfId, onuId, transactionId, msgType, class, instance) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 32 | |
| 33 | key := OnuKey{intfId, onuId} |
| 34 | if _, ok := OnuOmciStateMap[key]; !ok { |
| 35 | OnuOmciStateMap[key] = NewOnuOmciState() |
| 36 | } |
| 37 | |
| 38 | if _, ok := Handlers[msgType]; !ok { |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 39 | log.Printf("ONU {intfid:%d, onuid:%d} - Ignore omci msg (msgType %d not handled)", intfId, onuId, msgType) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 40 | return resp, &OmciError{"Unimplemented omci msg"} |
| 41 | } |
| 42 | |
| 43 | resp, err = Handlers[msgType](class, content, key) |
| 44 | if err != nil { |
Mahir Gunyel | ed7b07b | 2019-02-11 12:06:02 -0800 | [diff] [blame] | 45 | log.Println("ONU {intfid:%d, onuid:%d} - Unable to send a successful response, error:%s", intfId, onuId, err) |
Keita NISHIMOTO | 21853b3 | 2019-01-25 19:29:59 +0900 | [diff] [blame] | 46 | return resp, nil |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 47 | } |
Keita NISHIMOTO | 21853b3 | 2019-01-25 19:29:59 +0900 | [diff] [blame] | 48 | |
Zdravko Bozakov | f56cca4 | 2019-04-29 10:06:47 +0200 | [diff] [blame^] | 49 | // In the OMCI message, first 2-bytes is the Transaction Correlation ID |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 50 | resp[0] = byte(transactionId >> 8) |
| 51 | resp[1] = byte(transactionId & 0xFF) |
Zdravko Bozakov | f56cca4 | 2019-04-29 10:06:47 +0200 | [diff] [blame^] | 52 | 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 Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 53 | resp[3] = deviceId |
| 54 | |
Zdravko Bozakov | f56cca4 | 2019-04-29 10:06:47 +0200 | [diff] [blame^] | 55 | // for create, get and set |
| 56 | if ((msgType & 0xFF) != MibUploadNext) && ((msgType & 0xFF) != MibReset) && ((msgType & 0xFF) != MibUpload) { |
| 57 | log.Println("CREATE GET OR SET OPERATION") |
| 58 | // 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 Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 81 | return resp, nil |
| 82 | } |