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" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 22 | "fmt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 23 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | gp "github.com/google/gopacket" |
mpagenko | 836a1fd | 2021-11-01 16:12:42 +0000 | [diff] [blame] | 25 | "github.com/opencord/omci-lib-go/v2" |
| 26 | me "github.com/opencord/omci-lib-go/v2/generated" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 27 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 28 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 30 | ) |
| 31 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 32 | //OmciTestRequest structure holds the information for the OMCI test |
| 33 | type OmciTestRequest struct { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 34 | deviceID string |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 35 | pDevOmciCC *cmn.OmciCC |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 36 | started bool |
| 37 | result bool |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 38 | exclusiveCc bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 39 | allowFailure bool |
| 40 | txSeqNo uint16 |
| 41 | verifyDone chan<- bool |
| 42 | } |
| 43 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 44 | //NewOmciTestRequest returns a new instance of OmciTestRequest |
| 45 | func NewOmciTestRequest(ctx context.Context, |
| 46 | deviceID string, omciCc *cmn.OmciCC, |
| 47 | exclusive bool, allowFailure bool) *OmciTestRequest { |
| 48 | logger.Debug(ctx, "OmciTestRequest-init") |
| 49 | var OmciTestRequest OmciTestRequest |
| 50 | OmciTestRequest.deviceID = deviceID |
| 51 | OmciTestRequest.pDevOmciCC = omciCc |
| 52 | OmciTestRequest.started = false |
| 53 | OmciTestRequest.result = false |
| 54 | OmciTestRequest.exclusiveCc = exclusive |
| 55 | OmciTestRequest.allowFailure = allowFailure |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 56 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 57 | return &OmciTestRequest |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 60 | // PerformOmciTest - TODO: add comment |
| 61 | func (oo *OmciTestRequest) PerformOmciTest(ctx context.Context, execChannel chan<- bool) { |
| 62 | logger.Debug(ctx, "OmciTestRequest-start-test") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 63 | |
| 64 | if oo.pDevOmciCC != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 65 | oo.verifyDone = execChannel |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 66 | // test functionality is limited to ONU-2G get request for the moment |
| 67 | // without yet checking the received response automatically here (might be improved ??) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 68 | tid := oo.pDevOmciCC.GetNextTid(false) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 69 | onu2gBaseGet, _ := oo.createOnu2gBaseGet(ctx, tid) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 70 | omciRxCallbackPair := cmn.CallbackPair{ |
| 71 | CbKey: tid, |
| 72 | CbEntry: cmn.CallbackPairEntry{ |
| 73 | CbRespChannel: nil, |
| 74 | CbFunction: oo.ReceiveOmciVerifyResponse, |
| 75 | FramePrint: true, |
| 76 | }, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 77 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 78 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 79 | logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 80 | // send with default timeout and normal prio |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 81 | // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 82 | go oo.pDevOmciCC.Send(ctx, onu2gBaseGet, 10, cmn.CDefaultRetries, false, omciRxCallbackPair) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 83 | |
| 84 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 85 | 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] | 86 | } |
| 87 | } |
| 88 | |
| 89 | // these are OMCI related functions, could/should be collected in a separate file? TODO!!! |
| 90 | // for a simple start just included in here |
| 91 | //basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 92 | func (oo *OmciTestRequest) createOnu2gBaseGet(ctx context.Context, tid uint16) ([]byte, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 93 | |
| 94 | request := &omci.GetRequest{ |
| 95 | MeBasePacket: omci.MeBasePacket{ |
| 96 | EntityClass: me.Onu2GClassID, |
| 97 | EntityInstance: 0, //there is only the 0 instance of ONU2-G (still hard-coded - TODO!!!) |
| 98 | }, |
| 99 | AttributeMask: 0xE000, //example hardcoded (TODO!!!) request EquId, OmccVersion, VendorCode |
| 100 | } |
| 101 | |
| 102 | oo.txSeqNo = tid |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 103 | pkt, err := cmn.Serialize(ctx, omci.GetRequestType, request, tid) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 104 | if err != nil { |
| 105 | //omciLogger.WithFields(log.Fields{ ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 106 | logger.Errorw(ctx, "Cannot serialize Onu2-G GetRequest", log.Fields{"device-id": oo.deviceID, "Err": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 107 | return nil, err |
| 108 | } |
| 109 | // hexEncode would probably work as well, but not needed and leads to wrong logs on OltAdapter frame |
| 110 | // return hexEncode(pkt) |
| 111 | return pkt, nil |
| 112 | } |
| 113 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 114 | //ReceiveOmciVerifyResponse supply a response handler - in this testobject the message is evaluated directly, no response channel used |
| 115 | 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] | 116 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 117 | 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] | 118 | "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier}) |
| 119 | |
| 120 | if omciMsg.TransactionID == oo.txSeqNo { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 121 | 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] | 122 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 123 | 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] | 124 | "expected": oo.txSeqNo}) |
| 125 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 126 | return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 127 | } |
| 128 | if omciMsg.MessageType == omci.GetResponseType { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 129 | 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] | 130 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 131 | 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] | 132 | "expected": omci.GetResponseType}) |
| 133 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 134 | return fmt.Errorf("unexpected MessageType %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | //TODO!!! further tests on the payload should be done here ... |
| 138 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 139 | oo.pDevOmciCC.RLockMutexMonReq() |
| 140 | if _, exist := oo.pDevOmciCC.GetMonitoredRequest(omciMsg.TransactionID); exist { |
| 141 | oo.pDevOmciCC.SetChMonitoredRequest(omciMsg.TransactionID, true) |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 142 | } else { |
| 143 | logger.Infow(ctx, "reqMon: map entry does not exist!", |
| 144 | log.Fields{"tid": omciMsg.TransactionID, "device-id": oo.deviceID}) |
| 145 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 146 | oo.pDevOmciCC.RUnlockMutexMonReq() |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 147 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 148 | oo.result = true |
| 149 | oo.verifyDone <- true |
| 150 | |
| 151 | return nil |
| 152 | } |