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