Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [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 | |
| 17 | package omci |
| 18 | |
| 19 | import ( |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 20 | "errors" |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 21 | "fmt" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 22 | "github.com/google/gopacket" |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 23 | "github.com/opencord/omci-lib-go" |
| 24 | me "github.com/opencord/omci-lib-go/generated" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 25 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 26 | "strconv" |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | var omciLogger = log.WithFields(log.Fields{ |
| 30 | "module": "OMCI", |
| 31 | }) |
| 32 | |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 33 | // we have a fixed number of 8 T-CONTS |
| 34 | var reportedTcontsMeId = []uint16{ |
| 35 | 32769, |
| 36 | 32770, |
| 37 | 32771, |
| 38 | 32772, |
| 39 | 32773, |
| 40 | 32774, |
| 41 | 32775, |
| 42 | 32776, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 45 | // NOTE this is basically the same as https://github.com/opencord/voltha-openonu-adapter-go/blob/master/internal/pkg/onuadaptercore/omci_cc.go#L545-L564 |
| 46 | // we should probably move it in "omci-lib-go" |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 47 | func Serialize(msgType omci.MessageType, request gopacket.SerializableLayer, tid uint16) ([]byte, error) { |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 48 | omciLayer := &omci.OMCI{ |
| 49 | TransactionID: tid, |
| 50 | MessageType: msgType, |
| 51 | } |
| 52 | var options gopacket.SerializeOptions |
| 53 | options.FixLengths = true |
| 54 | |
| 55 | buffer := gopacket.NewSerializeBuffer() |
| 56 | err := gopacket.SerializeLayers(buffer, options, omciLayer, request) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | return buffer.Bytes(), nil |
| 61 | } |
| 62 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 63 | func CreateMibResetRequest(tid uint16) ([]byte, error) { |
| 64 | |
| 65 | request := &omci.MibResetRequest{ |
| 66 | MeBasePacket: omci.MeBasePacket{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 67 | EntityClass: me.OnuDataClassID, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 68 | }, |
| 69 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 70 | pkt, err := Serialize(omci.MibResetRequestType, request, tid) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 71 | if err != nil { |
| 72 | omciLogger.WithFields(log.Fields{ |
| 73 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 74 | }).Fatalf("Cannot Serialize MibResetRequest") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 75 | return nil, err |
| 76 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 77 | return HexEncode(pkt) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 80 | func CreateMibResetResponse(tid uint16) ([]byte, error) { |
| 81 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 82 | request := &omci.MibResetResponse{ |
| 83 | MeBasePacket: omci.MeBasePacket{ |
| 84 | EntityClass: me.OnuDataClassID, |
| 85 | }, |
| 86 | Result: me.Success, |
| 87 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 88 | pkt, err := Serialize(omci.MibResetResponseType, request, tid) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 89 | if err != nil { |
| 90 | omciLogger.WithFields(log.Fields{ |
| 91 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 92 | }).Error("Cannot Serialize MibResetResponse") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 93 | return nil, err |
| 94 | } |
| 95 | return pkt, nil |
| 96 | } |
| 97 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 98 | func CreateMibUploadRequest(tid uint16) ([]byte, error) { |
| 99 | request := &omci.MibUploadRequest{ |
| 100 | MeBasePacket: omci.MeBasePacket{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 101 | EntityClass: me.OnuDataClassID, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 102 | // Default Instance ID is 0 |
| 103 | }, |
| 104 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 105 | pkt, err := Serialize(omci.MibUploadRequestType, request, tid) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 106 | if err != nil { |
| 107 | omciLogger.WithFields(log.Fields{ |
| 108 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 109 | }).Fatalf("Cannot Serialize MibUploadRequest") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 110 | return nil, err |
| 111 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 112 | return HexEncode(pkt) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 115 | func CreateMibUploadResponse(tid uint16) ([]byte, error) { |
| 116 | |
| 117 | numberOfCommands := uint16(291) //NOTE should this be configurable? (not until we have moved all the messages away from omci-sim) |
| 118 | |
| 119 | request := &omci.MibUploadResponse{ |
| 120 | MeBasePacket: omci.MeBasePacket{ |
| 121 | EntityClass: me.OnuDataClassID, |
| 122 | }, |
| 123 | NumberOfCommands: numberOfCommands, |
| 124 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 125 | pkt, err := Serialize(omci.MibUploadResponseType, request, tid) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 126 | if err != nil { |
| 127 | omciLogger.WithFields(log.Fields{ |
| 128 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 129 | }).Error("Cannot Serialize MibUploadResponse") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 130 | return nil, err |
| 131 | } |
| 132 | return pkt, nil |
| 133 | } |
| 134 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 135 | func CreateMibUploadNextRequest(tid uint16, seqNumber uint16) ([]byte, error) { |
| 136 | |
| 137 | request := &omci.MibUploadNextRequest{ |
| 138 | MeBasePacket: omci.MeBasePacket{ |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 139 | EntityClass: me.OnuDataClassID, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 140 | // Default Instance ID is 0 |
| 141 | }, |
| 142 | CommandSequenceNumber: seqNumber, |
| 143 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 144 | pkt, err := Serialize(omci.MibUploadNextRequestType, request, tid) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 145 | |
| 146 | if err != nil { |
| 147 | omciLogger.WithFields(log.Fields{ |
| 148 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 149 | }).Fatalf("Cannot Serialize MibUploadNextRequest") |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 150 | return nil, err |
| 151 | } |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 152 | return HexEncode(pkt) |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 155 | func ParseMibUploadNextRequest(omciPkt gopacket.Packet) (*omci.MibUploadNextRequest, error) { |
| 156 | msgLayer := omciPkt.Layer(omci.LayerTypeMibUploadNextRequest) |
| 157 | if msgLayer == nil { |
| 158 | err := "omci Msg layer could not be detected for LayerTypeMibUploadNextRequest" |
| 159 | omciLogger.Error(err) |
| 160 | return nil, errors.New(err) |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 161 | } |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 162 | msgObj, msgOk := msgLayer.(*omci.MibUploadNextRequest) |
| 163 | if !msgOk { |
| 164 | err := "omci Msg layer could not be assigned for MibUploadNextRequest" |
| 165 | omciLogger.Error(err) |
| 166 | return nil, errors.New(err) |
| 167 | } |
| 168 | return msgObj, nil |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 171 | func CreateMibUploadNextResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI, mds uint8) ([]byte, error) { |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 172 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 173 | msgObj, err := ParseMibUploadNextRequest(omciPkt) |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 174 | if err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 175 | err := "omci Msg layer could not be assigned for LayerTypeGetRequest" |
| 176 | omciLogger.Error(err) |
| 177 | return nil, errors.New(err) |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 180 | omciLogger.WithFields(log.Fields{ |
| 181 | "EntityClass": msgObj.EntityClass, |
| 182 | "EntityInstance": msgObj.EntityInstance, |
| 183 | "CommandSequenceNumber": msgObj.CommandSequenceNumber, |
| 184 | }).Trace("received-omci-mibUploadNext-request") |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 185 | |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 186 | var reportedMe *me.ManagedEntity |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 187 | var meErr me.OmciErrors |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 188 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 189 | switch msgObj.CommandSequenceNumber { |
| 190 | case 0: |
| 191 | reportedMe, meErr = me.NewOnuData(me.ParamData{Attributes: me.AttributeValueMap{ |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 192 | "MibDataSync": mds, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 193 | }}) |
| 194 | if meErr.GetError() != nil { |
| 195 | omciLogger.Errorf("NewOnuData %v", meErr.Error()) |
| 196 | } |
Scott Baker | b90c431 | 2020-03-12 21:33:25 -0700 | [diff] [blame] | 197 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 198 | case 1: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 199 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 200 | EntityID: 257, // first UNI |
| 201 | Attributes: me.AttributeValueMap{ |
| 202 | "Type": 47, |
| 203 | "NumberOfPorts": 4, |
| 204 | "SerialNumber": toOctets("BBSM-Circuit-Pack", 20), |
| 205 | "Version": toOctets("v0.0.1", 20), |
| 206 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 207 | if meErr.GetError() != nil { |
| 208 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 209 | } |
| 210 | case 2: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 211 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 212 | EntityID: 257, // first UNI |
| 213 | Attributes: me.AttributeValueMap{ |
| 214 | "VendorId": "ONF", |
| 215 | "AdministrativeState": 0, |
| 216 | "OperationalState": 0, |
| 217 | "BridgedOrIpInd": 0, |
| 218 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 219 | if meErr.GetError() != nil { |
| 220 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 221 | } |
| 222 | case 3: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 223 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 224 | EntityID: 257, // first UNI |
| 225 | Attributes: me.AttributeValueMap{ |
| 226 | "EquipmentId": toOctets("BBSM-Circuit-Pack", 20), |
| 227 | "CardConfiguration": 0, |
| 228 | "TotalTContBufferNumber": 8, |
| 229 | "TotalPriorityQueueNumber": 8, |
| 230 | "TotalTrafficSchedulerNumber": 16, |
| 231 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 232 | if meErr.GetError() != nil { |
| 233 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 234 | } |
| 235 | case 4: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 236 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 237 | EntityID: 257, // first UNI |
| 238 | Attributes: me.AttributeValueMap{ |
| 239 | "PowerShedOverride": uint32(0), |
| 240 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 241 | if meErr.GetError() != nil { |
| 242 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 243 | } |
| 244 | case 5: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 245 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 246 | EntityID: 257, |
| 247 | Attributes: me.AttributeValueMap{ |
| 248 | "Type": 238, |
| 249 | "NumberOfPorts": 4, //number of UNI for this device |
| 250 | "SerialNumber": toOctets("BBSM-Circuit-Pack-2", 20), |
| 251 | "Version": toOctets("v0.0.1", 20), |
| 252 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 253 | if meErr.GetError() != nil { |
| 254 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 255 | } |
| 256 | case 6: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 257 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 258 | EntityID: 257, // first UNI |
| 259 | Attributes: me.AttributeValueMap{ |
| 260 | "VendorId": "ONF", |
| 261 | "AdministrativeState": 0, |
| 262 | "OperationalState": 0, |
| 263 | "BridgedOrIpInd": 0, |
| 264 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 265 | if meErr.GetError() != nil { |
| 266 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 267 | } |
| 268 | case 7: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 269 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 270 | EntityID: 257, // first UNI |
| 271 | Attributes: me.AttributeValueMap{ |
| 272 | "EquipmentId": toOctets("BBSM-Circuit-Pack", 20), |
| 273 | "CardConfiguration": 0, |
| 274 | "TotalTContBufferNumber": 0, |
| 275 | "TotalPriorityQueueNumber": 8, |
| 276 | "TotalTrafficSchedulerNumber": 0, |
| 277 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 278 | if meErr.GetError() != nil { |
| 279 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 280 | } |
| 281 | case 8: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 282 | reportedMe, meErr = me.NewCircuitPack(me.ParamData{ |
| 283 | EntityID: 257, // first UNI |
| 284 | Attributes: me.AttributeValueMap{ |
| 285 | "PowerShedOverride": uint32(0), |
| 286 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 287 | if meErr.GetError() != nil { |
| 288 | omciLogger.Errorf("NewCircuitPack %v", meErr.Error()) |
| 289 | } |
| 290 | case 9, 10, 11, 12: |
| 291 | // NOTE we're reporting for different UNIs, the IDs are 257, 258, 259, 260 |
| 292 | meInstance := 248 + msgObj.CommandSequenceNumber |
| 293 | reportedMe, meErr = me.NewPhysicalPathTerminationPointEthernetUni(me.ParamData{ |
| 294 | EntityID: meInstance, |
| 295 | Attributes: me.AttributeValueMap{ |
| 296 | "ExpectedType": 0, |
| 297 | "SensedType": 47, |
| 298 | "AutoDetectionConfiguration": 0, |
| 299 | "EthernetLoopbackConfiguration": 0, |
| 300 | "AdministrativeState": 0, |
| 301 | "OperationalState": 0, |
| 302 | "ConfigurationInd": 3, |
| 303 | "MaxFrameSize": 1518, |
| 304 | "DteOrDceInd": 0, |
| 305 | "PauseTime": 0, |
| 306 | "BridgedOrIpInd": 2, |
| 307 | "Arc": 0, |
| 308 | "ArcInterval": 0, |
| 309 | "PppoeFilter": 0, |
| 310 | "PowerControl": 0, |
| 311 | }}) |
| 312 | if meErr.GetError() != nil { |
| 313 | omciLogger.Errorf("NewPhysicalPathTerminationPointEthernetUni %v", meErr.Error()) |
| 314 | } |
| 315 | case 13, 14, 15, 16, 17, 18, 19, 20: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 316 | reportedMe, meErr = me.NewTCont(me.ParamData{ |
| 317 | // NOTE fetch the correct T-CONT MeID based on the sequence number |
| 318 | EntityID: reportedTcontsMeId[msgObj.CommandSequenceNumber-13], |
| 319 | Attributes: me.AttributeValueMap{ |
| 320 | "AllocId": 65535, |
| 321 | }, |
| 322 | }) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 323 | if meErr.GetError() != nil { |
| 324 | omciLogger.Errorf("NewTCont %v", meErr.Error()) |
| 325 | } |
| 326 | case 21: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 327 | reportedMe, meErr = me.NewAniG(me.ParamData{ |
| 328 | EntityID: 32769, // same as the first T-CONT |
| 329 | Attributes: me.AttributeValueMap{ |
| 330 | "Arc": 0, |
| 331 | "ArcInterval": 0, |
| 332 | "Deprecated": 0, |
| 333 | "GemBlockLength": 48, |
| 334 | "LowerOpticalThreshold": 255, |
| 335 | "LowerTransmitPowerThreshold": 129, |
| 336 | "OnuResponseTime": 0, |
| 337 | "OpticalSignalLevel": 57428, |
| 338 | "PiggybackDbaReporting": 0, |
| 339 | "SignalDegradeThreshold": 9, |
| 340 | "SignalFailThreshold": 5, |
| 341 | "SrIndication": 1, |
| 342 | "TotalTcontNumber": 8, |
| 343 | "TransmitOpticalLevel": 3171, |
| 344 | "UpperOpticalThreshold": 255, |
| 345 | "UpperTransmitPowerThreshold": 129, |
| 346 | }, |
| 347 | }) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 348 | if meErr.GetError() != nil { |
| 349 | omciLogger.Errorf("NewAniG %v", meErr.Error()) |
| 350 | } |
| 351 | case 22, 23, 24, 25: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 352 | // NOTE we're reporting for different UNIs, the IDs are 257, 258, 259, 260 |
| 353 | meInstance := 235 + msgObj.CommandSequenceNumber |
| 354 | reportedMe, meErr = me.NewUniG(me.ParamData{ |
| 355 | EntityID: meInstance, |
| 356 | Attributes: me.AttributeValueMap{ |
| 357 | "AdministrativeState": 0, |
| 358 | "Deprecated": 0, |
| 359 | "ManagementCapability": 0, |
| 360 | "NonOmciManagementIdentifier": 0, |
| 361 | "RelayAgentOptions": 0, |
| 362 | }}) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 363 | if meErr.GetError() != nil { |
| 364 | omciLogger.Errorf("NewUniG %v", meErr.Error()) |
| 365 | } |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 366 | // Prior-Q with mask downstream |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 367 | case 26, 30, 34, 38, 42, 46, 50, 54, |
| 368 | 58, 62, 66, 70, 74, 78, 82, 86, |
| 369 | 90, 94, 98, 102, 106, 110, 114, 118, |
| 370 | 122, 126, 130, 134, 138, 142, 146, 150, |
| 371 | 154, 158, 162, 166, 170, 174, 178, 182, |
| 372 | 186, 190, 194, 198, 202, 206, 210, 214, |
| 373 | 218, 222, 226, 230, 234, 238, 242, 246, |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 374 | 250, 254, 258, 262, 266, 270, 274, 278, |
| 375 | // Prior-Q with attribute list downstream |
| 376 | 27, 31, 35, 39, 43, 47, 51, 55, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 377 | 59, 63, 67, 71, 75, 79, 83, 87, |
| 378 | 91, 95, 99, 103, 107, 111, 115, 119, |
| 379 | 123, 127, 131, 135, 139, 143, 147, 151, |
| 380 | 155, 159, 163, 167, 171, 175, 179, 183, |
| 381 | 187, 191, 195, 199, 203, 207, 211, 215, |
| 382 | 219, 223, 227, 231, 235, 239, 243, 247, |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 383 | 251, 255, 259, 263, 267, 271, 275, 279, |
| 384 | // Prior-Q with mask upstream |
| 385 | 28, 32, 36, 40, 44, 48, 52, 56, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 386 | 60, 64, 68, 72, 76, 80, 84, 88, |
| 387 | 92, 96, 100, 104, 108, 112, 116, 120, |
| 388 | 124, 128, 132, 136, 140, 144, 148, 152, |
| 389 | 156, 160, 164, 168, 172, 176, 180, 184, |
| 390 | 188, 192, 196, 200, 204, 208, 212, 216, |
| 391 | 220, 224, 228, 232, 236, 240, 244, 248, |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 392 | 252, 256, 260, 264, 268, 272, 276, 280, |
| 393 | // Prior-Q with attribute list upstream |
| 394 | 29, 33, 37, 41, 45, 49, 53, 57, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 395 | 61, 65, 69, 73, 77, 81, 85, 89, |
| 396 | 93, 97, 101, 105, 109, 113, 117, 121, |
| 397 | 125, 129, 133, 137, 141, 145, 149, 153, |
| 398 | 157, 161, 165, 169, 173, 177, 181, 185, |
| 399 | 189, 193, 197, 201, 205, 209, 213, 217, |
| 400 | 221, 225, 229, 233, 237, 241, 245, 249, |
| 401 | 253, 257, 261, 265, 269, 273, 277, 281: |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 402 | |
| 403 | reportedMe, meErr = GeneratePriorityQueueMe(msgObj.CommandSequenceNumber) |
| 404 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 405 | if meErr.GetError() != nil { |
| 406 | omciLogger.Errorf("NewPriorityQueue %v", meErr.Error()) |
| 407 | } |
| 408 | case 282, 283, 284, 285, 286, 287, 288, 289: |
| 409 | reportedMe, meErr = me.NewTrafficScheduler(me.ParamData{Attributes: me.AttributeValueMap{ |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 410 | "TContPointer": 32768, // NOTE does this need to change? |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 411 | "TrafficSchedulerPointer": 0, |
| 412 | "Policy": 02, |
| 413 | "PriorityWeight": 0, |
| 414 | }}) |
| 415 | if meErr.GetError() != nil { |
| 416 | omciLogger.Errorf("NewTrafficScheduler %v", meErr.Error()) |
| 417 | } |
| 418 | case 290: |
| 419 | reportedMe, meErr = me.NewOnu2G(me.ParamData{Attributes: me.AttributeValueMap{ |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 420 | "ConnectivityCapability": 127, |
| 421 | "CurrentConnectivityMode": 0, |
| 422 | "Deprecated": 1, |
| 423 | "PriorityQueueScaleFactor": 1, |
| 424 | "QualityOfServiceQosConfigurationFlexibility": 63, |
| 425 | "Sysuptime": 0, |
| 426 | "TotalGemPortIdNumber": 8, |
| 427 | "TotalPriorityQueueNumber": 64, |
| 428 | "TotalTrafficSchedulerNumber": 8, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 429 | }}) |
| 430 | if meErr.GetError() != nil { |
| 431 | omciLogger.Errorf("NewOnu2G %v", meErr.Error()) |
| 432 | } |
| 433 | default: |
| 434 | omciLogger.Warn("unsupported-CommandSequenceNumber-in-mib-upload-next", msgObj.CommandSequenceNumber) |
| 435 | return nil, nil |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 438 | response := &omci.MibUploadNextResponse{ |
| 439 | MeBasePacket: omci.MeBasePacket{ |
| 440 | EntityClass: me.OnuDataClassID, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 441 | }, |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 442 | ReportedME: *reportedMe, |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 443 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 444 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 445 | omciLogger.WithFields(log.Fields{ |
| 446 | "reportedMe": reportedMe, |
| 447 | }).Trace("created-omci-mibUploadNext-response") |
| 448 | |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 449 | pkt, err := Serialize(omci.MibUploadNextResponseType, response, omciMsg.TransactionID) |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 450 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 451 | if err != nil { |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 452 | omciLogger.WithFields(log.Fields{ |
| 453 | "Err": err, |
Matteo Scandolo | 992a23e | 2021-02-04 15:35:04 -0800 | [diff] [blame] | 454 | }).Fatalf("Cannot Serialize MibUploadNextRequest") |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 455 | return nil, err |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 456 | } |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 457 | |
Matteo Scandolo | f9d4341 | 2021-01-12 11:11:34 -0800 | [diff] [blame] | 458 | return pkt, nil |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame] | 459 | } |
Matteo Scandolo | 9a1842d | 2021-02-08 16:00:17 -0800 | [diff] [blame] | 460 | |
| 461 | func GeneratePriorityQueueMe(sequence uint16) (*me.ManagedEntity, me.OmciErrors) { |
| 462 | |
| 463 | iteration := sequence - 26 |
| 464 | |
| 465 | // we report 256 messages for priority queues, |
| 466 | // 128 downstream and 128 upstream |
| 467 | // we repeat 64 times the quartet: |
| 468 | // - downstream with mask |
| 469 | // - downstream with attributes (same MeID as the previous) |
| 470 | // - upstream with mask |
| 471 | // - upstream with attributes (same MeID as the previous) |
| 472 | |
| 473 | // very ugly way to define whether the priority queue is upstream or downstream |
| 474 | // (first 2 blocks are downstream, second two are upstream) |
| 475 | // for example sequence 26, 27 are downstream |
| 476 | // sequence 28, 29 are upstream |
| 477 | isDownstream := ((sequence-26)%4 == 0) || ((sequence-27)%4 == 0) |
| 478 | // entityIds are: |
| 479 | // - 1 to 64 for downstream (hex 0001 to 0040) |
| 480 | // - 32769 to 32832 for upstream (hex 8001 to 8040) |
| 481 | var entityId uint16 |
| 482 | if isDownstream { |
| 483 | entityId = (iteration)/4 + 1 |
| 484 | } else { |
| 485 | entityId = (iteration)/4 + 32769 |
| 486 | } |
| 487 | |
| 488 | var relatedPort uint32 |
| 489 | if isDownstream { |
| 490 | // downstream the related port is: |
| 491 | // - Circuit Pack/ UNI port of UNI Port (01 01/04) |
| 492 | // - priority 0 to 15 -> iteration%16 |
| 493 | |
| 494 | // every 16 iteration (of 4 commands) we move to the next the TCONT MeID |
| 495 | uniPort := int(iteration/64) + 1 |
| 496 | priority := (iteration / 4) % 16 |
| 497 | |
| 498 | // concat the uniPort and priority in an hex string |
| 499 | // we have a single circuit pack, so we hardcode it |
| 500 | v := fmt.Sprintf("010%x000%x", uniPort, priority) |
| 501 | |
| 502 | // convert back to int |
| 503 | k, _ := strconv.ParseInt(v, 16, 64) |
| 504 | relatedPort = uint32(k) |
| 505 | } else { |
| 506 | // upstream the related port is: |
| 507 | // - Tcont MeID -> reportedTcontsMeId[ceil(iteration/4/8)] |
| 508 | // - priority 0 to 7 -> iteration%8 |
| 509 | |
| 510 | // every 8 iteration (of 4 commands) we move to the next the TCONT MeID |
| 511 | tcontMe := reportedTcontsMeId[int(iteration/32)] |
| 512 | priority := (iteration / 4) % 8 |
| 513 | |
| 514 | // concat the tcontMe and priority in an hex string |
| 515 | v := fmt.Sprintf("%x000%x", tcontMe, priority) |
| 516 | |
| 517 | // convert back to int |
| 518 | k, _ := strconv.ParseInt(v, 16, 64) |
| 519 | relatedPort = uint32(k) |
| 520 | } |
| 521 | |
| 522 | return me.NewPriorityQueue(me.ParamData{ |
| 523 | EntityID: entityId, |
| 524 | Attributes: me.AttributeValueMap{ |
| 525 | "QueueConfigurationOption": 0, |
| 526 | "MaximumQueueSize": 100, |
| 527 | "AllocatedQueueSize": 100, |
| 528 | "DiscardBlockCounterResetInterval": 0, |
| 529 | "ThresholdValueForDiscardedBlocksDueToBufferOverflow": 0, |
| 530 | "RelatedPort": relatedPort, |
| 531 | "TrafficSchedulerPointer": 264, |
| 532 | "Weight": 1, |
| 533 | "BackPressureOperation": 1, |
| 534 | "BackPressureTime": 0, |
| 535 | "BackPressureOccurQueueThreshold": 0, |
| 536 | "BackPressureClearQueueThreshold": 0, |
| 537 | }, |
| 538 | }) |
| 539 | } |