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" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 22 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 23 | "google.golang.org/grpc" |
| 24 | ) |
| 25 | |
| 26 | func (vpa *VPAgent) streamPacketOut(ctx context.Context) { |
| 27 | logger.Debug(ctx, "packet-out-started") |
| 28 | // If we exit, assume disconnected |
| 29 | defer func() { |
| 30 | vpa.events <- vpaEventVolthaDisconnected |
| 31 | logger.Debug(ctx, "packet-out-finished") |
| 32 | }() |
| 33 | if vpa.volthaClient == nil { |
Akash Soni | 6168f31 | 2023-05-18 20:57:33 +0530 | [diff] [blame] | 34 | logger.Fatal(ctx, "no-voltha-connection") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 35 | return |
| 36 | } |
| 37 | opt := grpc.EmptyCallOption{} |
| 38 | streamCtx, streamDone := context.WithCancel(context.Background()) |
| 39 | outClient, err := vpa.volthaClient.Get().StreamPacketsOut(streamCtx, opt) |
| 40 | defer streamDone() |
| 41 | if err != nil { |
| 42 | logger.Errorw(ctx, "streamPacketOut Error creating packetout stream ", log.Fields{"error": err}) |
| 43 | return |
| 44 | } |
| 45 | top: |
| 46 | for { |
| 47 | select { |
| 48 | case <-ctx.Done(): |
| 49 | break top |
| 50 | case ofPacketOut := <-vpa.packetOutChannel: |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 51 | logger.Debug(ctx, "streamPacketOut Receive PacketOut from Channel") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 52 | if err := outClient.Send(ofPacketOut); err != nil { |
| 53 | logger.Errorw(ctx, "packet-out-send-error", |
| 54 | log.Fields{"error": err.Error()}) |
| 55 | break top |
| 56 | } |
| 57 | logger.Debug(ctx, "packet-out-send") |
| 58 | } |
| 59 | } |
| 60 | } |