Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 8 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 10 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 16 | */ |
| 17 | package omci_test |
| 18 | |
| 19 | import ( |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 20 | mapset "github.com/deckarep/golang-set" |
| 21 | "github.com/google/gopacket" |
David K. Bainbridge | adf422d | 2021-04-09 16:06:41 +0000 | [diff] [blame] | 22 | . "github.com/opencord/omci-lib-go" |
| 23 | me "github.com/opencord/omci-lib-go/generated" |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 24 | "github.com/stretchr/testify/assert" |
| 25 | "math/rand" |
| 26 | "testing" |
| 27 | "time" |
| 28 | ) |
| 29 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 30 | var messageTypeTestFuncs map[MessageType]func(*testing.T, *me.ManagedEntity, DeviceIdent) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 31 | |
| 32 | func init() { |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 33 | messageTypeTestFuncs = make(map[MessageType]func(*testing.T, *me.ManagedEntity, DeviceIdent), 0) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 34 | |
| 35 | messageTypeTestFuncs[CreateRequestType] = testCreateRequestTypeMeFrame |
| 36 | messageTypeTestFuncs[CreateResponseType] = testCreateResponseTypeMeFrame |
| 37 | messageTypeTestFuncs[DeleteRequestType] = testDeleteRequestTypeMeFrame |
| 38 | messageTypeTestFuncs[DeleteResponseType] = testDeleteResponseTypeMeFrame |
| 39 | messageTypeTestFuncs[SetRequestType] = testSetRequestTypeMeFrame |
| 40 | messageTypeTestFuncs[SetResponseType] = testSetResponseTypeMeFrame |
| 41 | messageTypeTestFuncs[GetRequestType] = testGetRequestTypeMeFrame |
| 42 | messageTypeTestFuncs[GetResponseType] = testGetResponseTypeMeFrame |
| 43 | messageTypeTestFuncs[GetAllAlarmsRequestType] = testGetAllAlarmsRequestTypeMeFrame |
| 44 | messageTypeTestFuncs[GetAllAlarmsResponseType] = testGetAllAlarmsResponseTypeMeFrame |
| 45 | messageTypeTestFuncs[GetAllAlarmsNextRequestType] = testGetAllAlarmsNextRequestTypeMeFrame |
| 46 | messageTypeTestFuncs[GetAllAlarmsNextResponseType] = testGetAllAlarmsNextResponseTypeMeFrame |
| 47 | messageTypeTestFuncs[MibUploadRequestType] = testMibUploadRequestTypeMeFrame |
| 48 | messageTypeTestFuncs[MibUploadResponseType] = testMibUploadResponseTypeMeFrame |
| 49 | messageTypeTestFuncs[MibUploadNextRequestType] = testMibUploadNextRequestTypeMeFrame |
| 50 | messageTypeTestFuncs[MibUploadNextResponseType] = testMibUploadNextResponseTypeMeFrame |
| 51 | messageTypeTestFuncs[MibResetRequestType] = testMibResetRequestTypeMeFrame |
| 52 | messageTypeTestFuncs[MibResetResponseType] = testMibResetResponseTypeMeFrame |
| 53 | messageTypeTestFuncs[TestRequestType] = testTestRequestTypeMeFrame |
| 54 | messageTypeTestFuncs[TestResponseType] = testTestResponseTypeMeFrame |
| 55 | messageTypeTestFuncs[StartSoftwareDownloadRequestType] = testStartSoftwareDownloadRequestTypeMeFrame |
| 56 | messageTypeTestFuncs[StartSoftwareDownloadResponseType] = testStartSoftwareDownloadResponseTypeMeFrame |
| 57 | messageTypeTestFuncs[DownloadSectionRequestType] = testDownloadSectionRequestTypeMeFrame |
| 58 | messageTypeTestFuncs[DownloadSectionResponseType] = testDownloadSectionResponseTypeMeFrame |
| 59 | messageTypeTestFuncs[EndSoftwareDownloadRequestType] = testEndSoftwareDownloadRequestTypeMeFrame |
| 60 | messageTypeTestFuncs[EndSoftwareDownloadResponseType] = testEndSoftwareDownloadResponseTypeMeFrame |
| 61 | messageTypeTestFuncs[ActivateSoftwareRequestType] = testActivateSoftwareRequestTypeMeFrame |
| 62 | messageTypeTestFuncs[ActivateSoftwareResponseType] = testActivateSoftwareResponseTypeMeFrame |
| 63 | messageTypeTestFuncs[CommitSoftwareRequestType] = testCommitSoftwareRequestTypeMeFrame |
| 64 | messageTypeTestFuncs[CommitSoftwareResponseType] = testCommitSoftwareResponseTypeMeFrame |
| 65 | messageTypeTestFuncs[SynchronizeTimeRequestType] = testSynchronizeTimeRequestTypeMeFrame |
| 66 | messageTypeTestFuncs[SynchronizeTimeResponseType] = testSynchronizeTimeResponseTypeMeFrame |
| 67 | messageTypeTestFuncs[RebootRequestType] = testRebootRequestTypeMeFrame |
| 68 | messageTypeTestFuncs[RebootResponseType] = testRebootResponseTypeMeFrame |
| 69 | messageTypeTestFuncs[GetNextRequestType] = testGetNextRequestTypeMeFrame |
| 70 | messageTypeTestFuncs[GetNextResponseType] = testGetNextResponseTypeMeFrame |
| 71 | messageTypeTestFuncs[GetCurrentDataRequestType] = testGetCurrentDataRequestTypeMeFrame |
| 72 | messageTypeTestFuncs[GetCurrentDataResponseType] = testGetCurrentDataResponseTypeMeFrame |
| 73 | messageTypeTestFuncs[SetTableRequestType] = testSetTableRequestTypeMeFrame |
| 74 | messageTypeTestFuncs[SetTableResponseType] = testSetTableResponseTypeMeFrame |
| 75 | messageTypeTestFuncs[AlarmNotificationType] = testAlarmNotificationTypeMeFrame |
| 76 | messageTypeTestFuncs[AttributeValueChangeType] = testAttributeValueChangeTypeMeFrame |
| 77 | messageTypeTestFuncs[TestResultType] = testTestResultTypeMeFrame |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 78 | |
| 79 | // Supported Extended message set types here |
| 80 | messageTypeTestFuncs[GetRequestType+ExtendedTypeDecodeOffset] = testGetRequestTypeMeFrame |
| 81 | messageTypeTestFuncs[GetResponseType+ExtendedTypeDecodeOffset] = testGetResponseTypeMeFrame |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | func getMEsThatSupportAMessageType(messageType MessageType) []*me.ManagedEntity { |
| 85 | msgType := me.MsgType(byte(messageType) & me.MsgTypeMask) |
| 86 | |
| 87 | entities := make([]*me.ManagedEntity, 0) |
| 88 | for _, classID := range me.GetSupportedClassIDs() { |
| 89 | if managedEntity, err := me.LoadManagedEntityDefinition(classID); err.StatusCode() == me.Success { |
| 90 | supportedTypes := managedEntity.GetManagedEntityDefinition().GetMessageTypes() |
| 91 | if supportedTypes.Contains(msgType) { |
| 92 | entities = append(entities, managedEntity) |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return entities |
| 97 | } |
| 98 | |
| 99 | func TestFrameFormatNotYetSupported(t *testing.T) { |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 100 | // We do not yet support a few message types for the extended frame formats. |
| 101 | // As we do, add appropriate tests and change this to one that is not supported |
| 102 | // Until all are supported |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 103 | |
| 104 | params := me.ParamData{ |
| 105 | Attributes: me.AttributeValueMap{"MibDataSync": 0}, |
| 106 | } |
| 107 | managedEntity, omciErr := me.NewOnuData(params) |
| 108 | assert.NotNil(t, omciErr) |
| 109 | assert.Equal(t, omciErr.StatusCode(), me.Success) |
| 110 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 111 | buffer, err := GenFrame(managedEntity, SetRequestType, FrameFormat(ExtendedIdent), TransactionID(1)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 112 | assert.Nil(t, buffer) |
| 113 | assert.NotNil(t, err) |
| 114 | } |
| 115 | |
| 116 | // TODO: Add more specific get next response tests as we have had issues |
| 117 | |
| 118 | func TestGetNextResponseOneFrameOnly(t *testing.T) { |
| 119 | // OMCI ME GetRequest for MsgTypes often needs only a single frame and |
| 120 | // it is a table of one octet values. Make sure we decode it correctly |
| 121 | |
| 122 | response1 := []uint8{ |
| 123 | 0, 250, 58, 10, 1, 31, 0, 0, 0, 64, 0, |
| 124 | 4, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 0, |
| 125 | 0, 0, 0, 0, 0, 0, 0, 40, |
| 126 | } |
| 127 | // getNextSize is the size returned by the original Get request. Normally you would |
| 128 | // do many OMCI requests and append all the results (while decreasing size), but |
| 129 | // this is all in on packet. |
| 130 | // |
| 131 | // Do the buffer loop anyway |
| 132 | getNextSize := 23 |
| 133 | remaining := getNextSize |
| 134 | |
| 135 | dataBuffer := make([]byte, 0) |
| 136 | packets := []gopacket.Packet{ |
| 137 | gopacket.NewPacket(response1, LayerTypeOMCI, gopacket.NoCopy), |
| 138 | } |
| 139 | for _, packet := range packets { |
| 140 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 141 | assert.NotNil(t, omciLayer) |
| 142 | |
| 143 | omciObj, omciOk := omciLayer.(*OMCI) |
| 144 | assert.True(t, omciOk) |
| 145 | assert.NotNil(t, omciObj) |
| 146 | assert.Equal(t, uint16(250), omciObj.TransactionID) |
| 147 | assert.Equal(t, GetNextResponseType, omciObj.MessageType) |
| 148 | assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier) |
| 149 | assert.Equal(t, uint32(0), omciObj.MIC) |
| 150 | assert.Equal(t, uint16(40), omciObj.Length) |
| 151 | |
| 152 | msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 153 | msgObj, msgOk := msgLayer.(*GetNextResponse) |
| 154 | assert.True(t, msgOk) |
| 155 | assert.NotNil(t, msgObj) |
| 156 | assert.Equal(t, me.Success, msgObj.Result) |
| 157 | assert.Equal(t, uint16(0x4000), msgObj.AttributeMask) |
| 158 | assert.Equal(t, 2, len(msgObj.Attributes)) |
| 159 | |
| 160 | for attrName, value := range msgObj.Attributes { |
| 161 | // Skip Entity ID attribute always stored in attribute list |
| 162 | if attrName == "ManagedEntityId" { |
| 163 | assert.Equal(t, uint16(0), value.(uint16)) |
| 164 | continue |
| 165 | } |
| 166 | assert.Equal(t, "MessageTypeTable", attrName) |
| 167 | tmpBuffer, ok := value.([]byte) |
| 168 | assert.True(t, ok) |
| 169 | |
| 170 | validOctets := len(tmpBuffer) |
| 171 | assert.NotZero(t, validOctets) |
| 172 | if validOctets > remaining { |
| 173 | validOctets = remaining |
| 174 | } |
| 175 | remaining -= validOctets |
| 176 | dataBuffer = append(dataBuffer, tmpBuffer[:validOctets]...) |
| 177 | |
| 178 | assert.True(t, remaining >= 0) |
| 179 | if remaining == 0 { |
| 180 | break |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | bufSize := len(dataBuffer) |
| 185 | assert.Equal(t, getNextSize, bufSize) |
| 186 | } |
| 187 | |
| 188 | func aTestFailingGetNextResponseTypeMeFrame(t *testing.T) { |
| 189 | //params := me.ParamData{ |
| 190 | // EntityID: 0, |
| 191 | // Attributes: me.AttributeValueMap{ |
| 192 | // "Rmep5DatabaseTable": []uint8{ |
| 193 | // 0,1,2,3,4,5,6,7,8,9, |
| 194 | // 10,11,12,13,14,15,16,17,18,19, |
| 195 | // 20,21,22,23,24,25,26,27,28,29, |
| 196 | // 30, |
| 197 | // }, |
| 198 | // }, |
| 199 | //} |
| 200 | //meInstance, err := me.NewDot1AgMepCcmDatabase(params) |
| 201 | //bitmask := uint16(2048) |
| 202 | //assert.NotNil(t, meInstance) |
| 203 | //assert.Nil(t, err) |
| 204 | // |
| 205 | //tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 206 | // |
| 207 | //frame, omciErr := GenFrame(meInstance, GetNextResponseType, TransactionID(tid), Result(me.Success), |
| 208 | // AttributeMask(bitmask)) |
| 209 | //assert.NotNil(t, frame) |
| 210 | //assert.NotZero(t, len(frame)) |
| 211 | //assert.Nil(t, omciErr) |
| 212 | // |
| 213 | ///////////////////////////////////////////////////////////////////// |
| 214 | //// Now decode and compare |
| 215 | //cid := meInstance.GetClassID() |
| 216 | //assert.NotEqual(t, cid, 0) |
| 217 | //packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 218 | //assert.NotNil(t, packet) |
| 219 | // |
| 220 | //omciLayer := packet.Layer(LayerTypeOMCI) |
| 221 | //assert.NotNil(t, omciLayer) |
| 222 | // |
| 223 | //omciObj, omciOk := omciLayer.(*OMCI) |
| 224 | //assert.NotNil(t, omciObj) |
| 225 | //assert.True(t, omciOk) |
| 226 | //assert.Equal(t, tid, omciObj.TransactionID) |
| 227 | //assert.Equal(t, GetNextResponseType, omciObj.MessageType) |
| 228 | //assert.Equal(t, BaselineIdent, omciObj.DeviceIdentifier) |
| 229 | // |
| 230 | //msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 231 | //assert.NotNil(t, msgLayer) |
| 232 | // |
| 233 | //msgObj, msgOk := msgLayer.(*GetNextResponse) |
| 234 | //assert.NotNil(t, msgObj) |
| 235 | //assert.True(t, msgOk) |
| 236 | // |
| 237 | //assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 238 | //assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 239 | //assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask) |
| 240 | |
| 241 | } |
| 242 | |
| 243 | func TestAllMessageTypes(t *testing.T) { |
| 244 | // Loop over all message types |
| 245 | for _, messageType := range allMessageTypes { |
| 246 | //typeTested := false |
| 247 | if testRoutine, ok := messageTypeTestFuncs[messageType]; ok { |
| 248 | // Loop over all Managed Entities that support that type |
| 249 | for _, managedEntity := range getMEsThatSupportAMessageType(messageType) { |
| 250 | // Call the test routine |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 251 | testRoutine(t, managedEntity, BaselineIdent) |
| 252 | //typeTested = true |
| 253 | } |
| 254 | } |
| 255 | // Verify at least one test ran for this message type |
| 256 | // TODO: Enable once all tests are working -> assert.True(t, typeTested) |
| 257 | } |
| 258 | // Now for the extended message set message types we support |
| 259 | for _, messageType := range allExtendedMessageTypes { |
| 260 | trueMessageType := messageType - ExtendedTypeDecodeOffset |
| 261 | |
| 262 | if testRoutine, ok := messageTypeTestFuncs[messageType]; ok { |
| 263 | // Loop over all Managed Entities that support that type |
| 264 | for _, managedEntity := range getMEsThatSupportAMessageType(trueMessageType) { |
| 265 | // Call the test routine |
| 266 | testRoutine(t, managedEntity, ExtendedIdent) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 267 | //typeTested = true |
| 268 | } |
| 269 | } |
| 270 | // Verify at least one test ran for this message type |
| 271 | // TODO: Enable once all tests are working -> assert.True(t, typeTested) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | //func TestAllThatSupportAlarms(t *testing.T) { TODO: Future |
| 276 | // // Loop over all Managed Entities and test those with Attributes that support |
| 277 | // |
| 278 | // for _, managedEntity := range getMEsThatSupportAMessageType(messageType) { |
| 279 | // // Call the test routine |
| 280 | // testRoutine(t, managedEntity) |
| 281 | // //typeTested = true |
| 282 | // } |
| 283 | //} |
| 284 | |
| 285 | func getAttributeNameSet(attributes me.AttributeValueMap) mapset.Set { |
| 286 | // TODO: For Classes with attribute masks that can set/get/... more than just |
| 287 | // a single attribute, test a set/get of just a single attribute to verify |
| 288 | // all encoding/decoding methods are working as expected. |
| 289 | names := mapset.NewSet() |
| 290 | for name, _ := range attributes { |
| 291 | names.Add(name) |
| 292 | } |
| 293 | return names |
| 294 | } |
| 295 | |
| 296 | func pickAValue(attrDef me.AttributeDefinition) interface{} { |
| 297 | constraint := attrDef.Constraint |
| 298 | defaultVal := attrDef.DefValue |
| 299 | size := attrDef.GetSize() |
| 300 | _, isOctetString := defaultVal.([]byte) |
| 301 | |
| 302 | if attrDef.IsTableAttribute() || isOctetString { |
| 303 | // Table attributes treated as a string of octets. If size is zero, it is |
| 304 | // most likely an attribute with variable size. Pick a random size that will |
| 305 | // fit into a simple frame (1-33 octets) |
| 306 | if size == 0 { |
| 307 | size = rand.Intn(32) + 1 |
| 308 | } |
| 309 | value := make([]byte, size) |
| 310 | for octet := 0; octet < size; octet++ { |
| 311 | value[octet] = byte(octet & 0xff) |
| 312 | } |
| 313 | return value |
| 314 | } |
| 315 | switch size { |
| 316 | case 1: |
| 317 | // Try the default + 1 as a value. Since some defaults are zero |
| 318 | // and we want example frames without zeros in them. |
| 319 | if value, ok := defaultVal.(uint8); ok { |
| 320 | if constraint == nil { |
| 321 | return value + 1 |
| 322 | } |
| 323 | if err := constraint(value + 1); err == nil { |
| 324 | return value + 1 |
| 325 | } |
| 326 | } |
| 327 | return defaultVal.(uint8) |
| 328 | |
| 329 | case 2: |
| 330 | // Try the default + 1 as a value. Since some defaults are zero |
| 331 | // and we want example frames without zeros in them. |
| 332 | if value, ok := defaultVal.(uint16); ok { |
| 333 | if constraint == nil { |
| 334 | return value + 1 |
| 335 | } |
| 336 | if err := constraint(value + 1); err == nil { |
| 337 | return value + 1 |
| 338 | } |
| 339 | } |
| 340 | return defaultVal.(uint16) |
| 341 | |
| 342 | case 4: |
| 343 | // Try the default + 1 as a value. Since some defaults are zero |
| 344 | // and we want example frames without zeros in them. |
| 345 | if value, ok := defaultVal.(uint32); ok { |
| 346 | if constraint == nil { |
| 347 | return value + 1 |
| 348 | } |
| 349 | if err := constraint(value + 1); err == nil { |
| 350 | return value + 1 |
| 351 | } |
| 352 | } |
| 353 | return defaultVal.(uint32) |
| 354 | |
| 355 | case 8: |
| 356 | // Try the default + 1 as a value. Since some defaults are zero |
| 357 | // and we want example frames without zeros in them. |
| 358 | if value, ok := defaultVal.(uint64); ok { |
| 359 | if constraint == nil { |
| 360 | return value + 1 |
| 361 | } |
| 362 | if err := constraint(value + 1); err == nil { |
| 363 | return value + 1 |
| 364 | } |
| 365 | } |
| 366 | return defaultVal.(uint64) |
| 367 | |
| 368 | default: |
| 369 | size := attrDef.GetSize() |
| 370 | value := make([]uint8, size) |
| 371 | for index := 0; index < size; index++ { |
| 372 | value[index] = uint8(index & 0xFF) |
| 373 | } |
| 374 | return value |
| 375 | } |
| 376 | } |
| 377 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 378 | func testCreateRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 379 | // Generate the frame. Use a default Entity ID of zero, but for the |
| 380 | // OMCI library, we need to specify all supported Set-By-Create |
| 381 | params := me.ParamData{ |
| 382 | EntityID: uint16(0), |
| 383 | Attributes: make(me.AttributeValueMap, 0), |
| 384 | } |
| 385 | for _, attrDef := range managedEntity.GetAttributeDefinitions() { |
| 386 | if attrDef.Index == 0 { |
| 387 | continue // Skip entity ID, already specified |
| 388 | |
| 389 | } else if attrDef.GetAccess().Contains(me.SetByCreate) { |
| 390 | params.Attributes[attrDef.GetName()] = pickAValue(attrDef) |
| 391 | } |
| 392 | } |
| 393 | // Create the managed instance |
| 394 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 395 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 396 | assert.NotNil(t, err) |
| 397 | assert.Equal(t, err.StatusCode(), me.Success) |
| 398 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 399 | frame, omciErr := GenFrame(meInstance, CreateRequestType, TransactionID(tid), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 400 | assert.NotNil(t, frame) |
| 401 | assert.NotZero(t, len(frame)) |
| 402 | assert.Nil(t, omciErr) |
| 403 | |
| 404 | /////////////////////////////////////////////////////////////////// |
| 405 | // Now decode and compare |
| 406 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 407 | assert.NotNil(t, packet) |
| 408 | |
| 409 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 410 | assert.NotNil(t, omciLayer) |
| 411 | |
| 412 | omciObj, omciOk := omciLayer.(*OMCI) |
| 413 | assert.NotNil(t, omciObj) |
| 414 | assert.True(t, omciOk) |
| 415 | assert.Equal(t, tid, omciObj.TransactionID) |
| 416 | assert.Equal(t, CreateRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 417 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 418 | |
| 419 | msgLayer := packet.Layer(LayerTypeCreateRequest) |
| 420 | assert.NotNil(t, msgLayer) |
| 421 | |
| 422 | msgObj, msgOk := msgLayer.(*CreateRequest) |
| 423 | assert.NotNil(t, msgObj) |
| 424 | assert.True(t, msgOk) |
| 425 | |
| 426 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 427 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 428 | assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes) |
| 429 | } |
| 430 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 431 | func testCreateResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 432 | params := me.ParamData{ |
| 433 | EntityID: uint16(0), |
| 434 | } |
| 435 | // Create the managed instance |
| 436 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 437 | assert.NotNil(t, err) |
| 438 | assert.Equal(t, err.StatusCode(), me.Success) |
| 439 | |
| 440 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 441 | result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested |
| 442 | |
| 443 | // Always pass a failure mask, but should only get encoded if result == ParameterError |
| 444 | var mask uint16 |
| 445 | for _, attrDef := range managedEntity.GetAttributeDefinitions() { |
| 446 | if attrDef.Index == 0 { |
| 447 | continue // Skip entity ID, already specified |
| 448 | |
| 449 | } else if attrDef.GetAccess().Contains(me.SetByCreate) { |
| 450 | // Random 20% chance this parameter was bad |
| 451 | if rand.Int31n(5) == 0 { |
| 452 | mask |= attrDef.Mask |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | frame, omciErr := GenFrame(meInstance, CreateResponseType, |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 457 | TransactionID(tid), Result(result), AttributeExecutionMask(mask), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 458 | assert.NotNil(t, frame) |
| 459 | assert.NotZero(t, len(frame)) |
| 460 | assert.Nil(t, omciErr) |
| 461 | |
| 462 | /////////////////////////////////////////////////////////////////// |
| 463 | // Now decode and compare |
| 464 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 465 | assert.NotNil(t, packet) |
| 466 | |
| 467 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 468 | assert.NotNil(t, omciLayer) |
| 469 | |
| 470 | omciObj, omciOk := omciLayer.(*OMCI) |
| 471 | assert.NotNil(t, omciObj) |
| 472 | assert.True(t, omciOk) |
| 473 | assert.Equal(t, tid, omciObj.TransactionID) |
| 474 | assert.Equal(t, CreateResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 475 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 476 | |
| 477 | msgLayer := packet.Layer(LayerTypeCreateResponse) |
| 478 | assert.NotNil(t, msgLayer) |
| 479 | |
| 480 | msgObj, msgOk := msgLayer.(*CreateResponse) |
| 481 | assert.NotNil(t, msgObj) |
| 482 | assert.True(t, msgOk) |
| 483 | |
| 484 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 485 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 486 | assert.Equal(t, result, msgObj.Result) |
| 487 | |
| 488 | if result == me.ParameterError { |
| 489 | assert.Equal(t, mask, msgObj.AttributeExecutionMask) |
| 490 | } else { |
| 491 | assert.Zero(t, msgObj.AttributeExecutionMask) |
| 492 | } |
| 493 | } |
| 494 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 495 | func testDeleteRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 496 | // Generate the frame. Use a default Entity ID of zero, but for the |
| 497 | // OMCI library, we need to specify all supported Set-By-Create |
| 498 | params := me.ParamData{ |
| 499 | EntityID: uint16(0), |
| 500 | } |
| 501 | // Create the managed instance |
| 502 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 503 | assert.NotNil(t, err) |
| 504 | assert.Equal(t, err.StatusCode(), me.Success) |
| 505 | |
| 506 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 507 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 508 | frame, omciErr := GenFrame(meInstance, DeleteRequestType, TransactionID(tid), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 509 | assert.NotNil(t, frame) |
| 510 | assert.NotZero(t, len(frame)) |
| 511 | assert.Nil(t, omciErr) |
| 512 | |
| 513 | /////////////////////////////////////////////////////////////////// |
| 514 | // Now decode and compare |
| 515 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 516 | assert.NotNil(t, packet) |
| 517 | |
| 518 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 519 | assert.NotNil(t, omciLayer) |
| 520 | |
| 521 | omciObj, omciOk := omciLayer.(*OMCI) |
| 522 | assert.NotNil(t, omciObj) |
| 523 | assert.True(t, omciOk) |
| 524 | assert.Equal(t, tid, omciObj.TransactionID) |
| 525 | assert.Equal(t, DeleteRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 526 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 527 | |
| 528 | msgLayer := packet.Layer(LayerTypeDeleteRequest) |
| 529 | assert.NotNil(t, msgLayer) |
| 530 | |
| 531 | msgObj, msgOk := msgLayer.(*DeleteRequest) |
| 532 | assert.NotNil(t, msgObj) |
| 533 | assert.True(t, msgOk) |
| 534 | |
| 535 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 536 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 537 | } |
| 538 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 539 | func testDeleteResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 540 | params := me.ParamData{ |
| 541 | EntityID: uint16(0), |
| 542 | } |
| 543 | // Create the managed instance |
| 544 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 545 | assert.NotNil(t, err) |
| 546 | assert.Equal(t, err.StatusCode(), me.Success) |
| 547 | |
| 548 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 549 | result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested |
| 550 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 551 | frame, omciErr := GenFrame(meInstance, DeleteResponseType, TransactionID(tid), Result(result), |
| 552 | FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 553 | assert.NotNil(t, frame) |
| 554 | assert.NotZero(t, len(frame)) |
| 555 | assert.Nil(t, omciErr) |
| 556 | |
| 557 | /////////////////////////////////////////////////////////////////// |
| 558 | // Now decode and compare |
| 559 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 560 | assert.NotNil(t, packet) |
| 561 | |
| 562 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 563 | assert.NotNil(t, omciLayer) |
| 564 | |
| 565 | omciObj, omciOk := omciLayer.(*OMCI) |
| 566 | assert.NotNil(t, omciObj) |
| 567 | assert.True(t, omciOk) |
| 568 | assert.Equal(t, tid, omciObj.TransactionID) |
| 569 | assert.Equal(t, DeleteResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 570 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 571 | |
| 572 | msgLayer := packet.Layer(LayerTypeDeleteResponse) |
| 573 | assert.NotNil(t, msgLayer) |
| 574 | |
| 575 | msgObj, msgOk := msgLayer.(*DeleteResponse) |
| 576 | assert.NotNil(t, msgObj) |
| 577 | assert.True(t, msgOk) |
| 578 | |
| 579 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 580 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 581 | assert.Equal(t, result, msgObj.Result) |
| 582 | } |
| 583 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 584 | func testSetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 585 | params := me.ParamData{ |
| 586 | EntityID: uint16(0), |
| 587 | Attributes: make(me.AttributeValueMap, 0), |
| 588 | } |
| 589 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 590 | tableAttrFound := false |
| 591 | for _, attrDef := range attrDefs { |
| 592 | if attrDef.Index == 0 { |
| 593 | continue // Skip entity ID, already specified |
| 594 | } else if attrDef.IsTableAttribute() { |
| 595 | tableAttrFound = true |
| 596 | continue // TODO: Skip table attributes for now |
| 597 | } else if attrDef.GetAccess().Contains(me.Write) { |
| 598 | params.Attributes[attrDef.GetName()] = pickAValue(attrDef) |
| 599 | } |
| 600 | } |
| 601 | if tableAttrFound && len(params.Attributes) == 0 { |
| 602 | // The only set attribute may have been a table and we do not have |
| 603 | // a test for that right now. |
| 604 | return |
| 605 | } |
| 606 | assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute |
| 607 | bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 608 | assert.Nil(t, attrErr) |
| 609 | |
| 610 | // Create the managed instance |
| 611 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 612 | assert.NotNil(t, err) |
| 613 | assert.Equal(t, err.StatusCode(), me.Success) |
| 614 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 615 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 616 | frame, omciErr := GenFrame(meInstance, SetRequestType, TransactionID(tid), |
| 617 | AttributeMask(bitmask), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 618 | // some frames cannot fit all the attributes |
| 619 | if omciErr != nil { |
| 620 | if _, ok := omciErr.(*me.MessageTruncatedError); ok { |
| 621 | return |
| 622 | } |
| 623 | } |
| 624 | assert.NotNil(t, frame) |
| 625 | assert.NotZero(t, len(frame)) |
| 626 | |
| 627 | /////////////////////////////////////////////////////////////////// |
| 628 | // Now decode and compare |
| 629 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 630 | assert.NotNil(t, packet) |
| 631 | |
| 632 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 633 | assert.NotNil(t, omciLayer) |
| 634 | |
| 635 | omciObj, omciOk := omciLayer.(*OMCI) |
| 636 | assert.NotNil(t, omciObj) |
| 637 | assert.True(t, omciOk) |
| 638 | assert.Equal(t, tid, omciObj.TransactionID) |
| 639 | assert.Equal(t, SetRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 640 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 641 | |
| 642 | msgLayer := packet.Layer(LayerTypeSetRequest) |
| 643 | assert.NotNil(t, msgLayer) |
| 644 | |
| 645 | msgObj, msgOk := msgLayer.(*SetRequest) |
| 646 | assert.NotNil(t, msgObj) |
| 647 | assert.True(t, msgOk) |
| 648 | |
| 649 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 650 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 651 | assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes) |
| 652 | } |
| 653 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 654 | func testSetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 655 | params := me.ParamData{ |
| 656 | EntityID: uint16(0), |
| 657 | } |
| 658 | // Create the managed instance |
| 659 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 660 | assert.NotNil(t, err) |
| 661 | assert.Equal(t, err.StatusCode(), me.Success) |
| 662 | |
| 663 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 664 | result := me.Results(rand.Int31n(10)) // [0, 9] Not all types will be tested |
| 665 | |
| 666 | // Always pass a failure mask, but should only get encoded if result == ParameterError |
| 667 | var unsupportedMask uint16 |
| 668 | var failedMask uint16 |
| 669 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 670 | for _, attrDef := range attrDefs { |
| 671 | if attrDef.Index == 0 { |
| 672 | continue // Skip entity ID, already specified |
| 673 | |
| 674 | } else if attrDef.GetAccess().Contains(me.Write) { |
| 675 | // Random 10% chance this parameter unsupported and |
| 676 | // 10% it failed |
| 677 | switch rand.Int31n(5) { |
| 678 | case 0: |
| 679 | unsupportedMask |= attrDef.Mask |
| 680 | case 1: |
| 681 | failedMask |= attrDef.Mask |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 686 | assert.Nil(t, attrErr) |
| 687 | |
| 688 | frame, omciErr := GenFrame(meInstance, SetResponseType, |
| 689 | TransactionID(tid), Result(result), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 690 | AttributeMask(bitmask), FrameFormat(messageSet), |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 691 | AttributeExecutionMask(failedMask), |
| 692 | UnsupportedAttributeMask(unsupportedMask)) |
| 693 | assert.NotNil(t, frame) |
| 694 | assert.NotZero(t, len(frame)) |
| 695 | assert.Nil(t, omciErr) |
| 696 | |
| 697 | /////////////////////////////////////////////////////////////////// |
| 698 | // Now decode and compare |
| 699 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 700 | assert.NotNil(t, packet) |
| 701 | |
| 702 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 703 | assert.NotNil(t, omciLayer) |
| 704 | |
| 705 | omciObj, omciOk := omciLayer.(*OMCI) |
| 706 | assert.NotNil(t, omciObj) |
| 707 | assert.True(t, omciOk) |
| 708 | assert.Equal(t, tid, omciObj.TransactionID) |
| 709 | assert.Equal(t, SetResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 710 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 711 | |
| 712 | msgLayer := packet.Layer(LayerTypeSetResponse) |
| 713 | assert.NotNil(t, msgLayer) |
| 714 | |
| 715 | msgObj, msgOk := msgLayer.(*SetResponse) |
| 716 | assert.NotNil(t, msgObj) |
| 717 | assert.True(t, msgOk) |
| 718 | |
| 719 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 720 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 721 | assert.Equal(t, result, msgObj.Result) |
| 722 | |
| 723 | if result == me.AttributeFailure { |
| 724 | assert.Equal(t, failedMask, msgObj.FailedAttributeMask) |
| 725 | assert.Equal(t, unsupportedMask, msgObj.UnsupportedAttributeMask) |
| 726 | } else { |
| 727 | assert.Zero(t, msgObj.FailedAttributeMask) |
| 728 | assert.Zero(t, msgObj.UnsupportedAttributeMask) |
| 729 | } |
| 730 | } |
| 731 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 732 | func testGetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 733 | params := me.ParamData{ |
| 734 | EntityID: uint16(0), |
| 735 | Attributes: make(me.AttributeValueMap, 0), |
| 736 | } |
| 737 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 738 | for _, attrDef := range attrDefs { |
| 739 | if attrDef.Index == 0 { |
| 740 | continue // Skip entity ID, already specified |
| 741 | } else if attrDef.GetAccess().Contains(me.Read) { |
| 742 | // Allow 'nil' as parameter value for GetRequests since we only need names |
| 743 | params.Attributes[attrDef.GetName()] = nil |
| 744 | } |
| 745 | } |
| 746 | assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute |
| 747 | bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 748 | assert.Nil(t, attrErr) |
| 749 | |
| 750 | // Create the managed instance |
| 751 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 752 | assert.NotNil(t, err) |
| 753 | assert.Equal(t, err.StatusCode(), me.Success) |
| 754 | |
| 755 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 756 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 757 | frame, omciErr := GenFrame(meInstance, GetRequestType, TransactionID(tid), |
| 758 | AttributeMask(bitmask), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 759 | assert.NotNil(t, frame) |
| 760 | assert.NotZero(t, len(frame)) |
| 761 | assert.Nil(t, omciErr) |
| 762 | |
| 763 | /////////////////////////////////////////////////////////////////// |
| 764 | // Now decode and compare |
| 765 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 766 | assert.NotNil(t, packet) |
| 767 | |
| 768 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 769 | assert.NotNil(t, omciLayer) |
| 770 | |
| 771 | omciObj, omciOk := omciLayer.(*OMCI) |
| 772 | assert.NotNil(t, omciObj) |
| 773 | assert.True(t, omciOk) |
| 774 | assert.Equal(t, tid, omciObj.TransactionID) |
| 775 | assert.Equal(t, GetRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 776 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 777 | |
| 778 | msgLayer := packet.Layer(LayerTypeGetRequest) |
| 779 | assert.NotNil(t, msgLayer) |
| 780 | |
| 781 | msgObj, msgOk := msgLayer.(*GetRequest) |
| 782 | assert.NotNil(t, msgObj) |
| 783 | assert.True(t, msgOk) |
| 784 | |
| 785 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 786 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 787 | assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask) |
| 788 | } |
| 789 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 790 | func testGetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 791 | params := me.ParamData{ |
| 792 | EntityID: uint16(0), |
| 793 | Attributes: make(me.AttributeValueMap), |
| 794 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 795 | // Add loop to test all valid result codes for this message type |
| 796 | validResultCodes := []me.Results{ |
| 797 | me.Success, |
| 798 | me.ProcessingError, |
| 799 | me.NotSupported, |
| 800 | me.ParameterError, |
| 801 | me.UnknownEntity, |
| 802 | me.UnknownInstance, |
| 803 | me.DeviceBusy, |
| 804 | me.AttributeFailure, |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 805 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 806 | for _, result := range validResultCodes { |
| 807 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 808 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 809 | // If success Results selected, set FailIfTruncated 50% of time to test |
| 810 | // overflow detection and failures periodically. This is primarily for |
| 811 | // baseline message set for those MEs that may have lots of attribute space |
| 812 | // needed. If extended message set, always fail if truncated since we should |
| 813 | // be able to stuff as much as we want (at least for now in these unit tests) |
| 814 | failIfTruncated := false |
| 815 | if result == me.Success && (rand.Int31n(2) == 1 || messageSet == ExtendedIdent) { |
| 816 | failIfTruncated = true |
| 817 | } |
| 818 | // Always pass a failure mask, but should only get encoded if result == ParameterError |
| 819 | var unsupportedMask uint16 |
| 820 | var failedMask uint16 |
| 821 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 822 | for _, attrDef := range attrDefs { |
| 823 | if attrDef.Index == 0 { |
| 824 | continue // Skip entity ID, already specified |
| 825 | |
| 826 | } else if attrDef.GetAccess().Contains(me.Read) { |
| 827 | // Random 5% chance this parameter unsupported and |
| 828 | // 5% it failed |
| 829 | switch rand.Int31n(20) { |
| 830 | default: |
| 831 | // TODO: Table attributes not yet supported. For Table Attributes, figure out a |
| 832 | // good way to unit test this and see if that can be extended to a more |
| 833 | // general operation that provides the 'get-next' frames to the caller who |
| 834 | // wishes to serialize a table attribute. |
| 835 | if !attrDef.IsTableAttribute() { |
| 836 | params.Attributes[attrDef.GetName()] = pickAValue(attrDef) |
| 837 | } |
| 838 | case 0: |
| 839 | unsupportedMask |= attrDef.Mask |
| 840 | case 1: |
| 841 | failedMask |= attrDef.Mask |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 842 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 843 | } |
| 844 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 845 | bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 846 | assert.Nil(t, attrErr) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 847 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 848 | // Create the managed instance |
| 849 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 850 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 851 | frame, omciErr := GenFrame(meInstance, GetResponseType, |
| 852 | TransactionID(tid), Result(result), |
| 853 | AttributeMask(bitmask), FrameFormat(messageSet), |
| 854 | AttributeExecutionMask(failedMask), |
| 855 | UnsupportedAttributeMask(unsupportedMask), |
| 856 | FailIfTruncated(failIfTruncated)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 857 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 858 | // TODO: Need to test if err is MessageTruncatedError. Sometimes reported as |
| 859 | // a proessing error |
| 860 | if omciErr != nil { |
| 861 | if _, ok := omciErr.(*me.MessageTruncatedError); ok { |
| 862 | return |
| 863 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 864 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 865 | assert.NotNil(t, frame) |
| 866 | assert.NotZero(t, len(frame)) |
| 867 | assert.NotNil(t, err) |
| 868 | assert.Equal(t, err.StatusCode(), me.Success) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 869 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 870 | /////////////////////////////////////////////////////////////////// |
| 871 | // Now decode and compare |
| 872 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 873 | assert.NotNil(t, packet) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 874 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 875 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 876 | assert.NotNil(t, omciLayer) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 877 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 878 | omciObj, omciOk := omciLayer.(*OMCI) |
| 879 | assert.NotNil(t, omciObj) |
| 880 | assert.True(t, omciOk) |
| 881 | assert.Equal(t, tid, omciObj.TransactionID) |
| 882 | assert.Equal(t, GetResponseType, omciObj.MessageType) |
| 883 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 884 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 885 | msgLayer := packet.Layer(LayerTypeGetResponse) |
| 886 | // If requested Result was Success and FailIfTruncated is true, then we may |
| 887 | // fail (get nil layer) if too many attributes to fit in a frame |
| 888 | if result == me.Success && msgLayer == nil { |
| 889 | return // was expected |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 890 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 891 | assert.NotNil(t, msgLayer) |
| 892 | |
| 893 | msgObj, msgOk := msgLayer.(*GetResponse) |
| 894 | assert.NotNil(t, msgObj) |
| 895 | assert.True(t, msgOk) |
| 896 | |
| 897 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 898 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 899 | |
| 900 | switch msgObj.Result { |
| 901 | default: |
| 902 | assert.Equal(t, result, msgObj.Result) |
| 903 | assert.Zero(t, msgObj.FailedAttributeMask) |
| 904 | assert.Zero(t, msgObj.UnsupportedAttributeMask) |
| 905 | |
| 906 | case me.Success: |
| 907 | assert.Equal(t, result, msgObj.Result) |
| 908 | assert.Zero(t, msgObj.FailedAttributeMask) |
| 909 | assert.Zero(t, msgObj.UnsupportedAttributeMask) |
| 910 | assert.Equal(t, meInstance.GetAttributeValueMap(), msgObj.Attributes) |
| 911 | |
| 912 | case me.AttributeFailure: |
| 913 | // Should have been Success or AttributeFailure to start with |
| 914 | assert.True(t, result == me.Success || result == me.AttributeFailure) |
| 915 | if result == me.AttributeFailure { |
| 916 | assert.Equal(t, unsupportedMask, msgObj.UnsupportedAttributeMask) |
| 917 | } |
| 918 | // Returned may have more bits set in failed mask and less attributes |
| 919 | // since failIfTruncated is false and we may add more fail attributes |
| 920 | // since they do not fit. May also set only lower value (lower bits) |
| 921 | // if it turns out that the upper bits are already pre-assigned to the |
| 922 | // failure bits. |
| 923 | // |
| 924 | // Make sure any successful attributes were requested |
| 925 | meMap := meInstance.GetAttributeValueMap() |
| 926 | for name := range msgObj.Attributes { |
| 927 | getValue, ok := meMap[name] |
| 928 | assert.True(t, ok) |
| 929 | assert.NotNil(t, getValue) |
| 930 | } |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | } |
| 934 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 935 | func testGetAllAlarmsRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 936 | params := me.ParamData{ |
| 937 | EntityID: uint16(0), |
| 938 | } |
| 939 | // Create the managed instance |
| 940 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 941 | assert.NotNil(t, err) |
| 942 | assert.Equal(t, err.StatusCode(), me.Success) |
| 943 | |
| 944 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 945 | mode := uint8(rand.Int31n(2)) // [0, 1] |
| 946 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 947 | frame, omciErr := GenFrame(meInstance, GetAllAlarmsRequestType, TransactionID(tid), |
| 948 | RetrievalMode(mode), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 949 | assert.NotNil(t, frame) |
| 950 | assert.NotZero(t, len(frame)) |
| 951 | assert.Nil(t, omciErr) |
| 952 | |
| 953 | /////////////////////////////////////////////////////////////////// |
| 954 | // Now decode and compare |
| 955 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 956 | assert.NotNil(t, packet) |
| 957 | |
| 958 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 959 | assert.NotNil(t, omciLayer) |
| 960 | |
| 961 | omciObj, omciOk := omciLayer.(*OMCI) |
| 962 | assert.NotNil(t, omciObj) |
| 963 | assert.True(t, omciOk) |
| 964 | assert.Equal(t, tid, omciObj.TransactionID) |
| 965 | assert.Equal(t, GetAllAlarmsRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 966 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 967 | |
| 968 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsRequest) |
| 969 | assert.NotNil(t, msgLayer) |
| 970 | |
| 971 | msgObj, msgOk := msgLayer.(*GetAllAlarmsRequest) |
| 972 | assert.NotNil(t, msgObj) |
| 973 | assert.True(t, msgOk) |
| 974 | |
| 975 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 976 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 977 | assert.Equal(t, mode, msgObj.AlarmRetrievalMode) |
| 978 | } |
| 979 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 980 | func testGetAllAlarmsResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 981 | params := me.ParamData{ |
| 982 | EntityID: uint16(0), |
| 983 | } |
| 984 | // Create the managed instance |
| 985 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 986 | assert.NotNil(t, err) |
| 987 | assert.Equal(t, err.StatusCode(), me.Success) |
| 988 | |
| 989 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 990 | numOfCommands := uint16(rand.Int31n(5)) // [0, 5) |
| 991 | |
| 992 | frame, omciErr := GenFrame(meInstance, GetAllAlarmsResponseType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 993 | SequenceNumberCountOrSize(numOfCommands), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 994 | assert.NotNil(t, frame) |
| 995 | assert.NotZero(t, len(frame)) |
| 996 | assert.Nil(t, omciErr) |
| 997 | |
| 998 | /////////////////////////////////////////////////////////////////// |
| 999 | // Now decode and compare |
| 1000 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1001 | assert.NotNil(t, packet) |
| 1002 | |
| 1003 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1004 | assert.NotNil(t, omciLayer) |
| 1005 | |
| 1006 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1007 | assert.NotNil(t, omciObj) |
| 1008 | assert.True(t, omciOk) |
| 1009 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1010 | assert.Equal(t, GetAllAlarmsResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1011 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1012 | |
| 1013 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsResponse) |
| 1014 | assert.NotNil(t, msgLayer) |
| 1015 | |
| 1016 | msgObj, msgOk := msgLayer.(*GetAllAlarmsResponse) |
| 1017 | assert.NotNil(t, msgObj) |
| 1018 | assert.True(t, msgOk) |
| 1019 | |
| 1020 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1021 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1022 | assert.Equal(t, numOfCommands, msgObj.NumberOfCommands) |
| 1023 | } |
| 1024 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1025 | func testGetAllAlarmsNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1026 | params := me.ParamData{ |
| 1027 | EntityID: uint16(0), |
| 1028 | } |
| 1029 | // Create the managed instance |
| 1030 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1031 | assert.NotNil(t, err) |
| 1032 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1033 | |
| 1034 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1035 | sequenceNumber := uint16(rand.Int31n(5)) // [0, 5) |
| 1036 | |
| 1037 | frame, omciErr := GenFrame(meInstance, GetAllAlarmsNextRequestType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1038 | SequenceNumberCountOrSize(sequenceNumber), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1039 | assert.NotNil(t, frame) |
| 1040 | assert.NotZero(t, len(frame)) |
| 1041 | assert.Nil(t, omciErr) |
| 1042 | |
| 1043 | /////////////////////////////////////////////////////////////////// |
| 1044 | // Now decode and compare |
| 1045 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1046 | assert.NotNil(t, packet) |
| 1047 | |
| 1048 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1049 | assert.NotNil(t, omciLayer) |
| 1050 | |
| 1051 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1052 | assert.NotNil(t, omciObj) |
| 1053 | assert.True(t, omciOk) |
| 1054 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1055 | assert.Equal(t, GetAllAlarmsNextRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1056 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1057 | |
| 1058 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextRequest) |
| 1059 | assert.NotNil(t, msgLayer) |
| 1060 | |
| 1061 | msgObj, msgOk := msgLayer.(*GetAllAlarmsNextRequest) |
| 1062 | assert.NotNil(t, msgObj) |
| 1063 | assert.True(t, msgOk) |
| 1064 | |
| 1065 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1066 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1067 | assert.Equal(t, sequenceNumber, msgObj.CommandSequenceNumber) |
| 1068 | } |
| 1069 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1070 | func testGetAllAlarmsNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1071 | params := me.ParamData{ |
| 1072 | EntityID: uint16(0), |
| 1073 | } |
| 1074 | // Create the managed instance |
| 1075 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1076 | assert.NotNil(t, err) |
| 1077 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1078 | |
| 1079 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1080 | |
| 1081 | alarmInfo := AlarmOptions{ |
| 1082 | AlarmClassID: 123, // TODO: Real class here? |
| 1083 | AlarmInstance: 456, |
| 1084 | AlarmBitmap: make([]byte, 28), |
| 1085 | } |
| 1086 | // TODO: Allow a 1 to 28 octet array to be used and zero fill any remainder... |
| 1087 | for octet := 0; octet < 28; octet++ { |
| 1088 | alarmInfo.AlarmBitmap[octet] = uint8(rand.Intn(256)) |
| 1089 | } |
| 1090 | frame, omciErr := GenFrame(meInstance, GetAllAlarmsNextResponseType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1091 | Alarm(alarmInfo), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1092 | assert.NotNil(t, frame) |
| 1093 | assert.NotZero(t, len(frame)) |
| 1094 | assert.Nil(t, omciErr) |
| 1095 | |
| 1096 | /////////////////////////////////////////////////////////////////// |
| 1097 | // Now decode and compare |
| 1098 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1099 | assert.NotNil(t, packet) |
| 1100 | |
| 1101 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1102 | assert.NotNil(t, omciLayer) |
| 1103 | |
| 1104 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1105 | assert.NotNil(t, omciObj) |
| 1106 | assert.True(t, omciOk) |
| 1107 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1108 | assert.Equal(t, GetAllAlarmsNextResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1109 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1110 | |
| 1111 | msgLayer := packet.Layer(LayerTypeGetAllAlarmsNextResponse) |
| 1112 | assert.NotNil(t, msgLayer) |
| 1113 | |
| 1114 | msgObj, msgOk := msgLayer.(*GetAllAlarmsNextResponse) |
| 1115 | assert.NotNil(t, msgObj) |
| 1116 | assert.True(t, msgOk) |
| 1117 | |
| 1118 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1119 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1120 | assert.Equal(t, alarmInfo.AlarmClassID, msgObj.AlarmEntityClass) |
| 1121 | assert.Equal(t, alarmInfo.AlarmInstance, msgObj.AlarmEntityInstance) |
| 1122 | for octet := 0; octet < len(alarmInfo.AlarmBitmap); octet++ { |
| 1123 | assert.Equal(t, alarmInfo.AlarmBitmap[octet], msgObj.AlarmBitMap[octet]) |
| 1124 | } |
| 1125 | } |
| 1126 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1127 | func testMibUploadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1128 | params := me.ParamData{ |
| 1129 | EntityID: uint16(0), |
| 1130 | } |
| 1131 | // Create the managed instance |
| 1132 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1133 | assert.NotNil(t, err) |
| 1134 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1135 | |
| 1136 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1137 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1138 | frame, omciErr := GenFrame(meInstance, MibUploadRequestType, TransactionID(tid), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1139 | assert.NotNil(t, frame) |
| 1140 | assert.NotZero(t, len(frame)) |
| 1141 | assert.Nil(t, omciErr) |
| 1142 | |
| 1143 | /////////////////////////////////////////////////////////////////// |
| 1144 | // Now decode and compare |
| 1145 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1146 | assert.NotNil(t, packet) |
| 1147 | |
| 1148 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1149 | assert.NotNil(t, omciLayer) |
| 1150 | |
| 1151 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1152 | assert.NotNil(t, omciObj) |
| 1153 | assert.True(t, omciOk) |
| 1154 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1155 | assert.Equal(t, MibUploadRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1156 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1157 | |
| 1158 | msgLayer := packet.Layer(LayerTypeMibUploadRequest) |
| 1159 | assert.NotNil(t, msgLayer) |
| 1160 | |
| 1161 | msgObj, msgOk := msgLayer.(*MibUploadRequest) |
| 1162 | assert.NotNil(t, msgObj) |
| 1163 | assert.True(t, msgOk) |
| 1164 | |
| 1165 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1166 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1167 | } |
| 1168 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1169 | func testMibUploadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1170 | params := me.ParamData{ |
| 1171 | EntityID: uint16(0), |
| 1172 | } |
| 1173 | // Create the managed instance |
| 1174 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1175 | assert.NotNil(t, err) |
| 1176 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1177 | |
| 1178 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1179 | numOfCommands := uint16(rand.Int31n(5)) // [0, 5) |
| 1180 | |
| 1181 | frame, omciErr := GenFrame(meInstance, MibUploadResponseType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1182 | SequenceNumberCountOrSize(numOfCommands), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1183 | assert.NotNil(t, frame) |
| 1184 | assert.NotZero(t, len(frame)) |
| 1185 | assert.Nil(t, omciErr) |
| 1186 | |
| 1187 | /////////////////////////////////////////////////////////////////// |
| 1188 | // Now decode and compare |
| 1189 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1190 | assert.NotNil(t, packet) |
| 1191 | |
| 1192 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1193 | assert.NotNil(t, omciLayer) |
| 1194 | |
| 1195 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1196 | assert.NotNil(t, omciObj) |
| 1197 | assert.True(t, omciOk) |
| 1198 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1199 | assert.Equal(t, MibUploadResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1200 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1201 | |
| 1202 | msgLayer := packet.Layer(LayerTypeMibUploadResponse) |
| 1203 | assert.NotNil(t, msgLayer) |
| 1204 | |
| 1205 | msgObj, msgOk := msgLayer.(*MibUploadResponse) |
| 1206 | assert.NotNil(t, msgObj) |
| 1207 | assert.True(t, msgOk) |
| 1208 | |
| 1209 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1210 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1211 | assert.Equal(t, numOfCommands, msgObj.NumberOfCommands) |
| 1212 | } |
| 1213 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1214 | func testMibUploadNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1215 | params := me.ParamData{ |
| 1216 | EntityID: uint16(0), |
| 1217 | } |
| 1218 | // Create the managed instance |
| 1219 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1220 | assert.NotNil(t, err) |
| 1221 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1222 | |
| 1223 | seqNumber := uint16(rand.Int31n(0xFFFF)) // [0, 0xFFFE] |
| 1224 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1225 | |
| 1226 | var frame []byte |
| 1227 | frame, omciErr := GenFrame(meInstance, MibUploadNextRequestType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1228 | SequenceNumberCountOrSize(seqNumber), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1229 | assert.NotNil(t, frame) |
| 1230 | assert.NotZero(t, len(frame)) |
| 1231 | assert.Nil(t, omciErr) |
| 1232 | |
| 1233 | /////////////////////////////////////////////////////////////////// |
| 1234 | // Now decode and compare |
| 1235 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1236 | assert.NotNil(t, packet) |
| 1237 | |
| 1238 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1239 | assert.NotNil(t, omciLayer) |
| 1240 | |
| 1241 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1242 | assert.NotNil(t, omciObj) |
| 1243 | assert.True(t, omciOk) |
| 1244 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1245 | assert.Equal(t, MibUploadNextRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1246 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1247 | |
| 1248 | msgLayer := packet.Layer(LayerTypeMibUploadNextRequest) |
| 1249 | assert.NotNil(t, msgLayer) |
| 1250 | |
| 1251 | msgObj, msgOk := msgLayer.(*MibUploadNextRequest) |
| 1252 | assert.NotNil(t, msgObj) |
| 1253 | assert.True(t, msgOk) |
| 1254 | |
| 1255 | assert.Equal(t, seqNumber, msgObj.CommandSequenceNumber) |
| 1256 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1257 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1258 | } |
| 1259 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1260 | func testMibUploadNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1261 | params := me.ParamData{ |
| 1262 | EntityID: uint16(0), |
| 1263 | } |
| 1264 | // Create the managed instance |
| 1265 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1266 | assert.NotNil(t, err) |
| 1267 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1268 | |
| 1269 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1270 | |
| 1271 | // TODO: Since only baseline messages supported, send only one ME |
| 1272 | uploadMe := meInstance |
| 1273 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1274 | frame, omciErr := GenFrame(meInstance, MibUploadNextResponseType, TransactionID(tid), |
| 1275 | Payload(uploadMe), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1276 | assert.NotNil(t, frame) |
| 1277 | assert.NotZero(t, len(frame)) |
| 1278 | assert.Nil(t, omciErr) |
| 1279 | |
| 1280 | /////////////////////////////////////////////////////////////////// |
| 1281 | // Now decode and compare |
| 1282 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1283 | assert.NotNil(t, packet) |
| 1284 | |
| 1285 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1286 | assert.NotNil(t, omciLayer) |
| 1287 | |
| 1288 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1289 | assert.NotNil(t, omciObj) |
| 1290 | assert.True(t, omciOk) |
| 1291 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1292 | assert.Equal(t, MibUploadNextResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1293 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1294 | |
| 1295 | msgLayer := packet.Layer(LayerTypeMibUploadNextResponse) |
| 1296 | assert.NotNil(t, msgLayer) |
| 1297 | |
| 1298 | msgObj, msgOk := msgLayer.(*MibUploadNextResponse) |
| 1299 | assert.NotNil(t, msgObj) |
| 1300 | assert.True(t, msgOk) |
| 1301 | |
| 1302 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1303 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1304 | assert.Equal(t, uploadMe.GetClassID(), msgObj.ReportedME.GetClassID()) |
| 1305 | assert.Equal(t, uploadMe.GetEntityID(), msgObj.ReportedME.GetEntityID()) |
| 1306 | } |
| 1307 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1308 | func testMibResetRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1309 | params := me.ParamData{ |
| 1310 | EntityID: uint16(0), |
| 1311 | } |
| 1312 | // Create the managed instance |
| 1313 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1314 | assert.NotNil(t, err) |
| 1315 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1316 | |
| 1317 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1318 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1319 | frame, omciErr := GenFrame(meInstance, MibResetRequestType, TransactionID(tid), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1320 | assert.NotNil(t, frame) |
| 1321 | assert.NotZero(t, len(frame)) |
| 1322 | assert.Nil(t, omciErr) |
| 1323 | |
| 1324 | /////////////////////////////////////////////////////////////////// |
| 1325 | // Now decode and compare |
| 1326 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1327 | assert.NotNil(t, packet) |
| 1328 | |
| 1329 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1330 | assert.NotNil(t, omciLayer) |
| 1331 | |
| 1332 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1333 | assert.NotNil(t, omciObj) |
| 1334 | assert.True(t, omciOk) |
| 1335 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1336 | assert.Equal(t, MibResetRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1337 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1338 | |
| 1339 | msgLayer := packet.Layer(LayerTypeMibResetRequest) |
| 1340 | assert.NotNil(t, msgLayer) |
| 1341 | |
| 1342 | msgObj, msgOk := msgLayer.(*MibResetRequest) |
| 1343 | assert.NotNil(t, msgObj) |
| 1344 | assert.True(t, msgOk) |
| 1345 | |
| 1346 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1347 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1348 | } |
| 1349 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1350 | func testMibResetResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1351 | params := me.ParamData{ |
| 1352 | EntityID: uint16(0), |
| 1353 | } |
| 1354 | // Create the managed instance |
| 1355 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1356 | assert.NotNil(t, err) |
| 1357 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1358 | |
| 1359 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1360 | result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested |
| 1361 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1362 | frame, omciErr := GenFrame(meInstance, MibResetResponseType, TransactionID(tid), |
| 1363 | Result(result), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1364 | assert.NotNil(t, frame) |
| 1365 | assert.NotZero(t, len(frame)) |
| 1366 | assert.Nil(t, omciErr) |
| 1367 | |
| 1368 | /////////////////////////////////////////////////////////////////// |
| 1369 | // Now decode and compare |
| 1370 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1371 | assert.NotNil(t, packet) |
| 1372 | |
| 1373 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1374 | assert.NotNil(t, omciLayer) |
| 1375 | |
| 1376 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1377 | assert.NotNil(t, omciObj) |
| 1378 | assert.True(t, omciOk) |
| 1379 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1380 | assert.Equal(t, MibResetResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1381 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1382 | |
| 1383 | msgLayer := packet.Layer(LayerTypeMibResetResponse) |
| 1384 | assert.NotNil(t, msgLayer) |
| 1385 | |
| 1386 | msgObj, msgOk := msgLayer.(*MibResetResponse) |
| 1387 | assert.NotNil(t, msgObj) |
| 1388 | assert.True(t, msgOk) |
| 1389 | |
| 1390 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1391 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1392 | assert.Equal(t, result, msgObj.Result) |
| 1393 | } |
| 1394 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1395 | func testTestRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1396 | // TODO: Implement |
| 1397 | } |
| 1398 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1399 | func testTestResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1400 | // TODO: Implement |
| 1401 | } |
| 1402 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1403 | func testStartSoftwareDownloadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1404 | instance := uint16(0) // ONU-G |
| 1405 | image := uint16(1) |
| 1406 | params := me.ParamData{ |
| 1407 | EntityID: uint16((instance << 8) + image), |
| 1408 | } |
| 1409 | // Create the managed instance |
| 1410 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1411 | assert.NotNil(t, err) |
| 1412 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1413 | |
| 1414 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1415 | options := SoftwareOptions{ |
| 1416 | WindowSize: uint8(rand.Int31n(255)), // [0, 255] |
| 1417 | ImageSize: uint32(rand.Int31n(0x100000) + 0x100000), // [1 Meg, 2M-1] |
| 1418 | CircuitPacks: []uint16{0}, // [1 Meg, 2M-1] |
| 1419 | } |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1420 | frame, omciErr := GenFrame(meInstance, StartSoftwareDownloadRequestType, |
| 1421 | TransactionID(tid), Software(options), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1422 | assert.NotNil(t, frame) |
| 1423 | assert.NotZero(t, len(frame)) |
| 1424 | assert.Nil(t, omciErr) |
| 1425 | |
| 1426 | /////////////////////////////////////////////////////////////////// |
| 1427 | // Now decode and compare |
| 1428 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1429 | assert.NotNil(t, packet) |
| 1430 | |
| 1431 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1432 | assert.NotNil(t, omciLayer) |
| 1433 | |
| 1434 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1435 | assert.NotNil(t, omciObj) |
| 1436 | assert.True(t, omciOk) |
| 1437 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1438 | assert.Equal(t, StartSoftwareDownloadRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1439 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1440 | |
| 1441 | msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest) |
| 1442 | assert.NotNil(t, msgLayer) |
| 1443 | |
| 1444 | msgObj, msgOk := msgLayer.(*StartSoftwareDownloadRequest) |
| 1445 | assert.NotNil(t, msgObj) |
| 1446 | assert.True(t, msgOk) |
| 1447 | |
| 1448 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1449 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1450 | assert.Equal(t, options.ImageSize, msgObj.ImageSize) |
| 1451 | assert.Equal(t, len(options.CircuitPacks), int(msgObj.NumberOfCircuitPacks)) |
| 1452 | |
| 1453 | for index, circuitPack := range options.CircuitPacks { |
| 1454 | assert.Equal(t, circuitPack, msgObj.CircuitPacks[index]) |
| 1455 | } |
| 1456 | } |
| 1457 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1458 | func testStartSoftwareDownloadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1459 | // TODO: Implement |
| 1460 | } |
| 1461 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1462 | func testDownloadSectionRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1463 | // TODO: Implement |
| 1464 | } |
| 1465 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1466 | func testDownloadSectionResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1467 | // TODO: Implement |
| 1468 | } |
| 1469 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1470 | func testEndSoftwareDownloadRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1471 | // TODO: Implement |
| 1472 | } |
| 1473 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1474 | func testEndSoftwareDownloadResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1475 | // TODO: Implement |
| 1476 | } |
| 1477 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1478 | func testActivateSoftwareRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1479 | // TODO: Implement |
| 1480 | } |
| 1481 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1482 | func testActivateSoftwareResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1483 | // TODO: Implement |
| 1484 | } |
| 1485 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1486 | func testCommitSoftwareRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1487 | // TODO: Implement |
| 1488 | } |
| 1489 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1490 | func testCommitSoftwareResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1491 | // TODO: Implement |
| 1492 | } |
| 1493 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1494 | func testSynchronizeTimeRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1495 | params := me.ParamData{ |
| 1496 | EntityID: uint16(0), |
| 1497 | } |
| 1498 | // Create the managed instance |
| 1499 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1500 | assert.NotNil(t, err) |
| 1501 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1502 | |
| 1503 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1504 | tm := time.Now().UTC() |
| 1505 | tmUnix := tm.Unix() |
| 1506 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1507 | frame, omciErr := GenFrame(meInstance, SynchronizeTimeRequestType, TransactionID(tid), |
| 1508 | Payload(tmUnix), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1509 | assert.NotNil(t, frame) |
| 1510 | assert.NotZero(t, len(frame)) |
| 1511 | assert.Nil(t, omciErr) |
| 1512 | |
| 1513 | /////////////////////////////////////////////////////////////////// |
| 1514 | // Now decode and compare |
| 1515 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1516 | assert.NotNil(t, packet) |
| 1517 | |
| 1518 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1519 | assert.NotNil(t, omciLayer) |
| 1520 | |
| 1521 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1522 | assert.NotNil(t, omciObj) |
| 1523 | assert.True(t, omciOk) |
| 1524 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1525 | assert.Equal(t, SynchronizeTimeRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1526 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1527 | |
| 1528 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeRequest) |
| 1529 | assert.NotNil(t, msgLayer) |
| 1530 | |
| 1531 | msgObj, msgOk := msgLayer.(*SynchronizeTimeRequest) |
| 1532 | assert.NotNil(t, msgObj) |
| 1533 | assert.True(t, msgOk) |
| 1534 | |
| 1535 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1536 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1537 | |
| 1538 | assert.Equal(t, uint16(tm.Year()), msgObj.Year) |
| 1539 | assert.Equal(t, uint8(tm.Month()), msgObj.Month) |
| 1540 | assert.Equal(t, uint8(tm.Day()), msgObj.Day) |
| 1541 | assert.Equal(t, uint8(tm.Hour()), msgObj.Hour) |
| 1542 | assert.Equal(t, uint8(tm.Minute()), msgObj.Minute) |
| 1543 | assert.Equal(t, uint8(tm.Second()), msgObj.Second) |
| 1544 | } |
| 1545 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1546 | func testSynchronizeTimeResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1547 | params := me.ParamData{ |
| 1548 | EntityID: uint16(0), |
| 1549 | } |
| 1550 | // Create the managed instance |
| 1551 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1552 | assert.NotNil(t, err) |
| 1553 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1554 | |
| 1555 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1556 | result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested |
| 1557 | successResult := uint8(rand.Int31n(2)) // [0, 1] |
| 1558 | |
| 1559 | var frame []byte |
| 1560 | frame, omciErr := GenFrame(meInstance, SynchronizeTimeResponseType, TransactionID(tid), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1561 | Result(result), SuccessResult(successResult), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1562 | assert.NotNil(t, frame) |
| 1563 | assert.NotZero(t, len(frame)) |
| 1564 | assert.Nil(t, omciErr) |
| 1565 | |
| 1566 | /////////////////////////////////////////////////////////////////// |
| 1567 | // Now decode and compare |
| 1568 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1569 | assert.NotNil(t, packet) |
| 1570 | |
| 1571 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1572 | assert.NotNil(t, omciLayer) |
| 1573 | |
| 1574 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1575 | assert.NotNil(t, omciObj) |
| 1576 | assert.True(t, omciOk) |
| 1577 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1578 | assert.Equal(t, SynchronizeTimeResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1579 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1580 | |
| 1581 | msgLayer := packet.Layer(LayerTypeSynchronizeTimeResponse) |
| 1582 | assert.NotNil(t, msgLayer) |
| 1583 | |
| 1584 | msgObj, msgOk := msgLayer.(*SynchronizeTimeResponse) |
| 1585 | assert.NotNil(t, msgObj) |
| 1586 | assert.True(t, msgOk) |
| 1587 | |
| 1588 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1589 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1590 | assert.Equal(t, result, msgObj.Result) |
| 1591 | if result == me.Success { |
| 1592 | assert.Equal(t, successResult, msgObj.SuccessResults) |
| 1593 | } else { |
| 1594 | assert.Zero(t, msgObj.SuccessResults) |
| 1595 | } |
| 1596 | } |
| 1597 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1598 | func testRebootRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1599 | params := me.ParamData{ |
| 1600 | EntityID: uint16(0), |
| 1601 | } |
| 1602 | // Create the managed instance |
| 1603 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1604 | assert.NotNil(t, err) |
| 1605 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1606 | |
| 1607 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1608 | condition := uint8(rand.Int31n(3)) // [0, 3] |
| 1609 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1610 | frame, omciErr := GenFrame(meInstance, RebootRequestType, TransactionID(tid), |
| 1611 | RebootCondition(condition), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1612 | assert.NotNil(t, frame) |
| 1613 | assert.NotZero(t, len(frame)) |
| 1614 | assert.Nil(t, omciErr) |
| 1615 | |
| 1616 | /////////////////////////////////////////////////////////////////// |
| 1617 | // Now decode and compare |
| 1618 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1619 | assert.NotNil(t, packet) |
| 1620 | |
| 1621 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1622 | assert.NotNil(t, omciLayer) |
| 1623 | |
| 1624 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1625 | assert.NotNil(t, omciObj) |
| 1626 | assert.True(t, omciOk) |
| 1627 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1628 | assert.Equal(t, RebootRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1629 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1630 | |
| 1631 | msgLayer := packet.Layer(LayerTypeRebootRequest) |
| 1632 | assert.NotNil(t, msgLayer) |
| 1633 | |
| 1634 | msgObj, msgOk := msgLayer.(*RebootRequest) |
| 1635 | assert.NotNil(t, msgObj) |
| 1636 | assert.True(t, msgOk) |
| 1637 | |
| 1638 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1639 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1640 | assert.Equal(t, condition, msgObj.RebootCondition) |
| 1641 | } |
| 1642 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1643 | func testRebootResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1644 | params := me.ParamData{ |
| 1645 | EntityID: uint16(0), |
| 1646 | } |
| 1647 | // Create the managed instance |
| 1648 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1649 | assert.NotNil(t, err) |
| 1650 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1651 | |
| 1652 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1653 | result := me.Results(rand.Int31n(7)) // [0, 6] Not all types will be tested |
| 1654 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1655 | frame, omciErr := GenFrame(meInstance, RebootResponseType, TransactionID(tid), |
| 1656 | Result(result), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1657 | assert.NotNil(t, frame) |
| 1658 | assert.NotZero(t, len(frame)) |
| 1659 | assert.Nil(t, omciErr) |
| 1660 | |
| 1661 | /////////////////////////////////////////////////////////////////// |
| 1662 | // Now decode and compare |
| 1663 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1664 | assert.NotNil(t, packet) |
| 1665 | |
| 1666 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1667 | assert.NotNil(t, omciLayer) |
| 1668 | |
| 1669 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1670 | assert.NotNil(t, omciObj) |
| 1671 | assert.True(t, omciOk) |
| 1672 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1673 | assert.Equal(t, RebootResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1674 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1675 | |
| 1676 | msgLayer := packet.Layer(LayerTypeRebootResponse) |
| 1677 | assert.NotNil(t, msgLayer) |
| 1678 | |
| 1679 | msgObj, msgOk := msgLayer.(*RebootResponse) |
| 1680 | assert.NotNil(t, msgObj) |
| 1681 | assert.True(t, msgOk) |
| 1682 | |
| 1683 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1684 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1685 | assert.Equal(t, result, msgObj.Result) |
| 1686 | } |
| 1687 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1688 | func testGetNextRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1689 | params := me.ParamData{ |
| 1690 | EntityID: uint16(0), |
| 1691 | Attributes: make(me.AttributeValueMap, 0), |
| 1692 | } |
| 1693 | // TODO: Loop over all table attributes for this class ID |
| 1694 | // Find first attribute that is a table definition |
| 1695 | // TODO: Test request of more than 1 attribute. G.988 specifies that a status |
| 1696 | // code of (3) should be returned. Raise error during encode instead of |
| 1697 | // waiting for compliant ONU. May want to have an 'ignore' to allow it. |
| 1698 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 1699 | for _, attrDef := range attrDefs { |
| 1700 | if attrDef.Index == 0 { |
| 1701 | continue // Skip entity ID, already specified |
| 1702 | } else if attrDef.IsTableAttribute() { |
| 1703 | // TODO: Tables without a size are not supported. At least needs to be one octet |
| 1704 | if attrDef.Size == 0 { |
| 1705 | continue |
| 1706 | } |
| 1707 | // Allow 'nil' as parameter value for GetNextRequests since we only need names |
| 1708 | params.Attributes[attrDef.GetName()] = nil |
| 1709 | break |
| 1710 | } |
| 1711 | } |
| 1712 | if len(params.Attributes) == 0 { |
| 1713 | return |
| 1714 | } |
| 1715 | bitmask, attrErr := me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 1716 | assert.Nil(t, attrErr) |
| 1717 | |
| 1718 | // Create the managed instance |
| 1719 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1720 | assert.NotNil(t, err) |
| 1721 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1722 | |
| 1723 | seqNumber := uint16(rand.Int31n(0xFFFF)) // [0, 0xFFFE] |
| 1724 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1725 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1726 | frame, omciErr := GenFrame(meInstance, GetNextRequestType, TransactionID(tid), |
| 1727 | SequenceNumberCountOrSize(seqNumber), AttributeMask(bitmask), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1728 | assert.NotNil(t, frame) |
| 1729 | assert.NotZero(t, len(frame)) |
| 1730 | assert.Nil(t, omciErr) |
| 1731 | |
| 1732 | /////////////////////////////////////////////////////////////////// |
| 1733 | // Now decode and compare |
| 1734 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1735 | assert.NotNil(t, packet) |
| 1736 | |
| 1737 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1738 | assert.NotNil(t, omciLayer) |
| 1739 | |
| 1740 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1741 | assert.NotNil(t, omciObj) |
| 1742 | assert.True(t, omciOk) |
| 1743 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1744 | assert.Equal(t, GetNextRequestType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1745 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1746 | |
| 1747 | msgLayer := packet.Layer(LayerTypeGetNextRequest) |
| 1748 | assert.NotNil(t, msgLayer) |
| 1749 | |
| 1750 | msgObj, msgOk := msgLayer.(*GetNextRequest) |
| 1751 | assert.NotNil(t, msgObj) |
| 1752 | assert.True(t, msgOk) |
| 1753 | |
| 1754 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1755 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1756 | assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask) |
| 1757 | assert.Equal(t, seqNumber, msgObj.SequenceNumber) |
| 1758 | } |
| 1759 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1760 | func testGetNextResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1761 | params := me.ParamData{ |
| 1762 | EntityID: uint16(0), |
| 1763 | Attributes: make(me.AttributeValueMap, 0), |
| 1764 | } |
| 1765 | // TODO: Loop over result types (here and other responses with results) |
| 1766 | result := me.Success // me.Results(rand.Int31n(7)) // [0, 6] |
| 1767 | bitmask := uint16(0) |
| 1768 | attrDefs := managedEntity.GetAttributeDefinitions() |
| 1769 | |
| 1770 | // TODO: Loop over all table attributes for this class ID |
| 1771 | if result == me.Success { |
| 1772 | // Find first attribute that is a table definition |
| 1773 | // TODO: Test request of more than 1 attribute. G.988 specifies that a status |
| 1774 | // code of (3) should be returned. Raise error during encode instead of |
| 1775 | // waiting for compliant ONU. May want to have an 'ignore' to allow it. |
| 1776 | for _, attrDef := range attrDefs { |
| 1777 | if attrDef.Index == 0 { |
| 1778 | continue // Skip entity ID, already specified |
| 1779 | } else if attrDef.IsTableAttribute() { |
| 1780 | if len(params.Attributes) == 0 { |
| 1781 | // Need a parameter that is a table attribute |
| 1782 | return |
| 1783 | } |
| 1784 | params.Attributes[attrDef.GetName()] = pickAValue(attrDef) |
| 1785 | break |
| 1786 | } |
| 1787 | } |
| 1788 | if len(params.Attributes) == 0 { |
| 1789 | return |
| 1790 | } |
| 1791 | assert.NotEmpty(t, params.Attributes) // Need a parameter that is a table attribute |
| 1792 | var attrErr error |
| 1793 | bitmask, attrErr = me.GetAttributesBitmap(attrDefs, getAttributeNameSet(params.Attributes)) |
| 1794 | assert.Nil(t, attrErr) |
| 1795 | } |
| 1796 | // Create the managed instance |
| 1797 | meInstance, err := me.NewManagedEntity(managedEntity.GetManagedEntityDefinition(), params) |
| 1798 | assert.NotNil(t, err) |
| 1799 | assert.Equal(t, err.StatusCode(), me.Success) |
| 1800 | |
| 1801 | tid := uint16(rand.Int31n(0xFFFE) + 1) // [1, 0xFFFF] |
| 1802 | |
| 1803 | frame, omciErr := GenFrame(meInstance, GetNextResponseType, TransactionID(tid), Result(result), |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1804 | AttributeMask(bitmask), FrameFormat(messageSet)) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1805 | assert.NotNil(t, frame) |
| 1806 | assert.NotZero(t, len(frame)) |
| 1807 | assert.Nil(t, omciErr) |
| 1808 | |
| 1809 | /////////////////////////////////////////////////////////////////// |
| 1810 | // Now decode and compare |
| 1811 | cid := meInstance.GetClassID() |
| 1812 | assert.NotEqual(t, cid, 0) |
| 1813 | packet := gopacket.NewPacket(frame, LayerTypeOMCI, gopacket.NoCopy) |
| 1814 | assert.NotNil(t, packet) |
| 1815 | |
| 1816 | omciLayer := packet.Layer(LayerTypeOMCI) |
| 1817 | assert.NotNil(t, omciLayer) |
| 1818 | |
| 1819 | omciObj, omciOk := omciLayer.(*OMCI) |
| 1820 | assert.NotNil(t, omciObj) |
| 1821 | assert.True(t, omciOk) |
| 1822 | assert.Equal(t, tid, omciObj.TransactionID) |
| 1823 | assert.Equal(t, GetNextResponseType, omciObj.MessageType) |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1824 | assert.Equal(t, messageSet, omciObj.DeviceIdentifier) |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1825 | |
| 1826 | msgLayer := packet.Layer(LayerTypeGetNextResponse) |
| 1827 | assert.NotNil(t, msgLayer) |
| 1828 | |
| 1829 | msgObj, msgOk := msgLayer.(*GetNextResponse) |
| 1830 | assert.NotNil(t, msgObj) |
| 1831 | assert.True(t, msgOk) |
| 1832 | |
| 1833 | assert.Equal(t, meInstance.GetClassID(), msgObj.EntityClass) |
| 1834 | assert.Equal(t, meInstance.GetEntityID(), msgObj.EntityInstance) |
| 1835 | assert.Equal(t, meInstance.GetAttributeMask(), msgObj.AttributeMask) |
| 1836 | |
| 1837 | switch msgObj.Result { |
| 1838 | default: |
| 1839 | assert.Equal(t, result, msgObj.Result) |
| 1840 | |
| 1841 | case me.Success: |
| 1842 | assert.Equal(t, result, msgObj.Result) |
| 1843 | // The attributes should be equal but for variable length table attribute (size = 0 in structure) |
| 1844 | // we will have the frame padding returned as well. |
| 1845 | for attrName, value := range meInstance.GetAttributeValueMap() { |
| 1846 | attr, err := me.GetAttributeDefinitionByName(attrDefs, attrName) |
| 1847 | assert.Nil(t, err) |
| 1848 | assert.NotNil(t, attr) |
| 1849 | assert.Equal(t, attrName, attr.GetName()) |
| 1850 | if attr.IsTableAttribute() { |
| 1851 | instValue := value.([]byte) |
| 1852 | msgValue := msgObj.Attributes[attrName].([]byte) |
| 1853 | assert.True(t, len(instValue) <= len(msgValue)) |
| 1854 | assert.Equal(t, msgValue[:len(instValue)], instValue) |
| 1855 | } else { |
| 1856 | assert.Equal(t, value, msgObj.Attributes[attrName]) |
| 1857 | } |
| 1858 | } |
| 1859 | } |
| 1860 | } |
| 1861 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1862 | func testGetCurrentDataRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1863 | // TODO: Implement |
| 1864 | } |
| 1865 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1866 | func testGetCurrentDataResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1867 | // TODO: Implement |
| 1868 | } |
| 1869 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1870 | func testSetTableRequestTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1871 | // TODO: Implement |
| 1872 | } |
| 1873 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1874 | func testSetTableResponseTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1875 | // TODO: Implement |
| 1876 | } |
| 1877 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1878 | func testAlarmNotificationTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1879 | // TODO: Implement |
| 1880 | } |
| 1881 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1882 | func testAttributeValueChangeTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1883 | // TODO: Implement |
| 1884 | } |
| 1885 | |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 1886 | func testTestResultTypeMeFrame(t *testing.T, managedEntity *me.ManagedEntity, messageSet DeviceIdent) { |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1887 | // TODO: Implement |
| 1888 | } |