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 { |
| 26 | return resp, &OmciError{"Cannot parse omci msg"} |
| 27 | } |
| 28 | |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 29 | log.Printf("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d", |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 30 | transactionId, msgType, class, instance) |
| 31 | |
| 32 | key := OnuKey{intfId, onuId} |
| 33 | if _, ok := OnuOmciStateMap[key]; !ok { |
| 34 | OnuOmciStateMap[key] = NewOnuOmciState() |
| 35 | } |
| 36 | |
| 37 | if _, ok := Handlers[msgType]; !ok { |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 38 | log.Printf("Ignore omci msg (msgType %d not handled)", msgType) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 39 | return resp, &OmciError{"Unimplemented omci msg"} |
| 40 | } |
| 41 | |
| 42 | resp, err = Handlers[msgType](class, content, key) |
| 43 | if err != nil { |
| 44 | return resp, err |
| 45 | } |
| 46 | resp[0] = byte(transactionId >> 8) |
| 47 | resp[1] = byte(transactionId & 0xFF) |
| 48 | resp[2] = 0x2<<4 | byte(msgType) |
| 49 | resp[3] = deviceId |
| 50 | |
| 51 | return resp, nil |
| 52 | } |