Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 68ac4a7 | 2023-01-23 14:02:09 -0500 | [diff] [blame^] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 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 | |
| 17 | package omci |
| 18 | |
| 19 | import ( |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 20 | "bytes" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 21 | "encoding/binary" |
| 22 | "encoding/hex" |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 23 | "fmt" |
| 24 | "strings" |
| 25 | |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 26 | "github.com/google/gopacket" |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 27 | "github.com/opencord/bbsim/internal/common" |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 28 | "github.com/opencord/omci-lib-go/v2" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 29 | me "github.com/opencord/omci-lib-go/v2/generated" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 32 | // MibDbEntry contains all the information needed to build a |
| 33 | // MibUploadNextResponse packet. |
| 34 | // if Packet has a value all the other fields are ignored and the packet is sent as is. |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 35 | type MibDbEntry struct { |
| 36 | classId me.ClassID |
| 37 | entityId EntityID |
| 38 | params me.AttributeValueMap |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 39 | packet []byte |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | type MibDb struct { |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 43 | NumberOfBaselineCommands uint16 |
| 44 | NumberOfExtendedCommands uint16 |
| 45 | baselineItems []MibDbEntry |
| 46 | extendedResponses [][]byte |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | type EntityID []byte |
| 50 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 51 | const ( |
| 52 | unknownMePktReportedMeHdr string = "002500018000" |
| 53 | unknownMePktAttributes string = "0102030405060708090A0B0C0D0E0F101112131415161718191A" |
| 54 | unknownAttribPktReportedMeHdr string = "0101000007FD" |
Holger Hildebrandt | 7840378 | 2022-05-13 10:59:31 +0000 | [diff] [blame] | 55 | unknownAttribPktAttributes string = "00400801000800000006007F07003F0001000100010001000000" |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 56 | extRespMsgContentsLenStart = 8 |
| 57 | extRespMsgContentsLenEnd = 10 |
| 58 | ) |
| 59 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 60 | func (e EntityID) ToString() string { |
| 61 | return hex.EncodeToString(e) |
| 62 | } |
| 63 | |
| 64 | func (e EntityID) ToUint16() uint16 { |
| 65 | return binary.BigEndian.Uint16(e) |
| 66 | } |
| 67 | |
| 68 | func (e EntityID) ToUint32() uint32 { |
| 69 | return binary.BigEndian.Uint32(e) |
| 70 | } |
| 71 | |
Matteo Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 72 | func (e EntityID) FromUint16(id uint16) EntityID { |
| 73 | buff := new(bytes.Buffer) |
| 74 | err := binary.Write(buff, binary.BigEndian, id) |
| 75 | if err != nil { |
| 76 | panic(err) |
| 77 | } |
| 78 | |
| 79 | return buff.Bytes() |
| 80 | } |
| 81 | |
| 82 | func (e EntityID) Equals(i EntityID) bool { |
| 83 | if res := bytes.Compare(e, i); res == 0 { |
| 84 | return true |
| 85 | } |
| 86 | return false |
| 87 | } |
| 88 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 89 | const ( |
| 90 | cardHolderOnuType byte = 0x01 // ONU is a single piece of integrated equipment |
| 91 | ethernetUnitType byte = 0x2f // Ethernet BASE-T |
| 92 | xgsPonUnitType byte = 0xee // XG-PON10G10 |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 93 | gPonUnitType byte = 0xf5 // GPON12441244 |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 94 | potsUnitType byte = 0x20 // POTS |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 95 | cardHolderSlotID byte = 0x01 |
| 96 | tcontSlotId byte = 0x80 // why is this not the same as the cardHolderSlotID, it does not point to anything |
| 97 | aniGId byte = 0x01 |
| 98 | |
Holger Hildebrandt | 01f92ce | 2022-12-20 09:33:57 +0000 | [diff] [blame] | 99 | upstreamPriorityQueues = 8 // Number of queues for each T-CONT |
| 100 | downstreamPriorityQueues = 8 // Number of queues for each PPTP |
| 101 | tconts = 8 // NOTE will we ever need to configure this? |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 102 | // trafficSchedulers = 8 // NOTE will we ever need to configure this? |
| 103 | ) |
| 104 | |
| 105 | var ( |
| 106 | cardHolderEntityID = EntityID{cardHolderOnuType, cardHolderSlotID} |
| 107 | circuitPackEntityID = cardHolderEntityID // is the same as that of the cardholder ME containing this circuit pack instance |
| 108 | ) |
| 109 | |
| 110 | func GenerateUniPortEntityId(id uint32) EntityID { |
| 111 | return EntityID{cardHolderSlotID, byte(id)} |
| 112 | } |
| 113 | |
| 114 | // creates a MIB database for a ONU |
| 115 | // CircuitPack and CardHolder are static, everything else can be configured |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 116 | func GenerateMibDatabase(ethUniPortCount int, potsUniPortCount int, technology common.PonTechnology) (*MibDb, error) { |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 117 | |
| 118 | mibDb := MibDb{ |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 119 | baselineItems: []MibDbEntry{}, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // the first element to return is the ONU-Data |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 123 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 124 | me.OnuDataClassID, |
| 125 | EntityID{0x00, 0x00}, |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 126 | me.AttributeValueMap{me.OnuData_MibDataSync: 0}, // FIXME this needs to be parametrized before sending the response |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 127 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 128 | }) |
| 129 | |
| 130 | // then we report the CardHolder |
| 131 | // NOTE we have not report it till now, so leave it commented out |
| 132 | //mibDb.items = append(mibDb.items, MibDbEntry{ |
| 133 | // me.CardholderClassID, |
| 134 | // cardHolderEntityID, |
| 135 | // me.AttributeValueMap{ |
| 136 | // "ActualPlugInUnitType": cardHolderOnuType, |
| 137 | // "ExpectedPlugInUnitType": ethernetUnitType, |
| 138 | // }, |
| 139 | //}) |
| 140 | |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 141 | // ANI circuitPack |
| 142 | var aniCPType byte |
| 143 | |
| 144 | switch technology { |
| 145 | case common.XGSPON: |
| 146 | aniCPType = xgsPonUnitType |
| 147 | case common.GPON: |
| 148 | aniCPType = gPonUnitType |
| 149 | } |
| 150 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 151 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 152 | me.CircuitPackClassID, |
| 153 | circuitPackEntityID, |
| 154 | me.AttributeValueMap{ |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame] | 155 | me.CircuitPack_Type: aniCPType, |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 156 | me.CircuitPack_NumberOfPorts: 1, // NOTE is this the ANI port? must be |
| 157 | me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack-ani", 20), |
| 158 | me.CircuitPack_Version: ToOctets("v0.0.1", 20), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 159 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 160 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 161 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 162 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 163 | me.CircuitPackClassID, |
| 164 | circuitPackEntityID, |
| 165 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 166 | me.CircuitPack_VendorId: ToOctets("ONF", 4), |
| 167 | me.CircuitPack_AdministrativeState: 0, |
| 168 | me.CircuitPack_OperationalState: 0, |
| 169 | me.CircuitPack_BridgedOrIpInd: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 170 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 171 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 172 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 173 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 174 | me.CircuitPackClassID, |
| 175 | circuitPackEntityID, |
| 176 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 177 | me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20), |
| 178 | me.CircuitPack_CardConfiguration: 0, |
| 179 | me.CircuitPack_TotalTContBufferNumber: 8, |
| 180 | me.CircuitPack_TotalPriorityQueueNumber: 8, |
| 181 | me.CircuitPack_TotalTrafficSchedulerNumber: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 182 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 183 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 184 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 185 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 186 | me.CircuitPackClassID, |
| 187 | circuitPackEntityID, |
| 188 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 189 | me.CircuitPack_PowerShedOverride: uint32(0), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 190 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 191 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 192 | }) |
| 193 | |
| 194 | // ANI-G |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 195 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 196 | me.AniGClassID, |
| 197 | EntityID{tcontSlotId, aniGId}, |
| 198 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 199 | me.AniG_Arc: 0, |
| 200 | me.AniG_ArcInterval: 0, |
| 201 | me.AniG_Deprecated: 0, |
| 202 | me.AniG_GemBlockLength: 48, |
| 203 | me.AniG_LowerOpticalThreshold: 255, |
| 204 | me.AniG_LowerTransmitPowerThreshold: 129, |
| 205 | me.AniG_OnuResponseTime: 0, |
| 206 | me.AniG_OpticalSignalLevel: 57428, |
| 207 | me.AniG_PiggybackDbaReporting: 0, |
| 208 | me.AniG_SignalDegradeThreshold: 9, |
| 209 | me.AniG_SignalFailThreshold: 5, |
| 210 | me.AniG_SrIndication: 1, |
| 211 | me.AniG_TotalTcontNumber: 8, |
| 212 | me.AniG_TransmitOpticalLevel: 3171, |
| 213 | me.AniG_UpperOpticalThreshold: 255, |
| 214 | me.AniG_UpperTransmitPowerThreshold: 129, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 215 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 216 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 217 | }) |
| 218 | |
| 219 | // circuitPack Ethernet |
| 220 | // NOTE the circuit pack is divided in multiple messages as too big to fit in a single one |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 221 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 222 | me.CircuitPackClassID, |
| 223 | circuitPackEntityID, |
| 224 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 225 | me.CircuitPack_Type: ethernetUnitType, |
| 226 | me.CircuitPack_NumberOfPorts: ethUniPortCount, |
| 227 | me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack", 20), |
| 228 | me.CircuitPack_Version: ToOctets("v0.0.1", 20), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 229 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 230 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 231 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 232 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 233 | me.CircuitPackClassID, |
| 234 | circuitPackEntityID, |
| 235 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 236 | me.CircuitPack_VendorId: ToOctets("ONF", 4), |
| 237 | me.CircuitPack_AdministrativeState: 0, |
| 238 | me.CircuitPack_OperationalState: 0, |
| 239 | me.CircuitPack_BridgedOrIpInd: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 240 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 241 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 242 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 243 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 244 | me.CircuitPackClassID, |
| 245 | circuitPackEntityID, |
| 246 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 247 | me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20), |
| 248 | me.CircuitPack_CardConfiguration: 0, |
| 249 | me.CircuitPack_TotalTContBufferNumber: 8, |
| 250 | me.CircuitPack_TotalPriorityQueueNumber: 8, |
| 251 | me.CircuitPack_TotalTrafficSchedulerNumber: 16, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 252 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 253 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 254 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 255 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 256 | me.CircuitPackClassID, |
| 257 | circuitPackEntityID, |
| 258 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 259 | me.CircuitPack_PowerShedOverride: uint32(0), |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 260 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 261 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 262 | }) |
| 263 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 264 | if potsUniPortCount > 0 { |
| 265 | // circuitPack POTS |
| 266 | // NOTE the circuit pack is divided in multiple messages as too big to fit in a single one |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 267 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 268 | me.CircuitPackClassID, |
| 269 | circuitPackEntityID, |
| 270 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 271 | me.CircuitPack_Type: potsUnitType, |
| 272 | me.CircuitPack_NumberOfPorts: potsUniPortCount, |
| 273 | me.CircuitPack_SerialNumber: ToOctets("BBSM-Circuit-Pack", 20), |
| 274 | me.CircuitPack_Version: ToOctets("v0.0.1", 20), |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 275 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 276 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 277 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 278 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 279 | me.CircuitPackClassID, |
| 280 | circuitPackEntityID, |
| 281 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 282 | me.CircuitPack_VendorId: ToOctets("ONF", 4), |
| 283 | me.CircuitPack_AdministrativeState: 0, |
| 284 | me.CircuitPack_OperationalState: 0, |
| 285 | me.CircuitPack_BridgedOrIpInd: 0, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 286 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 287 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 288 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 289 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 290 | me.CircuitPackClassID, |
| 291 | circuitPackEntityID, |
| 292 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 293 | me.CircuitPack_EquipmentId: ToOctets("BBSM-Circuit-Pack", 20), |
| 294 | me.CircuitPack_CardConfiguration: 0, |
| 295 | me.CircuitPack_TotalTContBufferNumber: 8, |
| 296 | me.CircuitPack_TotalPriorityQueueNumber: 8, |
| 297 | me.CircuitPack_TotalTrafficSchedulerNumber: 16, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 298 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 299 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 300 | }) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 301 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 302 | me.CircuitPackClassID, |
| 303 | circuitPackEntityID, |
| 304 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 305 | me.CircuitPack_PowerShedOverride: uint32(0), |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 306 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 307 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 308 | }) |
| 309 | } |
| 310 | |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 311 | // PPTP and UNI-Gs |
| 312 | // NOTE this are dependent on the number of UNI this ONU supports |
| 313 | // Through an identical ID, the UNI-G ME is implicitly linked to an instance of a PPTP |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 314 | totalPortsCount := ethUniPortCount + potsUniPortCount |
| 315 | for i := 1; i <= totalPortsCount; i++ { |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 316 | uniEntityId := GenerateUniPortEntityId(uint32(i)) |
| 317 | |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 318 | if i <= ethUniPortCount { |
| 319 | // first, create the correct amount of ethernet UNIs, the same is done in onu.go |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 320 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 321 | me.PhysicalPathTerminationPointEthernetUniClassID, |
| 322 | uniEntityId, |
| 323 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 324 | me.PhysicalPathTerminationPointEthernetUni_ExpectedType: 0, |
| 325 | me.PhysicalPathTerminationPointEthernetUni_SensedType: ethernetUnitType, |
| 326 | me.PhysicalPathTerminationPointEthernetUni_AutoDetectionConfiguration: 0, |
| 327 | me.PhysicalPathTerminationPointEthernetUni_EthernetLoopbackConfiguration: 0, |
| 328 | me.PhysicalPathTerminationPointEthernetUni_AdministrativeState: 0, |
| 329 | me.PhysicalPathTerminationPointEthernetUni_OperationalState: 0, |
| 330 | me.PhysicalPathTerminationPointEthernetUni_ConfigurationInd: 3, |
| 331 | me.PhysicalPathTerminationPointEthernetUni_MaxFrameSize: 1518, |
| 332 | me.PhysicalPathTerminationPointEthernetUni_DteOrDceInd: 0, |
| 333 | me.PhysicalPathTerminationPointEthernetUni_PauseTime: 0, |
| 334 | me.PhysicalPathTerminationPointEthernetUni_BridgedOrIpInd: 2, |
| 335 | me.PhysicalPathTerminationPointEthernetUni_Arc: 0, |
| 336 | me.PhysicalPathTerminationPointEthernetUni_ArcInterval: 0, |
| 337 | me.PhysicalPathTerminationPointEthernetUni_PppoeFilter: 0, |
| 338 | me.PhysicalPathTerminationPointEthernetUni_PowerControl: 0, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 339 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 340 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 341 | }) |
| 342 | } else { |
| 343 | // the remaining ones are pots UNIs, the same is done in onu.go |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 344 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 345 | me.PhysicalPathTerminationPointPotsUniClassID, |
| 346 | uniEntityId, |
| 347 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 348 | me.PhysicalPathTerminationPointPotsUni_AdministrativeState: 0, |
| 349 | me.PhysicalPathTerminationPointPotsUni_Deprecated: 0, |
| 350 | me.PhysicalPathTerminationPointPotsUni_Arc: 0, |
| 351 | me.PhysicalPathTerminationPointPotsUni_ArcInterval: 0, |
| 352 | me.PhysicalPathTerminationPointPotsUni_Impedance: 0, |
| 353 | me.PhysicalPathTerminationPointPotsUni_TransmissionPath: 0, |
| 354 | me.PhysicalPathTerminationPointPotsUni_RxGain: 0, |
| 355 | me.PhysicalPathTerminationPointPotsUni_TxGain: 0, |
| 356 | me.PhysicalPathTerminationPointPotsUni_OperationalState: 0, |
| 357 | me.PhysicalPathTerminationPointPotsUni_HookState: 0, |
| 358 | me.PhysicalPathTerminationPointPotsUni_PotsHoldoverTime: 0, |
| 359 | me.PhysicalPathTerminationPointPotsUni_NominalFeedVoltage: 0, |
| 360 | me.PhysicalPathTerminationPointPotsUni_LossOfSoftswitch: 0, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 361 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 362 | nil, |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 363 | }) |
| 364 | } |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 365 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 366 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 367 | me.UniGClassID, |
| 368 | uniEntityId, |
| 369 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 370 | me.UniG_AdministrativeState: 0, |
| 371 | me.UniG_Deprecated: 0, |
| 372 | me.UniG_ManagementCapability: 0, |
| 373 | me.UniG_NonOmciManagementIdentifier: 0, |
| 374 | me.UniG_RelayAgentOptions: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 375 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 376 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 377 | }) |
| 378 | |
| 379 | // Downstream Queues (related to PPTP) |
Holger Hildebrandt | 01f92ce | 2022-12-20 09:33:57 +0000 | [diff] [blame] | 380 | // downstreamPriorityQueues for each UNI Port |
| 381 | // EntityID = MSB: cardHolderSlotID, LSB: uniPortNo<<4 + prio |
| 382 | for j := 0; j < downstreamPriorityQueues; j++ { |
| 383 | queueEntityId := EntityID{cardHolderSlotID, byte(i<<4 + j)} |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 384 | |
| 385 | // we first report the PriorityQueue without any attribute |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 386 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 387 | me.PriorityQueueClassID, |
| 388 | queueEntityId, //was not reported in the original implementation |
| 389 | me.AttributeValueMap{}, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 390 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 391 | }) |
| 392 | |
| 393 | // then we report it with the required attributes |
| 394 | // In the downstream direction, the first byte is the slot number and the second byte is the port number of the queue's destination port. |
| 395 | relatedPort := append(uniEntityId, 0x00, byte(j)) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 396 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 397 | me.PriorityQueueClassID, |
| 398 | queueEntityId, //was not reported in the original implementation |
| 399 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 400 | me.PriorityQueue_QueueConfigurationOption: 0, |
| 401 | me.PriorityQueue_MaximumQueueSize: 100, |
| 402 | me.PriorityQueue_AllocatedQueueSize: 100, |
| 403 | me.PriorityQueue_DiscardBlockCounterResetInterval: 0, |
| 404 | me.PriorityQueue_ThresholdValueForDiscardedBlocksDueToBufferOverflow: 0, |
| 405 | me.PriorityQueue_RelatedPort: relatedPort.ToUint32(), |
| 406 | me.PriorityQueue_TrafficSchedulerPointer: 0, //it was hardcoded to 0x0108 in the current implementation |
| 407 | me.PriorityQueue_Weight: 1, |
| 408 | me.PriorityQueue_BackPressureOperation: 1, |
| 409 | me.PriorityQueue_BackPressureTime: 0, |
| 410 | me.PriorityQueue_BackPressureOccurQueueThreshold: 0, |
| 411 | me.PriorityQueue_BackPressureClearQueueThreshold: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 412 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 413 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 414 | }) |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | // T-CONTS and Traffic Schedulers |
| 419 | for i := 1; i <= tconts; i++ { |
| 420 | tcontEntityId := EntityID{tcontSlotId, byte(i)} |
| 421 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 422 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 423 | me.TContClassID, |
| 424 | tcontEntityId, |
| 425 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 426 | me.TCont_AllocId: 65535, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 427 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 428 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 429 | }) |
| 430 | |
| 431 | tsEntityId := EntityID{cardHolderSlotID, byte(i)} |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 432 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 433 | me.TrafficSchedulerClassID, |
| 434 | tsEntityId, //was not reported in the original implementation |
| 435 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 436 | me.TrafficScheduler_TContPointer: tcontEntityId.ToUint16(), // was hardcoded to a non-existing t-cont |
| 437 | me.TrafficScheduler_TrafficSchedulerPointer: 0, |
| 438 | me.TrafficScheduler_Policy: 02, |
| 439 | me.TrafficScheduler_PriorityWeight: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 440 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 441 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 442 | }) |
| 443 | |
Holger Hildebrandt | 01f92ce | 2022-12-20 09:33:57 +0000 | [diff] [blame] | 444 | for j := 0; j < upstreamPriorityQueues; j++ { |
| 445 | queueEntityId := EntityID{tcontSlotId, byte(i<<4 + j)} |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 446 | // Upstream Queues (related to traffic schedulers) |
Holger Hildebrandt | 01f92ce | 2022-12-20 09:33:57 +0000 | [diff] [blame] | 447 | // upstreamPriorityQueues per TCONT |
| 448 | // EntityID = MSB: tcontSlotId, LSB: tcontNo<<4 + prio |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 449 | |
| 450 | // we first report the PriorityQueue without any attribute |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 451 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 452 | me.PriorityQueueClassID, |
| 453 | queueEntityId, //was not reported in the original implementation |
| 454 | me.AttributeValueMap{}, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 455 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 456 | }) |
| 457 | |
| 458 | // then we report it with the required attributes |
| 459 | // In the upstream direction, the first 2 bytes are the ME ID of the associated T- CONT, the first byte of which is a slot number, the second byte a T-CONT number. |
| 460 | relatedPort := append(tcontEntityId, 0x00, byte(j)) |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 461 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 462 | me.PriorityQueueClassID, |
| 463 | queueEntityId, //was not reported in the original implementation |
| 464 | me.AttributeValueMap{ |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 465 | me.PriorityQueue_QueueConfigurationOption: 0, |
| 466 | me.PriorityQueue_MaximumQueueSize: 100, |
| 467 | me.PriorityQueue_AllocatedQueueSize: 100, |
| 468 | me.PriorityQueue_DiscardBlockCounterResetInterval: 0, |
| 469 | me.PriorityQueue_ThresholdValueForDiscardedBlocksDueToBufferOverflow: 0, |
| 470 | me.PriorityQueue_RelatedPort: relatedPort.ToUint32(), |
| 471 | me.PriorityQueue_TrafficSchedulerPointer: tsEntityId.ToUint16(), //it was hardcoded to 0x0108 in the current implementation |
| 472 | me.PriorityQueue_Weight: 1, |
| 473 | me.PriorityQueue_BackPressureOperation: 1, |
| 474 | me.PriorityQueue_BackPressureTime: 0, |
| 475 | me.PriorityQueue_BackPressureOccurQueueThreshold: 0, |
| 476 | me.PriorityQueue_BackPressureClearQueueThreshold: 0, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 477 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 478 | nil, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 479 | }) |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | // ONU-2g |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 484 | |
| 485 | onu2g := MibDbEntry{ |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 486 | me.Onu2GClassID, |
| 487 | EntityID{0x00, 0x00}, |
| 488 | me.AttributeValueMap{ |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 489 | //me.Onu2G_EquipmentId: 1, |
| 490 | //me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion: 2, |
| 491 | //me.Onu2G_VendorProductCode: 3, |
| 492 | //me.Onu2G_SecurityCapability: 4, |
| 493 | //me.Onu2G_SecurityMode: 5, |
| 494 | |
Elia Battiston | 9bfe110 | 2022-02-03 10:38:03 +0100 | [diff] [blame] | 495 | me.Onu2G_TotalPriorityQueueNumber: 64, |
| 496 | me.Onu2G_TotalTrafficSchedulerNumber: 8, |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 497 | me.Onu2G_Deprecated: 1, |
| 498 | me.Onu2G_TotalGemPortIdNumber: 8, |
| 499 | me.Onu2G_Sysuptime: 6, |
| 500 | me.Onu2G_ConnectivityCapability: 127, |
| 501 | me.Onu2G_CurrentConnectivityMode: 7, |
| 502 | me.Onu2G_QualityOfServiceQosConfigurationFlexibility: 63, |
| 503 | me.Onu2G_PriorityQueueScaleFactor: 1, |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 504 | }, |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 505 | nil, |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 506 | } |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 507 | |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 508 | if common.Config.BBSim.InjectOmciUnknownAttributes { |
Holger Hildebrandt | 7840378 | 2022-05-13 10:59:31 +0000 | [diff] [blame] | 509 | // NOTE the TxID is actually replaced |
| 510 | // by SetTxIdInEncodedPacket in CreateMibUploadNextResponse |
| 511 | txId := uint16(33066) |
| 512 | |
| 513 | b := make([]byte, 4) |
| 514 | binary.BigEndian.PutUint16(b, txId) |
| 515 | b[2] = byte(omci.MibUploadNextResponseType) |
| 516 | b[3] = byte(omci.BaselineIdent) |
| 517 | omciHdr := hex.EncodeToString(b) |
| 518 | |
| 519 | //omciHdr := "00032e0a" |
| 520 | msgHdr := "00020000" |
| 521 | trailer := "0000002828ce00e2" |
| 522 | |
| 523 | msg := omciHdr + msgHdr + unknownAttribPktReportedMeHdr + unknownAttribPktAttributes + trailer |
| 524 | data, err := hex.DecodeString(msg) |
| 525 | if err != nil { |
| 526 | omciLogger.Fatal("cannot-create-custom-packet") |
| 527 | } |
| 528 | packet := gopacket.NewPacket(data, omci.LayerTypeOMCI, gopacket.Lazy) |
| 529 | |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 530 | onu2g = MibDbEntry{ |
| 531 | me.Onu2GClassID, |
| 532 | nil, |
| 533 | me.AttributeValueMap{}, |
Holger Hildebrandt | 7840378 | 2022-05-13 10:59:31 +0000 | [diff] [blame] | 534 | packet.Data(), |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 538 | mibDb.baselineItems = append(mibDb.baselineItems, onu2g) |
Matteo Scandolo | 7011fc9 | 2022-03-16 15:50:15 -0700 | [diff] [blame] | 539 | |
| 540 | if common.Config.BBSim.InjectOmciUnknownMe { |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 541 | // NOTE the TxID is actually replaced |
| 542 | // by SetTxIdInEncodedPacket in CreateMibUploadNextResponse |
| 543 | txId := uint16(33066) |
| 544 | |
| 545 | b := make([]byte, 4) |
| 546 | binary.BigEndian.PutUint16(b, txId) |
| 547 | b[2] = byte(omci.MibUploadNextResponseType) |
| 548 | b[3] = byte(omci.BaselineIdent) |
| 549 | omciHdr := hex.EncodeToString(b) |
| 550 | |
| 551 | //omciHdr := "00032e0a" |
| 552 | msgHdr := "00020000" |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 553 | trailer := "0000002828ce00e2" |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 554 | msg := omciHdr + msgHdr + unknownMePktReportedMeHdr + unknownMePktAttributes + trailer |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 555 | data, err := hex.DecodeString(msg) |
| 556 | if err != nil { |
| 557 | omciLogger.Fatal("cannot-create-custom-packet") |
| 558 | } |
| 559 | |
| 560 | packet := gopacket.NewPacket(data, omci.LayerTypeOMCI, gopacket.Lazy) |
| 561 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 562 | mibDb.baselineItems = append(mibDb.baselineItems, MibDbEntry{ |
Matteo Scandolo | cfedba4 | 2022-02-14 16:08:54 -0800 | [diff] [blame] | 563 | me.ClassID(37), // G.988 "Intentionally left blank" |
| 564 | nil, |
| 565 | me.AttributeValueMap{}, |
| 566 | packet.Data(), |
| 567 | }) |
| 568 | } |
| 569 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 570 | mibDb.NumberOfBaselineCommands = uint16(len(mibDb.baselineItems)) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 571 | |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 572 | // Create extended MIB upload responses |
| 573 | omciLayer := &omci.OMCI{ |
| 574 | TransactionID: 0xFFFF, //to be replaced later on |
| 575 | MessageType: omci.MibUploadNextResponseType, |
| 576 | DeviceIdentifier: omci.ExtendedIdent, |
| 577 | } |
| 578 | var i uint16 = 0 |
| 579 | for i < mibDb.NumberOfBaselineCommands { |
| 580 | currentEntry := mibDb.baselineItems[i] |
| 581 | for mibDb.baselineItems[i].packet != nil { |
| 582 | // Skip any entry with a predefined packet currently used for MEs with unknown ClassID or unknown attributes. |
| 583 | // This information will be added later to the last extended response packet |
| 584 | i++ |
| 585 | currentEntry = mibDb.baselineItems[i] |
| 586 | } |
| 587 | reportedME, meErr := me.LoadManagedEntityDefinition(currentEntry.classId, me.ParamData{ |
| 588 | EntityID: currentEntry.entityId.ToUint16(), |
| 589 | Attributes: currentEntry.params, |
| 590 | }) |
| 591 | if meErr.GetError() != nil { |
| 592 | omciLogger.Errorf("Error while generating reportedME %s: %v", currentEntry.classId.String(), meErr.Error()) |
| 593 | } |
| 594 | request := &omci.MibUploadNextResponse{ |
| 595 | MeBasePacket: omci.MeBasePacket{ |
| 596 | EntityClass: me.OnuDataClassID, |
| 597 | EntityInstance: uint16(0), |
| 598 | Extended: true, |
| 599 | }, |
| 600 | ReportedME: *reportedME, |
| 601 | AdditionalMEs: make([]me.ManagedEntity, 0), |
| 602 | } |
| 603 | i++ |
| 604 | var outgoingPacket []byte |
| 605 | var outgoingPacketLen = 0 |
| 606 | addMeLoop: |
| 607 | for outgoingPacketLen <= omci.MaxExtendedLength-omci.MaxBaselineLength && i < mibDb.NumberOfBaselineCommands { |
| 608 | currentEntry := mibDb.baselineItems[i] |
| 609 | for mibDb.baselineItems[i].packet != nil { |
| 610 | // Skip any entry with a predefined packet currently used for MEs with unknown ClassID or unknown attributes. |
| 611 | // This information will be added later to the last extended response packet |
| 612 | i++ |
| 613 | if i < mibDb.NumberOfBaselineCommands { |
| 614 | currentEntry = mibDb.baselineItems[i] |
| 615 | } else { |
| 616 | break addMeLoop |
| 617 | } |
| 618 | } |
| 619 | additionalME, meErr := me.LoadManagedEntityDefinition(currentEntry.classId, me.ParamData{ |
| 620 | EntityID: currentEntry.entityId.ToUint16(), |
| 621 | Attributes: currentEntry.params, |
| 622 | }) |
| 623 | if meErr.GetError() != nil { |
| 624 | omciLogger.Errorf("Error while generating additionalME %s: %v", currentEntry.classId.String(), meErr.Error()) |
| 625 | } |
| 626 | request.AdditionalMEs = append(request.AdditionalMEs, *additionalME) |
| 627 | |
| 628 | var options gopacket.SerializeOptions |
| 629 | options.FixLengths = true |
| 630 | |
| 631 | buffer := gopacket.NewSerializeBuffer() |
| 632 | omciErr := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 633 | if omciErr != nil { |
| 634 | omciLogger.Errorf("Error while serializing generating additionalME %s: %v", currentEntry.classId.String(), omciErr) |
| 635 | } |
| 636 | outgoingPacket = buffer.Bytes() |
| 637 | outgoingPacketLen = len(outgoingPacket) |
| 638 | i++ |
| 639 | } |
| 640 | mibDb.extendedResponses = append(mibDb.extendedResponses, outgoingPacket) |
| 641 | mibDb.NumberOfExtendedCommands = uint16(len(mibDb.extendedResponses)) |
| 642 | |
| 643 | outgoingPacketString := strings.ToLower(hex.EncodeToString(mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1])) |
| 644 | omciLogger.Debugf("Extended MIB upload response respNo: %d length: %d string: %s", mibDb.NumberOfExtendedCommands, outgoingPacketLen, outgoingPacketString) |
| 645 | } |
| 646 | // Currently, there is enough space in the last extended response to add potential MEs with unknown ClassID or unknown attributes, if requested. |
| 647 | if common.Config.BBSim.InjectOmciUnknownMe { |
| 648 | var err error |
| 649 | mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1], err = AppendAdditionalMEs(mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1], unknownMePktReportedMeHdr, unknownMePktAttributes) |
| 650 | if err != nil { |
| 651 | omciLogger.Fatal(err) |
| 652 | } else { |
| 653 | outgoingPacketString := strings.ToLower(hex.EncodeToString(mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1])) |
| 654 | omciLogger.Debugf("Reponse with unknown ME added: %s", outgoingPacketString) |
| 655 | } |
| 656 | } |
| 657 | if common.Config.BBSim.InjectOmciUnknownAttributes { |
| 658 | var err error |
| 659 | mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1], err = AppendAdditionalMEs(mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1], unknownAttribPktReportedMeHdr, unknownAttribPktAttributes) |
| 660 | if err != nil { |
| 661 | omciLogger.Fatal(err) |
| 662 | } else { |
| 663 | outgoingPacketString := strings.ToLower(hex.EncodeToString(mibDb.extendedResponses[mibDb.NumberOfExtendedCommands-1])) |
| 664 | omciLogger.Debugf("Reponse with unknown attributes added: %s", outgoingPacketString) |
| 665 | } |
| 666 | } |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 667 | return &mibDb, nil |
| 668 | } |
Holger Hildebrandt | 236e374 | 2022-05-04 14:07:27 +0000 | [diff] [blame] | 669 | |
| 670 | func AppendAdditionalMEs(srcSlice []byte, reportedMeHdr string, attributes string) ([]byte, error) { |
| 671 | attribBytes, err := hex.DecodeString(attributes) |
| 672 | if err != nil { |
| 673 | return nil, fmt.Errorf("cannot-decode-attributes-string") |
| 674 | } |
| 675 | attribBytesLen := len(attribBytes) |
| 676 | attribBytesLenStr := fmt.Sprintf("%04X", attribBytesLen) |
| 677 | msg := attribBytesLenStr + reportedMeHdr + attributes |
| 678 | data, err := hex.DecodeString(msg) |
| 679 | if err != nil { |
| 680 | return nil, fmt.Errorf("cannot-decode-attributes") |
| 681 | } |
| 682 | dstSlice := make([]byte, len(srcSlice)) |
| 683 | copy(dstSlice, srcSlice) |
| 684 | dstSlice = append(dstSlice[:], data[:]...) |
| 685 | messageContentsLen := binary.BigEndian.Uint16(dstSlice[extRespMsgContentsLenStart:extRespMsgContentsLenEnd]) |
| 686 | dataLen := len(data) |
| 687 | newMessageContentsLen := messageContentsLen + uint16(dataLen) |
| 688 | newLenSlice := make([]byte, 2) |
| 689 | binary.BigEndian.PutUint16(newLenSlice, newMessageContentsLen) |
| 690 | copy(dstSlice[extRespMsgContentsLenStart:extRespMsgContentsLenEnd], newLenSlice[0:2]) |
| 691 | return dstSlice, nil |
| 692 | } |