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" |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 22 | "fmt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 23 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 24 | gp "github.com/google/gopacket" |
| 25 | "github.com/opencord/omci-lib-go" |
| 26 | me "github.com/opencord/omci-lib-go/generated" |
| 27 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 28 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 29 | ) |
| 30 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 31 | //omciTestRequest structure holds the information for the OMCI test |
| 32 | type omciTestRequest struct { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 33 | deviceID string |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 34 | pDevOmciCC *omciCC |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 35 | started bool |
| 36 | result bool |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 37 | exclusiveCc bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 38 | allowFailure bool |
| 39 | txSeqNo uint16 |
| 40 | verifyDone chan<- bool |
| 41 | } |
| 42 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 43 | //newOmciTestRequest returns a new instance of OmciTestRequest |
| 44 | func newOmciTestRequest(ctx context.Context, |
| 45 | deviceID string, omciCc *omciCC, |
| 46 | exclusive bool, allowFailure bool) *omciTestRequest { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 47 | logger.Debug(ctx, "omciTestRequest-init") |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 48 | var omciTestRequest omciTestRequest |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 49 | omciTestRequest.deviceID = deviceID |
| 50 | omciTestRequest.pDevOmciCC = omciCc |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 51 | omciTestRequest.started = false |
| 52 | omciTestRequest.result = false |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 53 | omciTestRequest.exclusiveCc = exclusive |
| 54 | omciTestRequest.allowFailure = allowFailure |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 55 | |
| 56 | return &omciTestRequest |
| 57 | } |
| 58 | |
| 59 | // |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 60 | func (oo *omciTestRequest) performOmciTest(ctx context.Context, execChannel chan<- bool) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 61 | logger.Debug(ctx, "omciTestRequest-start-test") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 62 | |
| 63 | if oo.pDevOmciCC != nil { |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 64 | oo.verifyDone = execChannel |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 65 | // 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 Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 67 | tid := oo.pDevOmciCC.getNextTid(false) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 68 | onu2gBaseGet, _ := oo.createOnu2gBaseGet(ctx, tid) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 69 | omciRxCallbackPair := callbackPair{ |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 70 | cbKey: tid, |
mpagenko | 80622a5 | 2021-02-09 16:53:23 +0000 | [diff] [blame] | 71 | cbEntry: callbackPairEntry{nil, oo.receiveOmciVerifyResponse, true}, |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 72 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 73 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 74 | logger.Debugw(ctx, "performOmciTest-start sending frame", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 75 | // send with default timeout and normal prio |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 76 | // Note: No reference to fetch the OMCI timeout value from configuration, so hardcode it to 10s |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 77 | go oo.pDevOmciCC.send(ctx, onu2gBaseGet, 10, cDefaultRetries, false, omciRxCallbackPair) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 78 | |
| 79 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 80 | logger.Errorw(ctx, "performOmciTest: Device does not exist", log.Fields{"for device-id": oo.deviceID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 81 | } |
| 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 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 87 | func (oo *omciTestRequest) createOnu2gBaseGet(ctx context.Context, tid uint16) ([]byte, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 88 | |
| 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 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 98 | pkt, err := serialize(ctx, omci.GetRequestType, request, tid) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 99 | if err != nil { |
| 100 | //omciLogger.WithFields(log.Fields{ ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 101 | logger.Errorw(ctx, "Cannot serialize Onu2-G GetRequest", log.Fields{"device-id": oo.deviceID, "Err": err}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 102 | 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 Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 109 | //supply a response handler - in this testobject the message is evaluated directly, no response channel used |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 110 | func (oo *omciTestRequest) receiveOmciVerifyResponse(ctx context.Context, omciMsg *omci.OMCI, packet *gp.Packet, respChan chan Message) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 111 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 112 | logger.Debugw(ctx, "verify-omci-message-response received:", log.Fields{"omciMsgType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 113 | "transCorrId": omciMsg.TransactionID, "DeviceIdent": omciMsg.DeviceIdentifier}) |
| 114 | |
| 115 | if omciMsg.TransactionID == oo.txSeqNo { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 116 | logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct TransCorrId": omciMsg.TransactionID}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 117 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 118 | logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect TransCorrId": omciMsg.TransactionID, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 119 | "expected": oo.txSeqNo}) |
| 120 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 121 | return fmt.Errorf("unexpected TransCorrId %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | } |
| 123 | if omciMsg.MessageType == omci.GetResponseType { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 124 | logger.Debugw(ctx, "verify-omci-message-response", log.Fields{"correct RespType": omciMsg.MessageType}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 125 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 126 | logger.Debugw(ctx, "verify-omci-message-response error", log.Fields{"incorrect RespType": omciMsg.MessageType, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 127 | "expected": omci.GetResponseType}) |
| 128 | oo.verifyDone <- false |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 129 | return fmt.Errorf("unexpected MessageType %s", oo.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | //TODO!!! further tests on the payload should be done here ... |
| 133 | |
Holger Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 134 | oo.pDevOmciCC.mutexMonReq.RLock() |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 135 | 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 Hildebrandt | 0da7e6f | 2021-05-12 13:08:43 +0000 | [diff] [blame] | 141 | oo.pDevOmciCC.mutexMonReq.RUnlock() |
Holger Hildebrandt | 366ef19 | 2021-05-05 11:07:44 +0000 | [diff] [blame] | 142 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 143 | oo.result = true |
| 144 | oo.verifyDone <- true |
| 145 | |
| 146 | return nil |
| 147 | } |