interim commit go fmt stuff
Change-Id: I617a7d771b50c2b7999eabbbebbabef4e68d8713
diff --git a/grpc/changeEvent.go b/grpc/changeEvent.go
index 275700d..ace6bc7 100644
--- a/grpc/changeEvent.go
+++ b/grpc/changeEvent.go
@@ -19,10 +19,10 @@
import (
"context"
"encoding/json"
+ ofp "github.com/donNewtonAlpha/goloxi/of13"
"github.com/golang/protobuf/ptypes/empty"
"github.com/opencord/ofagent-go/openflow"
pb "github.com/opencord/voltha-protos/go/voltha"
- ofp "github.com/skydive-project/goloxi/of13"
"google.golang.org/grpc"
"log"
"net"
@@ -50,7 +50,6 @@
log.Printf("Received change event that was not port status %v", jsonMessage)
break
}
- log.Println("???????????????????????????????????????????????????????????????????")
ofPortStatus := ofp.NewPortStatus()
ofPortStatus.SetXid(openflow.GetXid())
ofPortStatus.SetVersion(4)
diff --git a/grpc/client.go b/grpc/client.go
index acb2304..ea32986 100644
--- a/grpc/client.go
+++ b/grpc/client.go
@@ -99,3 +99,6 @@
clientMap[deviceId] = client
return client
}
+func GetClient(deviceId string) *openflow.Client {
+ return clientMap[deviceId]
+}
diff --git a/grpc/packetIn.go b/grpc/packetIn.go
index 938dabe..8200a37 100644
--- a/grpc/packetIn.go
+++ b/grpc/packetIn.go
@@ -18,10 +18,12 @@
import (
"context"
+ "github.com/donNewtonAlpha/goloxi"
+ ofp "github.com/donNewtonAlpha/goloxi/of13"
"github.com/golang/protobuf/ptypes/empty"
"github.com/opencord/ofagent-go/openflow"
+ "github.com/opencord/voltha-protos/go/openflow_13"
pb "github.com/opencord/voltha-protos/go/voltha"
- ofp "github.com/skydive-project/goloxi/of13"
"google.golang.org/grpc"
"log"
)
@@ -39,33 +41,89 @@
if err != nil {
log.Fatalf("error on stream.Rec %v", err)
}
+ deviceID := packet.GetId()
ofPacketIn := ofp.NewPacketIn()
ofPacketIn.SetVersion(uint8(4))
ofPacketIn.SetXid(openflow.GetXid())
ofPacketIn.SetBufferId(packetIn.GetBufferId())
ofPacketIn.SetCookie(packetIn.GetCookie())
ofPacketIn.SetData(packetIn.GetData())
- var outMatch ofp.Match
+ match := ofp.NewMatchV3()
inMatch := packetIn.GetMatch()
- outMatch.SetType(uint16(inMatch.GetType()))
- /*
- TODO not sure if anything further is needed
- fields := inMatch.GetOxmFields()
- var outFields []ofp.Oxm
- for i:=0;i< len(fields);i++{
- field := fields[i]
- outField := ofp.Oxm{}
- outField.SetTypeLen(field.OxmClass.)
- outField.SetTypeLen(field)
- }
- outMatch.SetOxmList(inMatch.GetOxmFields())
- */
+ match.SetType(uint16(inMatch.GetType()))
+ oxFields := inMatch.GetOxmFields()
+ var fields []goloxi.IOxm
+ var size uint16
+ size = 4
+ for i := 0; i < len(oxFields); i++ {
+ oxmField := oxFields[i]
+ field := oxmField.GetField()
+ ofbField := field.(*openflow_13.OfpOxmField_OfbField).OfbField
+ size += 4 //header for oxm
+ switch ofbField.Type {
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_IN_PORT:
+ ofpInPort := ofp.NewOxmInPort()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_Port)
+ ofpInPort.Value = ofp.Port(val.Port)
+ size += 4
+ fields = append(fields, ofpInPort)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_ETH_TYPE:
+ ofpEthType := ofp.NewOxmEthType()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_EthType)
+ ofpEthType.Value = ofp.EthernetType(val.EthType)
+ size += 2
+ fields = append(fields, ofpEthType)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_IN_PHY_PORT:
+ ofpInPhyPort := ofp.NewOxmInPhyPort()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_PhysicalPort)
+ ofpInPhyPort.Value = ofp.Port(val.PhysicalPort)
+ size += 4
+ fields = append(fields, ofpInPhyPort)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_IP_PROTO:
+ ofpIpProto := ofp.NewOxmIpProto()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_IpProto)
+ ofpIpProto.Value = ofp.IpPrototype(val.IpProto)
+ size += 1
+ fields = append(fields, ofpIpProto)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_UDP_SRC:
+ ofpUdpSrc := ofp.NewOxmUdpSrc()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_UdpSrc)
+ ofpUdpSrc.Value = uint16(val.UdpSrc)
+ size += 2
+ fields = append(fields, ofpUdpSrc)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_UDP_DST:
+ ofpUdpDst := ofp.NewOxmUdpDst()
+ val := ofbField.GetValue().(*openflow_13.OfpOxmOfbField_UdpDst)
+ ofpUdpDst.Value = uint16(val.UdpDst)
+ size += 2
+ fields = append(fields, ofpUdpDst)
+ case pb.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID:
+ ofpVlanVid := ofp.NewOxmVlanVid()
+ val := ofbField.GetValue()
+ if val != nil {
+ vlanId := val.(*openflow_13.OfpOxmOfbField_VlanVid)
+ ofpVlanVid.Value = uint16(vlanId.VlanVid) + 0x1000
+ size += 2
+ } else {
+ ofpVlanVid.Value = uint16(0)
+ }
- ofPacketIn.SetMatch(outMatch)
+ fields = append(fields, ofpVlanVid)
+ default:
+ log.Printf("handleFlowStatsRequest Unhandled OxmField %v", ofbField.Type)
+ }
+ }
+ match.SetLength(size)
+
+ match.SetOxmList(fields)
+
+ ofPacketIn.SetMatch(*match)
ofPacketIn.SetReason(uint8(packetIn.GetReason()))
ofPacketIn.SetTableId(uint8(packetIn.GetTableId()))
ofPacketIn.SetTotalLen(uint16(len(ofPacketIn.GetData())))
- //ofPacketIn.
+ openFlowClient := GetClient(deviceID)
+ openFlowClient.SendMessage(ofPacketIn)
+
}
}
diff --git a/grpc/packetOut.go b/grpc/packetOut.go
index 02920ae..ee58a31 100644
--- a/grpc/packetOut.go
+++ b/grpc/packetOut.go
@@ -17,6 +17,8 @@
package grpc
import (
+ "encoding/json"
+ "github.com/opencord/ofagent-go/openflow"
pb "github.com/opencord/voltha-protos/go/voltha"
"google.golang.org/grpc"
"log"
@@ -31,8 +33,11 @@
log.Printf("Error creating packetout stream %v", err)
}
packetOutChannel := make(chan pb.PacketOut)
+ openflow.SetPacketOutChannel(packetOutChannel)
for {
ofPacketOut := <-packetOutChannel
+ js, _ := json.Marshal(ofPacketOut)
+ log.Printf("RECEIVED PACKET OUT FROM CHANNEL %s", js)
outClient.Send(&ofPacketOut)
}