blob: e6291171a252a019c3b6051d2c6b38fdcb478e8b [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"
Shad Ansari1106b022019-01-16 22:22:35 -080020
21func 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 Gunyeled7b07b2019-02-11 12:06:02 -080026 log.Printf("ONU {intfid:%d, onuid:%d} - Cannot parse omci msg", intfId, onuId)
Shad Ansari1106b022019-01-16 22:22:35 -080027 return resp, &OmciError{"Cannot parse omci msg"}
28 }
29
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080030 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 Ansari1106b022019-01-16 22:22:35 -080032
33 key := OnuKey{intfId, onuId}
34 if _, ok := OnuOmciStateMap[key]; !ok {
35 OnuOmciStateMap[key] = NewOnuOmciState()
36 }
37
38 if _, ok := Handlers[msgType]; !ok {
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080039 log.Printf("ONU {intfid:%d, onuid:%d} - Ignore omci msg (msgType %d not handled)", intfId, onuId, msgType)
Shad Ansari1106b022019-01-16 22:22:35 -080040 return resp, &OmciError{"Unimplemented omci msg"}
41 }
42
43 resp, err = Handlers[msgType](class, content, key)
44 if err != nil {
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080045 log.Println("ONU {intfid:%d, onuid:%d} - Unable to send a successful response, error:%s", intfId, onuId, err)
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090046 return resp, nil
Shad Ansari1106b022019-01-16 22:22:35 -080047 }
Keita NISHIMOTO21853b32019-01-25 19:29:59 +090048
Shad Ansari1106b022019-01-16 22:22:35 -080049 resp[0] = byte(transactionId >> 8)
50 resp[1] = byte(transactionId & 0xFF)
51 resp[2] = 0x2<<4 | byte(msgType)
52 resp[3] = deviceId
53
54 return resp, nil
55}