blob: 1cf6b0de88f9940608fcb5660d48ef5e8e776a46 [file] [log] [blame]
Matt Jeanneret6fb68f32020-01-25 19:59:35 -05001/*
2 * Copyright 2020-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 OnuGAttributes int
20
21const (
22 _ = iota
23 VendorID OnuGAttributes = 0x8000
24 Version OnuGAttributes = 0x4000
25 SerialNumber OnuGAttributes = 0x2000
26 TrafficManagementOptions OnuGAttributes = 0x1000
27 VpVcCrossConnectOptions OnuGAttributes = 0x0800
28 BatteryBackup OnuGAttributes = 0x0400
29 AdministrativeState OnuGAttributes = 0x0200
30 OperationalState OnuGAttributes = 0x0100
31 OntSurvivalTime OnuGAttributes = 0x0080
32 LogicalOnuID OnuGAttributes = 0x0040
33 LogicalPassword OnuGAttributes = 0x0020
34 CredentialsStatus OnuGAttributes = 0x0010
35 ExtendedTcLayerOptions OnuGAttributes = 0x0008
36)
37
38type OnuGAttributeHandler func(*uint, []byte) ([]byte, error)
39
40var OnuGAttributeHandlers = map[OnuGAttributes]OnuGAttributeHandler{
41 VendorID: GetVendorID,
42 Version: GetVersion,
43 SerialNumber: GetSerialNumber,
44 TrafficManagementOptions: GetTrafficManagementOptions,
45 VpVcCrossConnectOptions: GetVpVcCrossConnectOptions,
46 BatteryBackup: GetBatteryBackup,
47 AdministrativeState: GetAdministrativeState,
48 OperationalState: GetOperationalState,
49 OntSurvivalTime: GetOntSurvivalTime,
50 LogicalOnuID: GetLogicalOnuID,
51 LogicalPassword: GetLogicalPassword,
52 CredentialsStatus: GetCredentialsStatus,
53 ExtendedTcLayerOptions: GetExtendedTcLayerOptions,
54}
55
56func GetOnuGAttributes(pos *uint, pkt []byte, content OmciContent) ([]byte, error) {
57 AttributesMask := getAttributeMask(content)
58
59 for index := uint(16); index >= 1; index-- {
60 Attribute := 1 << (index - 1)
61 reqAttribute := Attribute & AttributesMask
62
63 if reqAttribute != 0 {
64 pkt, _ = OnuGAttributeHandlers[OnuGAttributes(reqAttribute)](pos, pkt)
65 }
66 }
67
68 pkt[8] = 0x00 // Command Processed Successfully
69 pkt[9] = uint8(AttributesMask >> 8)
70 pkt[10] = uint8(AttributesMask & 0x00FF)
71
72 return pkt, nil
73
74}
75
76func GetVendorID(pos *uint, pkt []byte) ([]byte, error) {
77 // 4 bytes
78 vendorid := []byte("BBSM")
79 for _, ch := range vendorid {
80 pkt[*pos] = ch
81 *pos++
82 }
83 return pkt, nil
84}
85
86func GetVersion(pos *uint, pkt []byte) ([]byte, error) {
87 // 14 bytes
88 for i := 1; i <= 14; i++ {
89 b := byte(' ')
90 pkt[*pos] = b
91 *pos++
92 }
93 return pkt, nil
94}
95
96func GetSerialNumber(pos *uint, pkt []byte) ([]byte, error) {
97 // 8 bytes
98 vendorid := []byte("BBSM")
99 serialhex := []byte{0x00, 0x00, 0x00, 0x01}
100 serialnumber := append(vendorid, serialhex...)
101 for _, ch := range serialnumber {
102 pkt[*pos] = ch
103 *pos++
104 }
105 return pkt, nil
106}
107
108func GetTrafficManagementOptions(pos *uint, pkt []byte) ([]byte, error) {
109 // 1 byte
110 pkt[*pos] = 0x00
111 *pos++
112 return pkt, nil
113}
114
115func GetVpVcCrossConnectOptions(pos *uint, pkt []byte) ([]byte, error) {
116 // 1 byte
117 pkt[*pos] = 0x00
118 *pos++
119 return pkt, nil
120}
121
122func GetBatteryBackup(pos *uint, pkt []byte) ([]byte, error) {
123 // 1 byte
124 pkt[*pos] = 0x00
125 *pos++
126 return pkt, nil
127}
128
129func GetAdministrativeState(pos *uint, pkt []byte) ([]byte, error) {
130 // 1 byte
131 pkt[*pos] = 0x00
132 *pos++
133 return pkt, nil
134}
135
136func GetOperationalState(pos *uint, pkt []byte) ([]byte, error) {
137 // 1 byte
138 pkt[*pos] = 0x00
139 *pos++
140 return pkt, nil
141}
142
143func GetOntSurvivalTime(pos *uint, pkt []byte) ([]byte, error) {
144 // 1 byte
145 pkt[*pos] = 0x00
146 *pos++
147 return pkt, nil
148}
149
150func GetLogicalOnuID(pos *uint, pkt []byte) ([]byte, error) {
151 // 24 bytes
152 for i := 1; i <= 24; i++ {
153 b := byte(' ')
154 pkt[*pos] = b
155 *pos++
156 }
157 return pkt, nil
158}
159
160func GetLogicalPassword(pos *uint, pkt []byte) ([]byte, error) {
161 // 24 bytes
162 for i := 1; i <= 24; i++ {
163 b := byte(' ')
164 pkt[*pos] = b
165 *pos++
166 }
167 return pkt, nil
168}
169
170func GetCredentialsStatus(pos *uint, pkt []byte) ([]byte, error) {
171 // 1 byte
172 pkt[*pos] = 0x00
173 *pos++
174 return pkt, nil
175}
176
177func GetExtendedTcLayerOptions(pos *uint, pkt []byte) ([]byte, error) {
178 // 2 bytes
179 tcbits := []byte{0x00, 0x00}
180 for _, ch := range tcbits {
181 pkt[*pos] = ch
182 *pos++
183 }
184 return pkt, nil
185}