blob: 235f21d2b8c633c17bc4cc74f21941770d5c9f72 [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 Hildebrandt0f9b88d2020-04-20 13:33:25 +000017//Package adaptercoreonu provides the utility for onu devices, flows and statistics
18package adaptercoreonu
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"
27
khenaidoo7d3c5582021-08-11 18:09:44 -040028 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000029)
30
Himani Chawla6d2ae152020-09-02 13:11:20 +053031//omciTestRequest structure holds the information for the OMCI test
32type omciTestRequest struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000033 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053034 pDevOmciCC *omciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +000035 started bool
36 result bool
Himani Chawla4d908332020-08-31 12:30:20 +053037 exclusiveCc bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000038 allowFailure bool
39 txSeqNo uint16
40 verifyDone chan<- bool
41}
42
Himani Chawla6d2ae152020-09-02 13:11:20 +053043//newOmciTestRequest returns a new instance of OmciTestRequest
44func newOmciTestRequest(ctx context.Context,
45 deviceID string, omciCc *omciCC,
46 exclusive bool, allowFailure bool) *omciTestRequest {
dbainbri4d3a0dc2020-12-02 00:33:42 +000047 logger.Debug(ctx, "omciTestRequest-init")
Himani Chawla6d2ae152020-09-02 13:11:20 +053048 var omciTestRequest omciTestRequest
Himani Chawla4d908332020-08-31 12:30:20 +053049 omciTestRequest.deviceID = deviceID
50 omciTestRequest.pDevOmciCC = omciCc
Holger Hildebrandtfa074992020-03-27 15:42:06 +000051 omciTestRequest.started = false
52 omciTestRequest.result = false
Himani Chawla4d908332020-08-31 12:30:20 +053053 omciTestRequest.exclusiveCc = exclusive
54 omciTestRequest.allowFailure = allowFailure
Holger Hildebrandtfa074992020-03-27 15:42:06 +000055
56 return &omciTestRequest
57}
58
59//
Himani Chawla6d2ae152020-09-02 13:11:20 +053060func (oo *omciTestRequest) performOmciTest(ctx context.Context, execChannel chan<- bool) {
dbainbri4d3a0dc2020-12-02 00:33:42 +000061 logger.Debug(ctx, "omciTestRequest-start-test")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000062
63 if oo.pDevOmciCC != nil {
Himani Chawla4d908332020-08-31 12:30:20 +053064 oo.verifyDone = execChannel
Holger Hildebrandtfa074992020-03-27 15:42:06 +000065 // test functionality is limited to ONU-2G get request for the moment
66 // without yet checking the received response automatically here (might be improved ??)
Himani Chawla6d2ae152020-09-02 13:11:20 +053067 tid := oo.pDevOmciCC.getNextTid(false)
dbainbri4d3a0dc2020-12-02 00:33:42 +000068 onu2gBaseGet, _ := oo.createOnu2gBaseGet(ctx, tid)
Himani Chawla6d2ae152020-09-02 13:11:20 +053069 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000070 cbKey: tid,
mpagenko80622a52021-02-09 16:53:23 +000071 cbEntry: callbackPairEntry{nil, oo.receiveOmciVerifyResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000072 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +000073
dbainbri4d3a0dc2020-12-02 00:33:42 +000074 logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000075 // send with default timeout and normal prio
Girish Gowdra0b235842021-03-09 13:06:46 -080076 // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s
Holger Hildebrandt366ef192021-05-05 11:07:44 +000077 go oo.pDevOmciCC.send(ctx, onu2gBaseGet, 10, cDefaultRetries, false, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000078
79 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +000080 logger.Errorw(ctx, "performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000081 }
82}
83
84// these are OMCI related functions, could/should be collected in a separate file? TODO!!!
85// for a simple start just included in here
86//basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go
dbainbri4d3a0dc2020-12-02 00:33:42 +000087func (oo *omciTestRequest) createOnu2gBaseGet(ctx context.Context, tid uint16) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088
89 request := &omci.GetRequest{
90 MeBasePacket: omci.MeBasePacket{
91 EntityClass: me.Onu2GClassID,
92 EntityInstance: 0, //there is only the 0 instance of ONU2-G (still hard-coded - TODO!!!)
93 },
94 AttributeMask: 0xE000, //example hardcoded (TODO!!!) request EquId, OmccVersion, VendorCode
95 }
96
97 oo.txSeqNo = tid
dbainbri4d3a0dc2020-12-02 00:33:42 +000098 pkt, err := serialize(ctx, omci.GetRequestType, request, tid)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000099 if err != nil {
100 //omciLogger.WithFields(log.Fields{ ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000101 logger.Errorw(ctx, "Cannot serialize Onu2-G GetRequest", log.Fields{"device-id": oo.deviceID, "Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000102 return nil, err
103 }
104 // hexEncode would probably work as well, but not needed and leads to wrong logs on OltAdapter frame
105 // return hexEncode(pkt)
106 return pkt, nil
107}
108
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000109//supply a response handler - in this testobject the message is evaluated directly, no response channel used
dbainbri4d3a0dc2020-12-02 00:33:42 +0000110func (oo *omciTestRequest) receiveOmciVerifyResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000111
dbainbri4d3a0dc2020-12-02 00:33:42 +0000112 logger.Debugw(ctx, "verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000113 "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier})
114
115 if omciMsg.TransactionID == oo.txSeqNo {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000116 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000118 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119 "expected": oo.txSeqNo})
120 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200121 return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000122 }
123 if omciMsg.MessageType == omci.GetResponseType {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000124 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000126 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000127 "expected": omci.GetResponseType})
128 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200129 return fmt.Errorf("unexpected MessageType %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000130 }
131
132 //TODO!!! further tests on the payload should be done here ...
133
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000134 oo.pDevOmciCC.mutexMonReq.RLock()
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000135 if _, exist := oo.pDevOmciCC.monitoredRequests[omciMsg.TransactionID]; exist {
136 oo.pDevOmciCC.monitoredRequests[omciMsg.TransactionID].chSuccess <- true
137 } else {
138 logger.Infow(ctx, "reqMon: map entry does not exist!",
139 log.Fields{"tid": omciMsg.TransactionID, "device-id": oo.deviceID})
140 }
Holger Hildebrandt0da7e6f2021-05-12 13:08:43 +0000141 oo.pDevOmciCC.mutexMonReq.RUnlock()
Holger Hildebrandt366ef192021-05-05 11:07:44 +0000142
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000143 oo.result = true
144 oo.verifyDone <- true
145
146 return nil
147}