blob: 3a43335b6bb3722fd7fd8c593d446c3dd68c77d5 [file] [log] [blame]
David K. Bainbridge157bdab2020-01-16 14:38:05 -08001/*
2 Copyright 2020 the original author or authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17package ofagent
18
19import (
20 "context"
21 "encoding/json"
22 "github.com/opencord/voltha-lib-go/v2/pkg/log"
23 "google.golang.org/grpc"
24)
25
26func (ofa *OFAgent) streamPacketOut(ctx context.Context) {
27 if logger.V(log.DebugLevel) {
28 logger.Debug("GrpcClient streamPacketOut called")
29 }
30 opt := grpc.EmptyCallOption{}
31 streamCtx, streamDone := context.WithCancel(context.Background())
32 outClient, err := ofa.volthaClient.StreamPacketsOut(streamCtx, opt)
33 defer streamDone()
34 if err != nil {
35 logger.Errorw("streamPacketOut Error creating packetout stream ", log.Fields{"error": err})
36 ofa.events <- ofaEventVolthaDisconnected
37 }
38 for {
39 select {
40 case <-ctx.Done():
41 return
42 case ofPacketOut := <-ofa.packetOutChannel:
43 if logger.V(log.DebugLevel) {
44 js, _ := json.Marshal(ofPacketOut)
45 logger.Debugw("streamPacketOut Receive PacketOut from Channel", log.Fields{"PacketOut": js})
46 }
47 outClient.Send(ofPacketOut)
48 }
49 }
50}