Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 17 | //Package omcitst provides the omci test functionality |
| 18 | package omcitst |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 22 | "encoding/hex" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 23 | "fmt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 25 | gp "github.com/google/gopacket" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 26 | "github.com/opencord/omci-lib-go/v2" |
| 27 | me "github.com/opencord/omci-lib-go/v2/generated" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 28 | "github.com/opencord/omci-lib-go/v2/meframe" |
| 29 | oframe "github.com/opencord/omci-lib-go/v2/meframe" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 31 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 32 | ) |
| 33 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 34 | //OmciTestRequest structure holds the information for the OMCI test |
| 35 | type OmciTestRequest struct { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 36 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 37 | pDevOmciCC *cmn.OmciCC |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 38 | extended bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 39 | started bool |
| 40 | result bool |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 41 | exclusiveCc bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 42 | allowFailure bool |
| 43 | txSeqNo uint16 |
| 44 | verifyDone chan<- bool |
| 45 | } |
| 46 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 47 | // CTestRequestOmciTimeout - Special OMCI timeout for low prio test request |
| 48 | const CTestRequestOmciTimeout = 5 |
| 49 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 50 | //NewOmciTestRequest returns a new instance of OmciTestRequest |
| 51 | func NewOmciTestRequest(ctx context.Context, |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 52 | deviceID string, omciCc *cmn.OmciCC, extended bool, |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 53 | exclusive bool, allowFailure bool) *OmciTestRequest { |
| 54 | logger.Debug(ctx, "OmciTestRequest-init") |
| 55 | var OmciTestRequest OmciTestRequest |
| 56 | OmciTestRequest.deviceID = deviceID |
| 57 | OmciTestRequest.pDevOmciCC = omciCc |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 58 | OmciTestRequest.extended = extended |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 59 | OmciTestRequest.started = false |
| 60 | OmciTestRequest.result = false |
| 61 | OmciTestRequest.exclusiveCc = exclusive |
| 62 | OmciTestRequest.allowFailure = allowFailure |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 63 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 64 | return &OmciTestRequest |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 67 | // PerformOmciTest - TODO: add comment |
| 68 | func (oo *OmciTestRequest) PerformOmciTest(ctx context.Context, execChannel chan<- bool) { |
| 69 | logger.Debug(ctx, "OmciTestRequest-start-test") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 70 | |
| 71 | if oo.pDevOmciCC != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 72 | oo.verifyDone = execChannel |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 73 | // test functionality is limited to ONU-2G get request for the moment |
| 74 | // without yet checking the received response automatically here (might be improved ??) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 75 | tid := oo.pDevOmciCC.GetNextTid(false) |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 76 | onu2gGet, _ := oo.createOnu2gGet(ctx, tid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 77 | omciRxCallbackPair := cmn.CallbackPair{ |
| 78 | CbKey: tid, |
| 79 | CbEntry: cmn.CallbackPairEntry{ |
| 80 | CbRespChannel: nil, |
| 81 | CbFunction: oo.ReceiveOmciVerifyResponse, |
| 82 | FramePrint: true, |
| 83 | }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 84 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 85 | logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID, "onu2gGet": hex.EncodeToString(onu2gGet)}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 86 | // send with default timeout and normal prio |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 87 | // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 88 | go oo.pDevOmciCC.Send(ctx, onu2gGet, CTestRequestOmciTimeout, cmn.CDefaultRetries, false, omciRxCallbackPair) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 89 | |
| 90 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 91 | logger.Errorw(ctx, "performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | // these are OMCI related functions, could/should be collected in a separate file? TODO!!! |
| 96 | // for a simple start just included in here |
| 97 | //basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 98 | func (oo *OmciTestRequest) createOnu2gGet(ctx context.Context, tid uint16) ([]byte, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 99 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 100 | meParams := me.ParamData{ |
| 101 | EntityID: 0, |
| 102 | Attributes: me.AttributeValueMap{ |
| 103 | me.Onu2G_EquipmentId: "", |
| 104 | me.Onu2G_OpticalNetworkUnitManagementAndControlChannelOmccVersion: 0}, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 105 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 106 | meInstance, omciErr := me.NewOnu2G(meParams) |
| 107 | if omciErr.GetError() == nil { |
| 108 | var messageSet omci.DeviceIdent = omci.BaselineIdent |
| 109 | if oo.extended { |
| 110 | messageSet = omci.ExtendedIdent |
| 111 | } |
| 112 | omciLayer, msgLayer, err := oframe.EncodeFrame(meInstance, omci.GetRequestType, oframe.TransactionID(tid), |
| 113 | meframe.FrameFormat(messageSet)) |
| 114 | if err != nil { |
| 115 | logger.Errorw(ctx, "Cannot encode ONU2-G instance for get", log.Fields{ |
| 116 | "Err": err, "device-id": oo.deviceID}) |
| 117 | return nil, err |
| 118 | } |
| 119 | oo.txSeqNo = tid |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 121 | pkt, err := cmn.SerializeOmciLayer(ctx, omciLayer, msgLayer) |
| 122 | if err != nil { |
| 123 | logger.Errorw(ctx, "Cannot serialize ONU2-G get", log.Fields{ |
| 124 | "Err": err, "device-id": oo.deviceID}) |
| 125 | return nil, err |
| 126 | } |
| 127 | return pkt, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 128 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 129 | logger.Errorw(ctx, "Cannot generate ONU2-G", log.Fields{ |
| 130 | "Err": omciErr.GetError(), "device-id": oo.deviceID}) |
| 131 | return nil, omciErr.GetError() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 134 | //ReceiveOmciVerifyResponse supply a response handler - in this testobject the message is evaluated directly, no response channel used |
| 135 | func (oo *OmciTestRequest) ReceiveOmciVerifyResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan cmn.Message) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 136 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 137 | logger.Debugw(ctx, "verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 138 | "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier}) |
| 139 | |
| 140 | if omciMsg.TransactionID == oo.txSeqNo { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 141 | logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 142 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 143 | logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | "expected": oo.txSeqNo}) |
| 145 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 146 | return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 147 | } |
| 148 | if omciMsg.MessageType == omci.GetResponseType { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 149 | logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 150 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 151 | logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 152 | "expected": omci.GetResponseType}) |
| 153 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 154 | return fmt.Errorf("unexpected MessageType %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | } |
Holger Hildebrandt | a6ef0e8 | 2022-04-06 13:11:32 +0000 | [diff] [blame^] | 156 | if oo.extended { |
| 157 | if omciMsg.DeviceIdentifier == omci.ExtendedIdent { |
| 158 | logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct DeviceIdentifier": omciMsg.DeviceIdentifier}) |
| 159 | } else { |
| 160 | logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect DeviceIdentifier": omciMsg.DeviceIdentifier, |
| 161 | "expected": omci.ExtendedIdent}) |
| 162 | oo.verifyDone <- false |
| 163 | return fmt.Errorf("unexpected DeviceIdentifier %s", oo.deviceID) |
| 164 | } |
| 165 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 166 | |
| 167 | //TODO!!! further tests on the payload should be done here ... |
| 168 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 169 | oo.pDevOmciCC.RLockMutexMonReq() |
| 170 | if _, exist := oo.pDevOmciCC.GetMonitoredRequest(omciMsg.TransactionID); exist { |
| 171 | oo.pDevOmciCC.SetChMonitoredRequest(omciMsg.TransactionID, true) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 172 | } else { |
| 173 | logger.Infow(ctx, "reqMon: map entry does not exist!", |
| 174 | log.Fields{"tid": omciMsg.TransactionID, "device-id": oo.deviceID}) |
| 175 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 176 | oo.pDevOmciCC.RUnlockMutexMonReq() |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 177 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 178 | oo.result = true |
| 179 | oo.verifyDone <- true |
| 180 | |
| 181 | return nil |
| 182 | } |