Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2017 the original author or authors. |
| 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 | |
| 17 | package grpc |
| 18 | |
| 19 | import ( |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 20 | "context" |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 21 | "encoding/json" |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 22 | |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 23 | "github.com/opencord/ofagent-go/openflow" |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 24 | "github.com/opencord/ofagent-go/settings" |
| 25 | l "github.com/opencord/voltha-lib-go/v2/pkg/log" |
Don Newton | b437c6f | 2019-12-18 11:51:57 -0500 | [diff] [blame] | 26 | pb "github.com/opencord/voltha-protos/v2/go/voltha" |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 27 | "google.golang.org/grpc" |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 28 | ) |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 29 | |
| 30 | func streamPacketOut(client pb.VolthaServiceClient) { |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 31 | if settings.GetDebug(grpcDeviceID) { |
| 32 | logger.Debugln("GrpcClient streamPacketOut called") |
| 33 | } |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 34 | opt := grpc.EmptyCallOption{} |
| 35 | outClient, err := client.StreamPacketsOut(context.Background(), opt) |
| 36 | if err != nil { |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 37 | logger.Fatalw("streamPacketOut Error creating packetout stream ", l.Fields{"Error": err}) |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 38 | } |
| 39 | packetOutChannel := make(chan pb.PacketOut) |
Don Newton | e0d34a8 | 2019-11-14 10:58:06 -0500 | [diff] [blame] | 40 | openflow.SetPacketOutChannel(packetOutChannel) |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 41 | for { |
| 42 | ofPacketOut := <-packetOutChannel |
Don Newton | 7577f07 | 2020-01-06 12:41:11 -0500 | [diff] [blame^] | 43 | if settings.GetDebug(grpcDeviceID) { |
| 44 | js, _ := json.Marshal(ofPacketOut) |
| 45 | logger.Debugw("streamPacketOut Receive PacketOut from Channel", l.Fields{"PacketOut": js}) |
| 46 | } |
Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame] | 47 | outClient.Send(&ofPacketOut) |
| 48 | } |
| 49 | |
| 50 | } |