David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package openflow |
| 18 | |
| 19 | import ( |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 20 | "context" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 21 | "encoding/json" |
David K. Bainbridge | e05cf0c | 2021-08-19 03:16:50 +0000 | [diff] [blame] | 22 | |
Jonathan Hart | 828908c | 2020-04-15 14:23:45 -0700 | [diff] [blame] | 23 | ofp "github.com/opencord/goloxi/of13" |
David K. Bainbridge | e05cf0c | 2021-08-19 03:16:50 +0000 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | fcf0b8d | 2021-10-19 17:57:30 -0400 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 28 | func (ofc *OFConnection) handlePacketOut(ctx context.Context, packetOut *ofp.PacketOut) { |
Girish Kumar | 01e0c63 | 2020-08-10 16:48:56 +0000 | [diff] [blame] | 29 | span, ctx := log.CreateChildSpan(ctx, "openflow-packet-out") |
| 30 | defer span.Finish() |
| 31 | |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 32 | if logger.V(log.DebugLevel) { |
| 33 | js, _ := json.Marshal(packetOut) |
Rohan Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 34 | logger.Debugw(ctx, "handlePacketOut called", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 35 | log.Fields{ |
| 36 | "device-id": ofc.DeviceID, |
| 37 | "packet-out": js}) |
| 38 | } |
| 39 | |
| 40 | // Collection actions |
khenaidoo | fcf0b8d | 2021-10-19 17:57:30 -0400 | [diff] [blame] | 41 | var actions []*openflow_13.OfpAction |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 42 | for _, action := range packetOut.GetActions() { |
| 43 | actions = append(actions, extractAction(action)) |
| 44 | } |
| 45 | |
| 46 | // Build packet out |
khenaidoo | fcf0b8d | 2021-10-19 17:57:30 -0400 | [diff] [blame] | 47 | pbPacketOut := openflow_13.PacketOut{ |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 48 | Id: ofc.DeviceID, |
khenaidoo | fcf0b8d | 2021-10-19 17:57:30 -0400 | [diff] [blame] | 49 | PacketOut: &openflow_13.OfpPacketOut{ |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 50 | 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 Agrawal | c32d993 | 2020-06-15 11:01:47 +0000 | [diff] [blame] | 59 | logger.Debugw(ctx, "handlePacketOut sending", |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 60 | log.Fields{ |
| 61 | "device-id": ofc.DeviceID, |
| 62 | "packet-out": js}) |
| 63 | } |
| 64 | |
| 65 | // Queue it |
| 66 | ofc.PacketOutChannel <- &pbPacketOut |
| 67 | } |