blob: ac9fa8b7d9e92767f0c01056ce2a3080e02099dd [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"
Naveen Sampath04696f72022-06-13 15:19:14 +053022 "google.golang.org/grpc"
23)
24
25func (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 }
44top:
45 for {
46 select {
47 case <-ctx.Done():
48 break top
49 case ofPacketOut := <-vpa.packetOutChannel:
Tinoj Joseph1d108322022-07-13 10:07:39 +053050 logger.Debug(ctx, "streamPacketOut Receive PacketOut from Channel")
Naveen Sampath04696f72022-06-13 15:19:14 +053051 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}