blob: 33db828aadbe93883a9a2fcc99b29b37450db831 [file] [log] [blame]
Holger Hildebrandtfa074992020-03-27 15:42:06 +00001/*
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 Hildebrandt4b5e73f2021-08-19 06:51:21 +000017//Package omcitst provides the omci test functionality
18package omcitst
Holger Hildebrandtfa074992020-03-27 15:42:06 +000019
20import (
21 "context"
Andrea Campanella6515c582020-10-05 11:25:00 +020022 "fmt"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000023
Holger Hildebrandtfa074992020-03-27 15:42:06 +000024 gp "github.com/google/gopacket"
25 "github.com/opencord/omci-lib-go"
26 me "github.com/opencord/omci-lib-go/generated"
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000027 cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028
khenaidoo7d3c5582021-08-11 18:09:44 -040029 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000030)
31
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000032//OmciTestRequest structure holds the information for the OMCI test
33type OmciTestRequest struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000034 deviceID string
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000035 pDevOmciCC *cmn.OmciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +000036 started bool
37 result bool
Himani Chawla4d908332020-08-31 12:30:20 +053038 exclusiveCc bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039 allowFailure bool
40 txSeqNo uint16
41 verifyDone chan<- bool
42}
43
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000044//NewOmciTestRequest returns a new instance of OmciTestRequest
45func 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 Hildebrandtfa074992020-03-27 15:42:06 +000056
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000057 return &OmciTestRequest
Holger Hildebrandtfa074992020-03-27 15:42:06 +000058}
59
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000060// PerformOmciTest - TODO: add comment
61func (oo *OmciTestRequest) PerformOmciTest(ctx context.Context, execChannel chan<- bool) {
62 logger.Debug(ctx, "OmciTestRequest-start-test")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000063
64 if oo.pDevOmciCC != nil {
Himani Chawla4d908332020-08-31 12:30:20 +053065 oo.verifyDone = execChannel
Holger Hildebrandtfa074992020-03-27 15:42:06 +000066 // 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 Hildebrandt4b5e73f2021-08-19 06:51:21 +000068 tid := oo.pDevOmciCC.GetNextTid(false)
dbainbri4d3a0dc2020-12-02 00:33:42 +000069 onu2gBaseGet, _ := oo.createOnu2gBaseGet(ctx, tid)
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000070 omciRxCallbackPair := cmn.CallbackPair{
71 CbKey: tid,
72 CbEntry: cmn.CallbackPairEntry{
73 CbRespChannel: nil,
74 CbFunction: oo.ReceiveOmciVerifyResponse,
75 FramePrint: true,
76 },
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000077 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078
dbainbri4d3a0dc2020-12-02 00:33:42 +000079 logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080 // send with default timeout and normal prio
Girish Gowdra0b235842021-03-09 13:06:46 -080081 // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +000082 go oo.pDevOmciCC.Send(ctx, onu2gBaseGet, 10, cmn.CDefaultRetries, false, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000083
84 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +000085 logger.Errorw(ctx, "performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000086 }
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 Hildebrandt4b5e73f2021-08-19 06:51:21 +000092func (oo *OmciTestRequest) createOnu2gBaseGet(ctx context.Context, tid uint16) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000093
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 Hildebrandt4b5e73f2021-08-19 06:51:21 +0000103 pkt, err := cmn.Serialize(ctx, omci.GetRequestType, request, tid)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000104 if err != nil {
105 //omciLogger.WithFields(log.Fields{ ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000106 logger.Errorw(ctx, "Cannot serialize Onu2-G GetRequest", log.Fields{"device-id": oo.deviceID, "Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000107 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 Hildebrandt4b5e73f2021-08-19 06:51:21 +0000114//ReceiveOmciVerifyResponse supply a response handler - in this testobject the message is evaluated directly, no response channel used
115func (oo *OmciTestRequest) ReceiveOmciVerifyResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan cmn.Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000116
dbainbri4d3a0dc2020-12-02 00:33:42 +0000117 logger.Debugw(ctx, "verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000118 "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier})
119
120 if omciMsg.TransactionID == oo.txSeqNo {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000121 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000123 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 "expected": oo.txSeqNo})
125 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200126 return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127 }
128 if omciMsg.MessageType == omci.GetResponseType {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000129 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000130 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000131 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000132 "expected": omci.GetResponseType})
133 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200134 return fmt.Errorf("unexpected MessageType %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000135 }
136
137 //TODO!!! further tests on the payload should be done here ...
138
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000139 oo.pDevOmciCC.RLockMutexMonReq()
140 if _, exist := oo.pDevOmciCC.GetMonitoredRequest(omciMsg.TransactionID); exist {
141 oo.pDevOmciCC.SetChMonitoredRequest(omciMsg.TransactionID, true)
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000142 } else {
143 logger.Infow(ctx, "reqMon: map entry does not exist!",
144 log.Fields{"tid": omciMsg.TransactionID, "device-id": oo.deviceID})
145 }
Holger Hildebrandt4b5e73f2021-08-19 06:51:21 +0000146 oo.pDevOmciCC.RUnlockMutexMonReq()
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000147
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000148 oo.result = true
149 oo.verifyDone <- true
150
151 return nil
152}