blob: 622ff0d90c7d6bbbda99046b59c6dcdaf1742ef2 [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 openflow
18
19import (
20 "encoding/json"
21 ofp "github.com/donNewtonAlpha/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080022 "github.com/opencord/voltha-lib-go/v3/pkg/log"
23 "github.com/opencord/voltha-protos/v3/go/voltha"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080024)
25
26func (ofc *OFClient) handlePacketOut(packetOut *ofp.PacketOut) {
27 if logger.V(log.DebugLevel) {
28 js, _ := json.Marshal(packetOut)
29 logger.Debugw("handlePacketOut called",
30 log.Fields{
31 "device-id": ofc.DeviceID,
32 "packet-out": js})
33 }
34
35 // Collection actions
36 var actions []*voltha.OfpAction
37 for _, action := range packetOut.GetActions() {
38 actions = append(actions, extractAction(action))
39 }
40
41 // Build packet out
42 pbPacketOut := voltha.PacketOut{
43 Id: ofc.DeviceID,
44 PacketOut: &voltha.OfpPacketOut{
45 BufferId: packetOut.GetBufferId(),
46 InPort: uint32(packetOut.GetInPort()),
47 Actions: actions,
48 Data: packetOut.GetData(),
49 },
50 }
51
52 if logger.V(log.DebugLevel) {
53 js, _ := json.Marshal(pbPacketOut)
54 logger.Debugw("handlePacketOut sending",
55 log.Fields{
56 "device-id": ofc.DeviceID,
57 "packet-out": js})
58 }
59
60 // Queue it
61 ofc.PacketOutChannel <- &pbPacketOut
62}