blob: 00fbf5b2fc88f4af3339889896f9aafe559042ef [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301/*
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
16package vpagent
17
18import (
19 "context"
20
Tinoj Joseph1d108322022-07-13 10:07:39 +053021 "voltha-go-controller/log"
vinokuma926cb3e2023-03-29 11:41:06 +053022
Naveen Sampath04696f72022-06-13 15:19:14 +053023 "google.golang.org/grpc"
24)
25
26func (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 Soni6168f312023-05-18 20:57:33 +053034 logger.Fatal(ctx, "no-voltha-connection")
Naveen Sampath04696f72022-06-13 15:19:14 +053035 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 }
45top:
46 for {
47 select {
48 case <-ctx.Done():
49 break top
50 case ofPacketOut := <-vpa.packetOutChannel:
Tinoj Joseph1d108322022-07-13 10:07:39 +053051 logger.Debug(ctx, "streamPacketOut Receive PacketOut from Channel")
Naveen Sampath04696f72022-06-13 15:19:14 +053052 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}