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 ( |
| 20 | "encoding/json" |
| 21 | ofp "github.com/donNewtonAlpha/goloxi/of13" |
David K. Bainbridge | aea73cd | 2020-01-27 10:44:50 -0800 | [diff] [blame] | 22 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 23 | "github.com/opencord/voltha-protos/v3/go/voltha" |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
Jonathan Hart | 4b110f6 | 2020-03-13 17:36:19 -0700 | [diff] [blame] | 26 | func (ofc *OFConnection) handlePacketOut(packetOut *ofp.PacketOut) { |
David K. Bainbridge | 157bdab | 2020-01-16 14:38:05 -0800 | [diff] [blame] | 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 | } |