Don Newton | 98fd881 | 2019-09-23 15:15:02 -0400 | [diff] [blame^] | 1 | /* |
| 2 | Copyright 2017 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 grpc |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "github.com/golang/protobuf/ptypes/empty" |
| 22 | "github.com/opencord/ofagent-go/openflow" |
| 23 | pb "github.com/opencord/voltha-protos/go/voltha" |
| 24 | ofp "github.com/skydive-project/goloxi/of13" |
| 25 | "google.golang.org/grpc" |
| 26 | "log" |
| 27 | ) |
| 28 | |
| 29 | func receivePacketIn(client pb.VolthaServiceClient) { |
| 30 | opt := grpc.EmptyCallOption{} |
| 31 | stream, err := client.ReceivePacketsIn(context.Background(), &empty.Empty{}, opt) |
| 32 | if err != nil { |
| 33 | log.Fatalln("Unable to establish stream") |
| 34 | } |
| 35 | for { |
| 36 | packet, err := stream.Recv() |
| 37 | packetIn := packet.GetPacketIn() |
| 38 | |
| 39 | if err != nil { |
| 40 | log.Fatalf("error on stream.Rec %v", err) |
| 41 | } |
| 42 | ofPacketIn := ofp.NewPacketIn() |
| 43 | ofPacketIn.SetVersion(uint8(4)) |
| 44 | ofPacketIn.SetXid(openflow.GetXid()) |
| 45 | ofPacketIn.SetBufferId(packetIn.GetBufferId()) |
| 46 | ofPacketIn.SetCookie(packetIn.GetCookie()) |
| 47 | ofPacketIn.SetData(packetIn.GetData()) |
| 48 | var outMatch ofp.Match |
| 49 | inMatch := packetIn.GetMatch() |
| 50 | outMatch.SetType(uint16(inMatch.GetType())) |
| 51 | /* |
| 52 | TODO not sure if anything further is needed |
| 53 | fields := inMatch.GetOxmFields() |
| 54 | var outFields []ofp.Oxm |
| 55 | for i:=0;i< len(fields);i++{ |
| 56 | field := fields[i] |
| 57 | outField := ofp.Oxm{} |
| 58 | outField.SetTypeLen(field.OxmClass.) |
| 59 | outField.SetTypeLen(field) |
| 60 | } |
| 61 | outMatch.SetOxmList(inMatch.GetOxmFields()) |
| 62 | */ |
| 63 | |
| 64 | ofPacketIn.SetMatch(outMatch) |
| 65 | ofPacketIn.SetReason(uint8(packetIn.GetReason())) |
| 66 | ofPacketIn.SetTableId(uint8(packetIn.GetTableId())) |
| 67 | ofPacketIn.SetTotalLen(uint16(len(ofPacketIn.GetData()))) |
| 68 | //ofPacketIn. |
| 69 | } |
| 70 | |
| 71 | } |