Takahiro Suzuki | 241c10e | 2020-12-17 20:17:57 +0900 | [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 | package adaptercoreonu |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/json" |
| 21 | |
| 22 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 23 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 24 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 25 | ) |
| 26 | |
| 27 | //AdditionalMessage ... |
| 28 | type AdditionalMessage struct { |
| 29 | } |
| 30 | |
| 31 | /* |
| 32 | func (dh *deviceHandler) receivedMsgFromOlt(msg *ic.InterAdapterMessage) error { |
| 33 | msgBody := msg.GetBody() |
| 34 | ind := &oop.OnuIndication{} |
| 35 | |
| 36 | err := ptypes.UnmarshalAny(msgBody, ind) |
| 37 | if err != nil { |
| 38 | logger.Debugw("cannot-unmarshal-onu-indication-body", log.Fields{"error": err}) |
| 39 | } else { |
| 40 | var info AdditionalMessage |
| 41 | err = json.Unmarshal(ind.SerialNumber.VendorSpecific, &info) |
| 42 | if err != nil { |
| 43 | logger.Debugw("cannot-unmarshal-additional-message", log.Fields{"error": err}) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return err |
| 48 | } |
| 49 | */ |
| 50 | func (dh *deviceHandler) sendMsgToOlt(ctx context.Context, msg string, option interface{}) error { |
| 51 | bytes, _ := json.Marshal(option) |
| 52 | info := oop.OnuIndication{ |
| 53 | SerialNumber: &oop.SerialNumber{ |
| 54 | VendorSpecific: bytes, |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | err := dh.AdapterProxy.SendInterAdapterMessage(ctx, &info, |
| 59 | ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 60 | dh.DeviceType, dh.ProxyAddressType, |
| 61 | dh.deviceID, dh.parentID, msg) |
| 62 | |
| 63 | if err != nil { |
| 64 | logger.Debugw("err-sending-message", log.Fields{"device": dh}) |
| 65 | } |
| 66 | return err |
| 67 | } |