blob: b01579ea7a7e0a2171cbfca200515e38daab94e9 [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"
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +000022
Jonathan Hart828908c2020-04-15 14:23:45 -070023 ofp "github.com/opencord/goloxi/of13"
David K. Bainbridgee05cf0c2021-08-19 03:16:50 +000024 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoofcf0b8d2021-10-19 17:57:30 -040025 "github.com/opencord/voltha-protos/v5/go/openflow_13"
David K. Bainbridge157bdab2020-01-16 14:38:05 -080026)
27
Rohan Agrawalc32d9932020-06-15 11:01:47 +000028func (ofc *OFConnection) handlePacketOut(ctx context.Context, packetOut *ofp.PacketOut) {
Girish Kumar01e0c632020-08-10 16:48:56 +000029 span, ctx := log.CreateChildSpan(ctx, "openflow-packet-out")
30 defer span.Finish()
31
David K. Bainbridge157bdab2020-01-16 14:38:05 -080032 if logger.V(log.DebugLevel) {
33 js, _ := json.Marshal(packetOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000034 logger.Debugw(ctx, "handlePacketOut called",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080035 log.Fields{
36 "device-id": ofc.DeviceID,
37 "packet-out": js})
38 }
39
40 // Collection actions
khenaidoofcf0b8d2021-10-19 17:57:30 -040041 var actions []*openflow_13.OfpAction
David K. Bainbridge157bdab2020-01-16 14:38:05 -080042 for _, action := range packetOut.GetActions() {
43 actions = append(actions, extractAction(action))
44 }
45
46 // Build packet out
khenaidoofcf0b8d2021-10-19 17:57:30 -040047 pbPacketOut := openflow_13.PacketOut{
David K. Bainbridge157bdab2020-01-16 14:38:05 -080048 Id: ofc.DeviceID,
khenaidoofcf0b8d2021-10-19 17:57:30 -040049 PacketOut: &openflow_13.OfpPacketOut{
David K. Bainbridge157bdab2020-01-16 14:38:05 -080050 BufferId: packetOut.GetBufferId(),
51 InPort: uint32(packetOut.GetInPort()),
52 Actions: actions,
53 Data: packetOut.GetData(),
54 },
55 }
56
57 if logger.V(log.DebugLevel) {
58 js, _ := json.Marshal(pbPacketOut)
Rohan Agrawalc32d9932020-06-15 11:01:47 +000059 logger.Debugw(ctx, "handlePacketOut sending",
David K. Bainbridge157bdab2020-01-16 14:38:05 -080060 log.Fields{
61 "device-id": ofc.DeviceID,
62 "packet-out": js})
63 }
64
65 // Queue it
66 ofc.PacketOutChannel <- &pbPacketOut
67}