blob: 4395f10c707a9a3f210524a45e57e87b6512b0f7 [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
24 //"sync"
25 //"time"
26
27 gp "github.com/google/gopacket"
28 "github.com/opencord/omci-lib-go"
29 me "github.com/opencord/omci-lib-go/generated"
30
dbainbri4d3a0dc2020-12-02 00:33:42 +000031 //"github.com/opencord/voltha-lib-go/v4/pkg/kafka"
32 "github.com/opencord/voltha-lib-go/v4/pkg/log"
33 //ic "github.com/opencord/voltha-protos/v4/go/inter_container"
34 //"github.com/opencord/voltha-protos/v4/go/openflow_13"
35 //"github.com/opencord/voltha-protos/v4/go/voltha"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000036)
37
Himani Chawla6d2ae152020-09-02 13:11:20 +053038//omciTestRequest structure holds the information for the OMCI test
39type omciTestRequest struct {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000040 deviceID string
Himani Chawla6d2ae152020-09-02 13:11:20 +053041 pDevOmciCC *omciCC
Holger Hildebrandtfa074992020-03-27 15:42:06 +000042 started bool
43 result bool
Himani Chawla4d908332020-08-31 12:30:20 +053044 exclusiveCc bool
Holger Hildebrandtfa074992020-03-27 15:42:06 +000045 allowFailure bool
46 txSeqNo uint16
47 verifyDone chan<- bool
48}
49
Himani Chawla6d2ae152020-09-02 13:11:20 +053050//newOmciTestRequest returns a new instance of OmciTestRequest
51func newOmciTestRequest(ctx context.Context,
52 deviceID string, omciCc *omciCC,
53 exclusive bool, allowFailure bool) *omciTestRequest {
dbainbri4d3a0dc2020-12-02 00:33:42 +000054 logger.Debug(ctx, "omciTestRequest-init")
Himani Chawla6d2ae152020-09-02 13:11:20 +053055 var omciTestRequest omciTestRequest
Himani Chawla4d908332020-08-31 12:30:20 +053056 omciTestRequest.deviceID = deviceID
57 omciTestRequest.pDevOmciCC = omciCc
Holger Hildebrandtfa074992020-03-27 15:42:06 +000058 omciTestRequest.started = false
59 omciTestRequest.result = false
Himani Chawla4d908332020-08-31 12:30:20 +053060 omciTestRequest.exclusiveCc = exclusive
61 omciTestRequest.allowFailure = allowFailure
Holger Hildebrandtfa074992020-03-27 15:42:06 +000062
63 return &omciTestRequest
64}
65
66//
Himani Chawla6d2ae152020-09-02 13:11:20 +053067func (oo *omciTestRequest) performOmciTest(ctx context.Context, execChannel chan<- bool) {
dbainbri4d3a0dc2020-12-02 00:33:42 +000068 logger.Debug(ctx, "omciTestRequest-start-test")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000069
70 if oo.pDevOmciCC != nil {
Himani Chawla4d908332020-08-31 12:30:20 +053071 oo.verifyDone = execChannel
Holger Hildebrandtfa074992020-03-27 15:42:06 +000072 // test functionality is limited to ONU-2G get request for the moment
73 // without yet checking the received response automatically here (might be improved ??)
Himani Chawla6d2ae152020-09-02 13:11:20 +053074 tid := oo.pDevOmciCC.getNextTid(false)
dbainbri4d3a0dc2020-12-02 00:33:42 +000075 onu2gBaseGet, _ := oo.createOnu2gBaseGet(ctx, tid)
Himani Chawla6d2ae152020-09-02 13:11:20 +053076 omciRxCallbackPair := callbackPair{
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000077 cbKey: tid,
mpagenko80622a52021-02-09 16:53:23 +000078 cbEntry: callbackPairEntry{nil, oo.receiveOmciVerifyResponse, true},
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000079 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080
dbainbri4d3a0dc2020-12-02 00:33:42 +000081 logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000082 // send with default timeout and normal prio
Girish Gowdra0b235842021-03-09 13:06:46 -080083 // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s
84 go oo.pDevOmciCC.send(ctx, onu2gBaseGet, 10, 0, false, omciRxCallbackPair)
Holger Hildebrandtfa074992020-03-27 15:42:06 +000085
86 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +000087 logger.Errorw(ctx, "performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000088 }
89}
90
91// these are OMCI related functions, could/should be collected in a separate file? TODO!!!
92// for a simple start just included in here
93//basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go
dbainbri4d3a0dc2020-12-02 00:33:42 +000094func (oo *omciTestRequest) createOnu2gBaseGet(ctx context.Context, tid uint16) ([]byte, error) {
Holger Hildebrandtfa074992020-03-27 15:42:06 +000095
96 request := &omci.GetRequest{
97 MeBasePacket: omci.MeBasePacket{
98 EntityClass: me.Onu2GClassID,
99 EntityInstance: 0, //there is only the 0 instance of ONU2-G (still hard-coded - TODO!!!)
100 },
101 AttributeMask: 0xE000, //example hardcoded (TODO!!!) request EquId, OmccVersion, VendorCode
102 }
103
104 oo.txSeqNo = tid
dbainbri4d3a0dc2020-12-02 00:33:42 +0000105 pkt, err := serialize(ctx, omci.GetRequestType, request, tid)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000106 if err != nil {
107 //omciLogger.WithFields(log.Fields{ ...
dbainbri4d3a0dc2020-12-02 00:33:42 +0000108 logger.Errorw(ctx, "Cannot serialize Onu2-G GetRequest", log.Fields{"device-id": oo.deviceID, "Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000109 return nil, err
110 }
111 // hexEncode would probably work as well, but not needed and leads to wrong logs on OltAdapter frame
112 // return hexEncode(pkt)
113 return pkt, nil
114}
115
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000116//supply a response handler - in this testobject the message is evaluated directly, no response channel used
dbainbri4d3a0dc2020-12-02 00:33:42 +0000117func (oo *omciTestRequest) receiveOmciVerifyResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000118
dbainbri4d3a0dc2020-12-02 00:33:42 +0000119 logger.Debugw(ctx, "verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000120 "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier})
121
122 if omciMsg.TransactionID == oo.txSeqNo {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000123 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000124 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000125 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000126 "expected": oo.txSeqNo})
127 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200128 return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000129 }
130 if omciMsg.MessageType == omci.GetResponseType {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000131 logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000132 } else {
dbainbri4d3a0dc2020-12-02 00:33:42 +0000133 logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000134 "expected": omci.GetResponseType})
135 oo.verifyDone <- false
Andrea Campanella6515c582020-10-05 11:25:00 +0200136 return fmt.Errorf("unexpected MessageType %s", oo.deviceID)
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000137 }
138
139 //TODO!!! further tests on the payload should be done here ...
140
141 oo.result = true
142 oo.verifyDone <- true
143
144 return nil
145}