blob: 223fe0ec63077ff984782225c1e452def2cdf091 [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
Zdravko Bozakov3d762142019-07-15 16:57:17 +020019import (
20 "fmt"
21 "log"
22)
Shad Ansari1106b022019-01-16 22:22:35 -080023
24type OmciError struct {
25 Msg string
26}
27
28func (e *OmciError) Error() string {
29 return fmt.Sprintf("%s", e.Msg)
30}
31
32type OnuKey struct {
33 IntfId, OnuId uint32
34}
Mahir Gunyeled7b07b2019-02-11 12:06:02 -080035
36func (k OnuKey) String() string {
37 return fmt.Sprintf("Onu {intfid:%d, onuid:%d}", k.IntfId, k.OnuId)
38}
Zdravko Bozakov3d762142019-07-15 16:57:17 +020039
40func GetAttributes(class OmciClass, content OmciContent, key OnuKey, pkt []byte) []byte {
41 log.Printf("GetAttributes() invoked with onu key: %+v\n", key)
42
43 switch class {
44 case ANIG:
45 pos := uint(11)
46 pkt, _ = GetANIGAttributes(&pos, pkt, content)
47 return pkt
48
49 case EthernetPMHistoryData:
50 pos := uint(11)
51 pkt, _ = GetEthernetPMHistoryDataAttributes(&pos, pkt, content)
52 return pkt
53 default:
54 // For unimplemented MEs, just fill in the attribute mask and return 0 values for the requested attributes
55 // TODO implement Get for unimplemented MEs as well
56 log.Printf("Unimplemeted GetAttributes for ME Class: %v " +
57 "Filling with zero value for the requested attributes", class)
58 AttributesMask := getAttributeMask(content)
59 pkt[8] = 0x00 // Command Processed Successfully
60 pkt[9] = uint8(AttributesMask >> 8)
61 pkt[10] = uint8(AttributesMask & 0xFF)
62
63 return pkt
64 }
65}
66
67func getAttributeMask(content OmciContent) int {
68 // mask is present in pkt[8] and pkt[9]
69 log.Printf("GetAttributeMask() invoked\n content[0] , content[1]: %+v, %+v", content[0], content[1])
70 return (int(content[0]) << 8) | int(content[1])
71}