blob: 49734a7033749bc11a21da4016e3dd815d6bd050 [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
19type AniGAttributes int
20const (
21 _ = iota
22 SRIndication AniGAttributes = 0x8000
23 TotalTcontNumber AniGAttributes = 0x4000
24 GEMBlockLength AniGAttributes = 0x2000
25 PiggybackDBAReporting AniGAttributes = 0x1000
26 WholeONTDBAReporting AniGAttributes = 0x0800
27 SFThreshold AniGAttributes = 0x0400
28 SDThreshold AniGAttributes = 0x0200
29 ARC AniGAttributes = 0x0100
30 ARCInterval AniGAttributes = 0x0080
31 OpticalSignalLevel AniGAttributes = 0x0040
32 LowerOpticalThreshold AniGAttributes = 0x0020
33 UpperOpticalThreshold AniGAttributes = 0x0010
34 ONTResponseTime AniGAttributes = 0x0008
35 TransmitOpticalLeval AniGAttributes = 0x0004
36 LowerTransmitPowerThreshold AniGAttributes = 0x0002
37 UpperTransmitPowerThreshold AniGAttributes = 0x0001
38)
39
40type ANIGAttributeHandler func(*uint, []byte) ([]byte, error)
41
42var ANIGAttributeHandlers = map[AniGAttributes]ANIGAttributeHandler{
43 SRIndication: GetSRIndication,
44 OpticalSignalLevel: GetOpticalSignalLevel,
45 LowerOpticalThreshold: GetLowerOpticalThreshold,
46 UpperOpticalThreshold: GetUpperOpticalThreshold,
47 TotalTcontNumber: GetTotalTcontNumber,
48 GEMBlockLength: GetGEMBlockLength,
49 PiggybackDBAReporting: GetPiggybackDBAReporting,
50 WholeONTDBAReporting: GetWholeONTDBAReporting,
51 SFThreshold: GetSFThreshold,
52 SDThreshold: GetSDThreshold,
53 ARC: GetARC,
54 ARCInterval: GetARCInterval,
55 ONTResponseTime: GetONTResponseTime,
56 TransmitOpticalLeval: GetTransmitOpticalLeval,
57 LowerTransmitPowerThreshold: GetLowerTransmitPowerThreshold,
58 UpperTransmitPowerThreshold: GetUpperTransmitPowerThreshold,
59}
60
61
62func GetANIGAttributes(pos *uint, pkt []byte, content OmciContent) ([]byte, error) {
63 AttributesMask := getAttributeMask(content)
64
65 for index := uint(16); index>=1 ; index-- {
66 Attribute := 1 << (index - 1)
67 reqAttribute := Attribute & AttributesMask
68
69 if reqAttribute != 0 {
70 pkt, _ = ANIGAttributeHandlers[AniGAttributes(reqAttribute)](pos, pkt)
71 }
72 }
73
74 pkt[8] = 0x00 // Command Processed Successfully
75 pkt[9] = uint8(AttributesMask >> 8)
76 pkt[10] = uint8(AttributesMask & 0x00FF)
77
78 return pkt, nil
79
80}
81
82
83func GetSRIndication(pos *uint, pkt []byte) ([]byte, error) {
84 pkt[*pos] = 0x01
85 *pos++
86 return pkt, nil
87}
88
89func GetOpticalSignalLevel(pos *uint, pkt []byte) ([]byte, error) {
90 pkt[*pos] = 0xd7
91 *pos++
92 pkt[*pos] = 0xa9
93 *pos++
94 return pkt, nil
95}
96
97func GetTotalTcontNumber(pos *uint, pkt []byte) ([]byte, error) {
98 pkt[*pos] = 0x08
99 *pos++
100 return pkt, nil
101}
102
103func GetGEMBlockLength(pos *uint, pkt []byte) ([]byte, error) {
104 pkt[*pos] = 0x00
105 *pos++
106 pkt[*pos] = 0x30
107 return pkt, nil
108}
109
110func GetPiggybackDBAReporting (pos *uint, pkt []byte) ([]byte, error) {
111 pkt[*pos] = 0x00
112 *pos++
113 return pkt, nil
114}
115
116func GetWholeONTDBAReporting(pos *uint, pkt []byte) ([]byte, error) {
117 pkt[*pos] = 0x00
118 *pos++
119 return pkt, nil
120}
121
122func GetUpperOpticalThreshold(pos *uint, pkt []byte) ([]byte, error) {
123 pkt[*pos] = 0xff
124 *pos++
125 return pkt, nil
126}
127
128func GetSFThreshold(pos *uint, pkt []byte) ([]byte, error) {
129 pkt[*pos] = 0x03
130 *pos++
131 return pkt, nil
132}
133
134func GetSDThreshold(pos *uint, pkt []byte) ([]byte, error) {
135 pkt[*pos] = 0x05
136 *pos++
137 return pkt, nil
138}
139
140func GetARC(pos *uint, pkt []byte) ([]byte, error) {
141 pkt[*pos] = 0x00
142 *pos++
143 return pkt, nil
144}
145
146func GetARCInterval(pos *uint, pkt []byte) ([]byte, error) {
147 pkt[*pos] = 0x00
148 *pos++
149 return pkt, nil
150}
151
152func GetONTResponseTime(pos *uint, pkt []byte) ([]byte, error) {
153 pkt[*pos] = 0x00
154 *pos++
155 pkt[*pos] = 0x00
156 *pos++
157 return pkt, nil
158}
159
160func GetLowerOpticalThreshold(pos *uint, pkt []byte) ([]byte, error) {
161 pkt[*pos] = 0xff
162 *pos++
163 return pkt, nil
164}
165
166func GetTransmitOpticalLeval(pos *uint, pkt []byte) ([]byte, error) {
167 pkt[*pos] = 0x07
168 *pos++
169 pkt[*pos] = 0x1e
170 *pos++
171 return pkt, nil
172}
173
174func GetLowerTransmitPowerThreshold(pos *uint, pkt []byte) ([]byte, error) {
175 pkt[*pos] = 0x81
176 *pos++
177 return pkt, nil
178}
179
180func GetUpperTransmitPowerThreshold(pos *uint, pkt []byte) ([]byte, error) {
181 pkt[*pos] = 0x81
182 *pos++
183 return pkt, nil
184}