blob: 859dd9c1e46bcb370ef419c1b117e449b5558dfb [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"
22 "errors"
23
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
31 //"github.com/opencord/voltha-lib-go/v3/pkg/kafka"
32 "github.com/opencord/voltha-lib-go/v3/pkg/log"
33 //ic "github.com/opencord/voltha-protos/v3/go/inter_container"
34 //"github.com/opencord/voltha-protos/v3/go/openflow_13"
35 //"github.com/opencord/voltha-protos/v3/go/voltha"
36)
37
38//OmciTestRequest structure holds the information for the OMCI test
39type OmciTestRequest struct {
40 deviceID string
41 pDevOmciCC *OmciCC
42 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
50//NewOmciTestRequest returns a new instance of OmciTestRequest
51func NewOmciTestRequest(ctx context.Context,
Himani Chawla4d908332020-08-31 12:30:20 +053052 deviceID string, omciCc *OmciCC,
53 exclusive bool, allowFailure bool) *OmciTestRequest {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000054 logger.Debug("omciTestRequest-init")
Holger Hildebrandtfa074992020-03-27 15:42:06 +000055 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 Chawla4d908332020-08-31 12:30:20 +053067func (oo *OmciTestRequest) PerformOmciTest(ctx context.Context, execChannel chan<- bool) {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +000068 logger.Debug("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 ??)
74 tid := oo.pDevOmciCC.GetNextTid(false)
75 onu2gBaseGet, _ := oo.CreateOnu2gBaseGet(tid)
Holger Hildebrandtccd390c2020-05-29 13:49:04 +000076 omciRxCallbackPair := CallbackPair{
77 cbKey: tid,
78 cbEntry: CallbackPairEntry{nil, oo.ReceiveOmciVerifyResponse},
79 }
Holger Hildebrandtfa074992020-03-27 15:42:06 +000080
divyadesai4d299552020-08-18 07:13:49 +000081 logger.Debugw("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
83 go oo.pDevOmciCC.Send(ctx, onu2gBaseGet, ConstDefaultOmciTimeout, 0, false, omciRxCallbackPair)
84
85 } else {
divyadesai4d299552020-08-18 07:13:49 +000086 logger.Errorw("performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +000087 }
88}
89
90// these are OMCI related functions, could/should be collected in a separate file? TODO!!!
91// for a simple start just included in here
92//basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go
93func (oo *OmciTestRequest) CreateOnu2gBaseGet(tid uint16) ([]byte, error) {
94
95 request := &omci.GetRequest{
96 MeBasePacket: omci.MeBasePacket{
97 EntityClass: me.Onu2GClassID,
98 EntityInstance: 0, //there is only the 0 instance of ONU2-G (still hard-coded - TODO!!!)
99 },
100 AttributeMask: 0xE000, //example hardcoded (TODO!!!) request EquId, OmccVersion, VendorCode
101 }
102
103 oo.txSeqNo = tid
104 pkt, err := serialize(omci.GetRequestType, request, tid)
105 if err != nil {
106 //omciLogger.WithFields(log.Fields{ ...
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000107 logger.Errorw("Cannot serialize Onu2-G GetRequest", log.Fields{"Err": err})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000108 return nil, err
109 }
110 // hexEncode would probably work as well, but not needed and leads to wrong logs on OltAdapter frame
111 // return hexEncode(pkt)
112 return pkt, nil
113}
114
Holger Hildebrandtccd390c2020-05-29 13:49:04 +0000115//supply a response handler - in this testobject the message is evaluated directly, no response channel used
116func (oo *OmciTestRequest) ReceiveOmciVerifyResponse(omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error {
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000117
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000118 logger.Debugw("verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000119 "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier})
120
121 if omciMsg.TransactionID == oo.txSeqNo {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000122 logger.Debugw("verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000123 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000124 logger.Debugw("verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000125 "expected": oo.txSeqNo})
126 oo.verifyDone <- false
Himani Chawla4d908332020-08-31 12:30:20 +0530127 return errors.New("unexpected TransCorrId")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000128 }
129 if omciMsg.MessageType == omci.GetResponseType {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000130 logger.Debugw("verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType})
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000131 } else {
Holger Hildebrandt0f9b88d2020-04-20 13:33:25 +0000132 logger.Debugw("verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType,
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000133 "expected": omci.GetResponseType})
134 oo.verifyDone <- false
Himani Chawla4d908332020-08-31 12:30:20 +0530135 return errors.New("unexpected MessageType")
Holger Hildebrandtfa074992020-03-27 15:42:06 +0000136 }
137
138 //TODO!!! further tests on the payload should be done here ...
139
140 oo.result = true
141 oo.verifyDone <- true
142
143 return nil
144}