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