blob: 4335e0afb6e77d190768600aea87c2ff05162e73 [file] [log] [blame]
Shad Ansari65fed642019-01-16 14:04:19 -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
19import (
20 "gerrit.opencord.org/voltha-bbsim/common/logger"
21)
22
23func OmciSim(intfId uint32, onuId uint32, request []byte) ([]byte, error) {
24 var resp []byte
25
26 transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request)
27 if err != nil {
28 return resp, &OmciError{"Cannot parse omci msg"}
29 }
30
31 logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
32 transactionId, msgType, class, instance)
33
34 key := OnuKey{intfId, onuId}
35 if _, ok := OnuOmciStateMap[key]; !ok {
36 OnuOmciStateMap[key] = NewOnuOmciState()
37 }
38
39 if _, ok := Handlers[msgType]; !ok {
40 logger.Warn("Ignore omci msg (msgType %d not handled)", msgType)
41 return resp, &OmciError{"Unimplemented omci msg"}
42 }
43
44 resp, err = Handlers[msgType](class, content, key)
45 if err != nil {
46 return resp, err
47 }
48 resp[0] = byte(transactionId >> 8)
49 resp[1] = byte(transactionId & 0xFF)
50 resp[2] = 0x2<<4 | byte(msgType)
51 resp[3] = deviceId
52
53 return resp, nil
54}