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 | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 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 |
| 39 | type OmciTestRequest struct { |
| 40 | deviceID string |
| 41 | pDevOmciCC *OmciCC |
| 42 | started bool |
| 43 | result bool |
| 44 | exclusive_cc bool |
| 45 | allowFailure bool |
| 46 | txSeqNo uint16 |
| 47 | verifyDone chan<- bool |
| 48 | } |
| 49 | |
| 50 | //NewOmciTestRequest returns a new instance of OmciTestRequest |
| 51 | func NewOmciTestRequest(ctx context.Context, |
| 52 | device_id string, omci_cc *OmciCC, |
| 53 | exclusive bool, allow_failure bool) *OmciTestRequest { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 54 | logger.Debug("omciTestRequest-init") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 55 | var omciTestRequest OmciTestRequest |
| 56 | omciTestRequest.deviceID = device_id |
| 57 | omciTestRequest.pDevOmciCC = omci_cc |
| 58 | omciTestRequest.started = false |
| 59 | omciTestRequest.result = false |
| 60 | omciTestRequest.exclusive_cc = exclusive |
| 61 | omciTestRequest.allowFailure = allow_failure |
| 62 | |
| 63 | return &omciTestRequest |
| 64 | } |
| 65 | |
| 66 | // |
| 67 | func (oo *OmciTestRequest) PerformOmciTest(ctx context.Context, exec_Channel chan<- bool) { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 68 | logger.Debug("omciTestRequest-start-test") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 69 | |
| 70 | if oo.pDevOmciCC != nil { |
| 71 | oo.verifyDone = exec_Channel |
| 72 | // 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) |
| 76 | omciRxCallbackPair := CallbackPair{tid, oo.ReceiveOmciVerifyResponse} |
| 77 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 78 | logger.Debugw("performOmciTest-start sending frame", log.Fields{"for deviceId": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 79 | // send with default timeout and normal prio |
| 80 | go oo.pDevOmciCC.Send(ctx, onu2gBaseGet, ConstDefaultOmciTimeout, 0, false, omciRxCallbackPair) |
| 81 | |
| 82 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 83 | logger.Errorw("performOmciTest: Device does not exist", log.Fields{"for deviceId": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | // these are OMCI related functions, could/should be collected in a separate file? TODO!!! |
| 88 | // for a simple start just included in here |
| 89 | //basic approach copied from bbsim, cmp /devices/onu.go and /internal/common/omci/mibpackets.go |
| 90 | func (oo *OmciTestRequest) CreateOnu2gBaseGet(tid uint16) ([]byte, error) { |
| 91 | |
| 92 | request := &omci.GetRequest{ |
| 93 | MeBasePacket: omci.MeBasePacket{ |
| 94 | EntityClass: me.Onu2GClassID, |
| 95 | EntityInstance: 0, //there is only the 0 instance of ONU2-G (still hard-coded - TODO!!!) |
| 96 | }, |
| 97 | AttributeMask: 0xE000, //example hardcoded (TODO!!!) request EquId, OmccVersion, VendorCode |
| 98 | } |
| 99 | |
| 100 | oo.txSeqNo = tid |
| 101 | pkt, err := serialize(omci.GetRequestType, request, tid) |
| 102 | if err != nil { |
| 103 | //omciLogger.WithFields(log.Fields{ ... |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 104 | logger.Errorw("Cannot serialize Onu2-G GetRequest", log.Fields{"Err": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 105 | return nil, err |
| 106 | } |
| 107 | // hexEncode would probably work as well, but not needed and leads to wrong logs on OltAdapter frame |
| 108 | // return hexEncode(pkt) |
| 109 | return pkt, nil |
| 110 | } |
| 111 | |
| 112 | //supply a response handler |
| 113 | func (oo *OmciTestRequest) ReceiveOmciVerifyResponse(omciMsg *omci.OMCI, packet *gp.Packet) error { |
| 114 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 115 | logger.Debugw("verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 116 | "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier}) |
| 117 | |
| 118 | if omciMsg.TransactionID == oo.txSeqNo { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 119 | logger.Debugw("verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 121 | logger.Debugw("verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | "expected": oo.txSeqNo}) |
| 123 | oo.verifyDone <- false |
| 124 | return errors.New("Unexpected TransCorrId") |
| 125 | } |
| 126 | if omciMsg.MessageType == omci.GetResponseType { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 127 | logger.Debugw("verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 128 | } else { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 129 | logger.Debugw("verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 130 | "expected": omci.GetResponseType}) |
| 131 | oo.verifyDone <- false |
| 132 | return errors.New("Unexpected MessageType") |
| 133 | } |
| 134 | |
| 135 | //TODO!!! further tests on the payload should be done here ... |
| 136 | |
| 137 | oo.result = true |
| 138 | oo.verifyDone <- true |
| 139 | |
| 140 | return nil |
| 141 | } |