blob: 0c2329d9425c159d134362c4c03da8b92108477b [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
19import (
20 "encoding/binary"
21)
22
23type Onu2GAttributes int
24
25const (
26 _ = iota
27 EquipmentID Onu2GAttributes = 0x8000
28 OmccVersion Onu2GAttributes = 0x4000
29 VendorProductCode Onu2GAttributes = 0x2000
30 SecurityCapability Onu2GAttributes = 0x1000
31 SecurityMode Onu2GAttributes = 0x0800
32 TotalPriorityQueueNumber Onu2GAttributes = 0x0400
33 TotalTrafficSchedulerNumber Onu2GAttributes = 0x0200
34 Mode Onu2GAttributes = 0x0100
35 TotalGemPortIDNumber Onu2GAttributes = 0x0080
36 SysUptime Onu2GAttributes = 0x0040
37 ConnectivityCapability Onu2GAttributes = 0x0020
38 CurrentConnectivityMode Onu2GAttributes = 0x0010
39 QosConfigurationFlexibility Onu2GAttributes = 0x0008
40 PriorityQueueScaleFactor Onu2GAttributes = 0x0004
41)
42
43type Onu2GAttributeHandler func(*uint, []byte) ([]byte, error)
44
45var Onu2GAttributeHandlers = map[Onu2GAttributes]Onu2GAttributeHandler{
46 EquipmentID: GetEquipmentID,
47 OmccVersion: GetOmccVersion,
48 VendorProductCode: GetVendorProductCode,
49 SecurityCapability: GetSecurityCapability,
50 SecurityMode: GetSecurityMode,
51 TotalPriorityQueueNumber: GetTotalPriorityQueueNumber,
52 TotalTrafficSchedulerNumber: GetTotalTrafficSchedulerNumber,
53 Mode: GetMode,
54 TotalGemPortIDNumber: GetTotalGemPortIDNumber,
55 SysUptime: GetSysUptime,
56 ConnectivityCapability: GetConnectivityCapability,
57 CurrentConnectivityMode: GetCurrentConnectivityMode,
58 QosConfigurationFlexibility: GetQosConfigurationFlexibility,
59 PriorityQueueScaleFactor: GetPriorityQueueScaleFactor,
60}
61
62func GetOnu2GAttributes(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, _ = Onu2GAttributeHandlers[Onu2GAttributes(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
82func GetEquipmentID(pos *uint, pkt []byte) ([]byte, error) {
83 // 20 bytes
84 equipid := []byte("12345123451234512345")
85 for _, ch := range equipid {
86 pkt[*pos] = ch
87 *pos++
88 }
89 return pkt, nil
90}
91
92func GetOmccVersion(pos *uint, pkt []byte) ([]byte, error) {
93 // 1 bytes
94 pkt[*pos] = 0xB4
95 *pos++
96 return pkt, nil
97}
98
99func GetVendorProductCode(pos *uint, pkt []byte) ([]byte, error) {
100 // 2 bytes
101 prodcode := []byte{0x00, 0x00}
102 for _, ch := range prodcode {
103 pkt[*pos] = ch
104 *pos++
105 }
106 return pkt, nil
107}
108
109func GetSecurityCapability(pos *uint, pkt []byte) ([]byte, error) {
110 // 1 byte
111 pkt[*pos] = 0x01
112 *pos++
113 return pkt, nil
114}
115
116func GetSecurityMode(pos *uint, pkt []byte) ([]byte, error) {
117 // 1 byte
118 pkt[*pos] = 0x01
119 *pos++
120 return pkt, nil
121}
122
123func GetTotalPriorityQueueNumber(pos *uint, pkt []byte) ([]byte, error) {
124 // 2 bytes
125 // report 0 queues because thats what BRCM does...
126 numqueues := 0
127 bs := make([]byte, 2)
128 binary.BigEndian.PutUint16(bs, uint16(numqueues))
129 for _, ch := range bs {
130 pkt[*pos] = ch
131 *pos++
132 }
133 return pkt, nil
134}
135
136func GetTotalTrafficSchedulerNumber(pos *uint, pkt []byte) ([]byte, error) {
137 // 1 byte
138 pkt[*pos] = 0x00
139 *pos++
140 return pkt, nil
141}
142
143func GetMode(pos *uint, pkt []byte) ([]byte, error) {
144 // 1 byte
145 pkt[*pos] = 0x01
146 *pos++
147 return pkt, nil
148}
149
150func GetTotalGemPortIDNumber(pos *uint, pkt []byte) ([]byte, error) {
151 // 2 bytes
152 gemports := 32
153 bs := make([]byte, 2)
154 binary.BigEndian.PutUint16(bs, uint16(gemports))
155 for _, ch := range bs {
156 pkt[*pos] = ch
157 *pos++
158 }
159 return pkt, nil
160}
161
162func GetSysUptime(pos *uint, pkt []byte) ([]byte, error) {
163 // 4 byte int
164 uptime := 0
165 bs := make([]byte, 4)
166 binary.BigEndian.PutUint32(bs, uint32(uptime))
167 for _, ch := range bs {
168 pkt[*pos] = ch
169 *pos++
170 }
171 return pkt, nil
172}
173
174func GetConnectivityCapability(pos *uint, pkt []byte) ([]byte, error) {
175 // 2 bytes
176 caps := []byte{0x00, 0x7F}
177 for _, ch := range caps {
178 pkt[*pos] = ch
179 *pos++
180 }
181 return pkt, nil
182}
183
184func GetCurrentConnectivityMode(pos *uint, pkt []byte) ([]byte, error) {
185 // 1 byte
186 pkt[*pos] = 0x00
187 *pos++
188 return pkt, nil
189}
190
191func GetQosConfigurationFlexibility(pos *uint, pkt []byte) ([]byte, error) {
192 // 2 bytes
193 qosconf := []byte{0x00, 0x30}
194 for _, ch := range qosconf {
195 pkt[*pos] = ch
196 *pos++
197 }
198 return pkt, nil
199}
200
201func GetPriorityQueueScaleFactor(pos *uint, pkt []byte) ([]byte, error) {
202 // 1 bytes
203 pkt[*pos] = 0x01
204 *pos++
205 return pkt, nil
206}