Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package vpagent |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 21 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 22 | "google.golang.org/grpc" |
| 23 | ) |
| 24 | |
| 25 | func (vpa *VPAgent) streamPacketOut(ctx context.Context) { |
| 26 | logger.Debug(ctx, "packet-out-started") |
| 27 | // If we exit, assume disconnected |
| 28 | defer func() { |
| 29 | vpa.events <- vpaEventVolthaDisconnected |
| 30 | logger.Debug(ctx, "packet-out-finished") |
| 31 | }() |
| 32 | if vpa.volthaClient == nil { |
| 33 | logger.Error(ctx, "no-voltha-connection") |
| 34 | return |
| 35 | } |
| 36 | opt := grpc.EmptyCallOption{} |
| 37 | streamCtx, streamDone := context.WithCancel(context.Background()) |
| 38 | outClient, err := vpa.volthaClient.Get().StreamPacketsOut(streamCtx, opt) |
| 39 | defer streamDone() |
| 40 | if err != nil { |
| 41 | logger.Errorw(ctx, "streamPacketOut Error creating packetout stream ", log.Fields{"error": err}) |
| 42 | return |
| 43 | } |
| 44 | top: |
| 45 | for { |
| 46 | select { |
| 47 | case <-ctx.Done(): |
| 48 | break top |
| 49 | case ofPacketOut := <-vpa.packetOutChannel: |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 50 | logger.Debug(ctx, "streamPacketOut Receive PacketOut from Channel") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 51 | if err := outClient.Send(ofPacketOut); err != nil { |
| 52 | logger.Errorw(ctx, "packet-out-send-error", |
| 53 | log.Fields{"error": err.Error()}) |
| 54 | break top |
| 55 | } |
| 56 | logger.Debug(ctx, "packet-out-send") |
| 57 | } |
| 58 | } |
| 59 | } |