blob: 3fa44089b99a18cb34be85bcfb75d92bbd6ac5c3 [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001/*
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 "fmt"
21 log "github.com/sirupsen/logrus"
22)
23
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 {
Matteo Scandolo7b512202020-11-09 16:38:10 -080033 OltId int
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070034 IntfId, OnuId uint32
35}
36
37func (k OnuKey) String() string {
38 return fmt.Sprintf("Onu {intfid:%d, onuid:%d}", k.IntfId, k.OnuId)
39}
40
41func GetAttributes(class OmciClass, content OmciContent, key OnuKey, pkt []byte) []byte {
42 log.WithFields(log.Fields{
43 "IntfId": key.IntfId,
44 "OnuId": key.OnuId,
45 }).Tracef("GetAttributes() invoked")
46
47 switch class {
48 case ANIG:
49 pos := uint(11)
50 pkt, _ = GetANIGAttributes(&pos, pkt, content)
51 return pkt
52
Matteo Scandolo732c0752020-01-28 07:24:13 -080053 case SoftwareImage:
54 pos := uint(11)
55 pkt, _ = GetSoftwareImageAttributes(&pos, pkt, content)
56 return pkt
57
58 case ONUG:
59 pos := uint(11)
Matteo Scandolo7b512202020-11-09 16:38:10 -080060 pkt, _ = GetOnuGAttributes(&pos, pkt, content, key)
Matteo Scandolo732c0752020-01-28 07:24:13 -080061 return pkt
62
63 case ONU2G:
64 pos := uint(11)
65 pkt, _ = GetOnu2GAttributes(&pos, pkt, content)
66 return pkt
67
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070068 case EthernetPMHistoryData:
69 pos := uint(11)
70 pkt, _ = GetEthernetPMHistoryDataAttributes(&pos, pkt, content)
71 return pkt
Matteo Scandolo732c0752020-01-28 07:24:13 -080072
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070073 default:
74 // For unimplemented MEs, just fill in the attribute mask and return 0 values for the requested attributes
75 // TODO implement Get for unimplemented MEs as well
76 log.WithFields(log.Fields{
77 "IntfId": key.IntfId,
78 "OnuId": key.OnuId,
79 "class": class,
80 }).Tracef("Unimplemeted GetAttributes for ME Class: %v " +
81 "Filling with zero value for the requested attributes", class)
82 AttributesMask := getAttributeMask(content)
83 pkt[8] = 0x00 // Command Processed Successfully
84 pkt[9] = uint8(AttributesMask >> 8)
85 pkt[10] = uint8(AttributesMask & 0xFF)
86
87 return pkt
88 }
89}
90
91func getAttributeMask(content OmciContent) int {
92 // mask is present in pkt[8] and pkt[9]
93 log.WithFields(log.Fields{
94 "content[0]": content[0],
95 "content[1]": content[1],
96 }).Tracef("GetAttributeMask() invoked")
97 return (int(content[0]) << 8) | int(content[1])
98}