Takahiro Suzuki | d7bf820 | 2020-12-17 20:21:59 +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 core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/json" |
| 21 | |
| 22 | "github.com/golang/protobuf/ptypes" |
| 23 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 24 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 25 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 26 | ) |
| 27 | |
| 28 | // AdditionalMessage is used for something... |
| 29 | type AdditionalMessage struct { |
| 30 | } |
| 31 | |
| 32 | func (dh *DeviceHandler) receivedMsgFromOnu(ctx context.Context, 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(ctx, "cannot-unmarshal-onu-indication-body", log.Fields{"error": err}) |
| 39 | return err |
| 40 | } |
| 41 | |
| 42 | var info AdditionalMessage |
| 43 | err = json.Unmarshal(ind.SerialNumber.VendorSpecific, &info) |
| 44 | if err != nil { |
| 45 | logger.Debugw(ctx, "cannot-unmarshal-additional-message", log.Fields{"error": err}) |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | onuDevice := FindL2oamDeviceByDeviceID(msg.Header.ToDeviceId) |
| 50 | if onuDevice == nil { |
| 51 | logger.Error(ctx, "receivedMsgFromOnu() OnuDevice is not found. deviceId=%s", msg.Header.ToDeviceId) |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | id := msg.Header.Id |
| 56 | switch id { |
| 57 | case "reboot": |
| 58 | onuDevice.reboot(ctx) |
| 59 | case "disable": |
| 60 | logger.Warn(ctx, "unsupported message, Id=%s", id) |
| 61 | case "reenable": |
| 62 | logger.Warn(ctx, "unsupported message, Id=%s", id) |
| 63 | } |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | func (dh *DeviceHandler) sendMsgToOnu(ctx context.Context, deviceID string, topic string, msg string, option interface{}) error { |
| 69 | bytes, _ := json.Marshal(option) |
| 70 | info := oop.OnuIndication{ |
| 71 | SerialNumber: &oop.SerialNumber{ |
| 72 | VendorSpecific: bytes, |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | err := dh.AdapterProxy.SendInterAdapterMessage(ctx, &info, |
| 77 | ic.InterAdapterMessageType_ONU_IND_REQUEST, |
| 78 | dh.device.Type, topic, |
| 79 | deviceID, dh.device.Id, msg) |
| 80 | |
| 81 | if err != nil { |
| 82 | logger.Debugw(ctx, "err-sending-message", log.Fields{"device-id": deviceID, "topic": topic, "error": err}) |
| 83 | } |
| 84 | return err |
| 85 | } |
| 86 | */ |