blob: dfbb0d94353751700ef5502dfe3d0aa66cfce46f [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) {
Girish Kumar01e0c632020-08-10 16:48:56 +000028 span, ctx := log.CreateChildSpan(ctx, "openflow-packet-out")
29 defer span.Finish()
30
David K. Bainbridge157bdab2020-01-16 14:38:05 -080031 if logger.V(log.DebugLevel) {
32 js, _ := json.Marshal(packetOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000033 logger.Debugw(ctx, "handlePacketOut called",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080034 log.Fields{
35 "device-id": ofc.DeviceID,
36 "packet-out": js})
37 }
38
39 // Collection actions
40 var actions []*voltha.OfpAction
41 for _, action := range packetOut.GetActions() {
42 actions = append(actions, extractAction(action))
43 }
44
45 // Build packet out
46 pbPacketOut := voltha.PacketOut{
47 Id: ofc.DeviceID,
48 PacketOut: &voltha.OfpPacketOut{
49 BufferId: packetOut.GetBufferId(),
50 InPort: uint32(packetOut.GetInPort()),
51 Actions: actions,
52 Data: packetOut.GetData(),
53 },
54 }
55
56 if logger.V(log.DebugLevel) {
57 js, _ := json.Marshal(pbPacketOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000058 logger.Debugw(ctx, "handlePacketOut sending",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080059 log.Fields{
60 "device-id": ofc.DeviceID,
61 "packet-out": js})
62 }
63
64 // Queue it
65 ofc.PacketOutChannel <- &pbPacketOut
66}