blob: 501bdea9eacd244844b117d5f49d13d40d4ab095 [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
21 "github.com/opencord/voltha-lib-go/v7/pkg/log"
22 "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:
50 if logger.V(log.DebugLevel) {
51 logger.Debug(ctx, "streamPacketOut Receive PacketOut from Channel")
52 }
53 if err := outClient.Send(ofPacketOut); err != nil {
54 logger.Errorw(ctx, "packet-out-send-error",
55 log.Fields{"error": err.Error()})
56 break top
57 }
58 logger.Debug(ctx, "packet-out-send")
59 }
60 }
61}