William Kurkian | 3687c57 | 2019-10-11 15:29:17 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 17 | package core |
| 18 | |
| 19 | type AniGAttributes int |
| 20 | const ( |
| 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 | |
| 40 | type ANIGAttributeHandler func(*uint, []byte) ([]byte, error) |
| 41 | |
| 42 | var 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 | |
| 62 | func 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 | |
| 83 | func GetSRIndication(pos *uint, pkt []byte) ([]byte, error) { |
| 84 | pkt[*pos] = 0x01 |
| 85 | *pos++ |
| 86 | return pkt, nil |
| 87 | } |
| 88 | |
| 89 | func 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 | |
| 97 | func GetTotalTcontNumber(pos *uint, pkt []byte) ([]byte, error) { |
| 98 | pkt[*pos] = 0x08 |
| 99 | *pos++ |
| 100 | return pkt, nil |
| 101 | } |
| 102 | |
| 103 | func GetGEMBlockLength(pos *uint, pkt []byte) ([]byte, error) { |
| 104 | pkt[*pos] = 0x00 |
| 105 | *pos++ |
| 106 | pkt[*pos] = 0x30 |
| 107 | return pkt, nil |
| 108 | } |
| 109 | |
| 110 | func GetPiggybackDBAReporting (pos *uint, pkt []byte) ([]byte, error) { |
| 111 | pkt[*pos] = 0x00 |
| 112 | *pos++ |
| 113 | return pkt, nil |
| 114 | } |
| 115 | |
| 116 | func GetWholeONTDBAReporting(pos *uint, pkt []byte) ([]byte, error) { |
| 117 | pkt[*pos] = 0x00 |
| 118 | *pos++ |
| 119 | return pkt, nil |
| 120 | } |
| 121 | |
| 122 | func GetUpperOpticalThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 123 | pkt[*pos] = 0xff |
| 124 | *pos++ |
| 125 | return pkt, nil |
| 126 | } |
| 127 | |
| 128 | func GetSFThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 129 | pkt[*pos] = 0x03 |
| 130 | *pos++ |
| 131 | return pkt, nil |
| 132 | } |
| 133 | |
| 134 | func GetSDThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 135 | pkt[*pos] = 0x05 |
| 136 | *pos++ |
| 137 | return pkt, nil |
| 138 | } |
| 139 | |
| 140 | func GetARC(pos *uint, pkt []byte) ([]byte, error) { |
| 141 | pkt[*pos] = 0x00 |
| 142 | *pos++ |
| 143 | return pkt, nil |
| 144 | } |
| 145 | |
| 146 | func GetARCInterval(pos *uint, pkt []byte) ([]byte, error) { |
| 147 | pkt[*pos] = 0x00 |
| 148 | *pos++ |
| 149 | return pkt, nil |
| 150 | } |
| 151 | |
| 152 | func 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 | |
| 160 | func GetLowerOpticalThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 161 | pkt[*pos] = 0xff |
| 162 | *pos++ |
| 163 | return pkt, nil |
| 164 | } |
| 165 | |
| 166 | func 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 | |
| 174 | func GetLowerTransmitPowerThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 175 | pkt[*pos] = 0x81 |
| 176 | *pos++ |
| 177 | return pkt, nil |
| 178 | } |
| 179 | |
| 180 | func GetUpperTransmitPowerThreshold(pos *uint, pkt []byte) ([]byte, error) { |
| 181 | pkt[*pos] = 0x81 |
| 182 | *pos++ |
| 183 | return pkt, nil |
William Kurkian | 3687c57 | 2019-10-11 15:29:17 -0400 | [diff] [blame] | 184 | } |