blob: dcef5fc74ed4b5f40240223fad889cc73962df22 [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 (
Rohan Agrawalc32d9932020-06-15 11:01:47 +000020 "context"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080021 "encoding/json"
Jonathan Hart828908c2020-04-15 14:23:45 -070022 ofp "github.com/opencord/goloxi/of13"
David K. Bainbridgeaea73cd2020-01-27 10:44:50 -080023 "github.com/opencord/voltha-lib-go/v3/pkg/log"
24 "github.com/opencord/voltha-protos/v3/go/voltha"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080025)
26
Rohan Agrawalc32d9932020-06-15 11:01:47 +000027func (ofc *OFConnection) handlePacketOut(ctx context.Context, packetOut *ofp.PacketOut) {
David K. Bainbridge157bdab2020-01-16 14:38:05 -080028 if logger.V(log.DebugLevel) {
29 js, _ := json.Marshal(packetOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000030 logger.Debugw(ctx, "handlePacketOut called",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080031 log.Fields{
32 "device-id": ofc.DeviceID,
33 "packet-out": js})
34 }
35
36 // Collection actions
37 var actions []*voltha.OfpAction
38 for _, action := range packetOut.GetActions() {
39 actions = append(actions, extractAction(action))
40 }
41
42 // Build packet out
43 pbPacketOut := voltha.PacketOut{
44 Id: ofc.DeviceID,
45 PacketOut: &voltha.OfpPacketOut{
46 BufferId: packetOut.GetBufferId(),
47 InPort: uint32(packetOut.GetInPort()),
48 Actions: actions,
49 Data: packetOut.GetData(),
50 },
51 }
52
53 if logger.V(log.DebugLevel) {
54 js, _ := json.Marshal(pbPacketOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000055 logger.Debugw(ctx, "handlePacketOut sending",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080056 log.Fields{
57 "device-id": ofc.DeviceID,
58 "packet-out": js})
59 }
60
61 // Queue it
62 ofc.PacketOutChannel <- &pbPacketOut
63}