Skip to content

Commit

Permalink
modify of13 to of15
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyingd committed May 11, 2022
1 parent 63d5008 commit 672cfb1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ require (
// explicit imports of gopkg.in/yaml.v2.
replace (
antrea.io/libOpenflow v0.6.2 => github.com/ashish-varma/libOpenflow v0.5.3-0.20220406070346-d753d6267491
antrea.io/ofnet v0.5.5 => github.com/ashish-varma/ofnet v0.2.5-0.20220408000302-c6bcd158d462
antrea.io/ofnet v0.5.7 => github.com/ashish-varma/ofnet v0.2.5-0.20220408000302-c6bcd158d462
github.com/googleapis/gnostic v0.5.5 => github.com/googleapis/gnostic v0.4.1
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
antrea.io/ofnet v0.5.7/go.mod h1:8TJVF6MLe9/gZ/KbhGUvULs9/TxssepEaYEe+o1SEgs=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/controller/networkpolicy/packetin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"time"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/openflow15"
"antrea.io/ofnet/ofctrl"
"github.com/vmware/go-ipfix/pkg/registry"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -94,7 +94,7 @@ func getMatch(matchers *ofctrl.Matchers, tableID uint8, disposition uint32) *ofc
}

// getInfoInReg unloads and returns data stored in the match field.
func getInfoInReg(regMatch *ofctrl.MatchField, rng *openflow13.NXRange) (uint32, error) {
func getInfoInReg(regMatch *ofctrl.MatchField, rng *openflow15.NXRange) (uint32, error) {
regValue, ok := regMatch.GetValue().(*ofctrl.NXRegister)
if !ok {
return 0, errors.New("register value cannot be retrieved")
Expand Down
12 changes: 6 additions & 6 deletions pkg/agent/multicast/mcast_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/openflow15"
"antrea.io/libOpenflow/protocol"
"antrea.io/libOpenflow/util"
"antrea.io/ofnet/ofctrl"
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestUpdateGroupMemberStatus(t *testing.T) {
iface: if1,
}
mctrl.addGroupMemberStatus(event)
mockOFClient.EXPECT().SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, uint32(openflow13.P_NORMAL), gomock.Any()).Times(len(queryVersions))
mockOFClient.EXPECT().SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, uint32(openflow15.P_NORMAL), gomock.Any()).Times(len(queryVersions))
for _, e := range []*mcastGroupEvent{
{group: mgroup, eType: groupJoin, time: event.time.Add(time.Second * 20), iface: if1},
{group: mgroup, eType: groupJoin, time: event.time.Add(time.Second * 40), iface: if1},
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCheckLastMember(t *testing.T) {
}
_ = mctrl.groupCache.Add(status)
mctrl.addInstalledGroup(status.group.String())
mockOFClient.EXPECT().SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, uint32(openflow13.P_NORMAL), gomock.Any()).AnyTimes()
mockOFClient.EXPECT().SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, uint32(openflow15.P_NORMAL), gomock.Any()).AnyTimes()
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down Expand Up @@ -392,8 +392,8 @@ func createIGMPReportPacketIn(joinedGroups []net.IP, leftGroups []net.IP, versio
joinMessages := createIGMPJoinMessage(joinedGroups, version)
leaveMessages := createIGMPLeaveMessage(leftGroups, version)
generatePacket := func(m util.Message) ofctrl.PacketIn {
pkt := openflow13.NewPacketIn()
matchInport := openflow13.NewInPortField(ofport)
pkt := openflow15.NewPacketIn()
matchInport := openflow15.NewInPortField(ofport)
pkt.Match.AddField(*matchInport)
ipPacket := &protocol.IPv4{
Version: 0x4,
Expand All @@ -402,7 +402,7 @@ func createIGMPReportPacketIn(joinedGroups []net.IP, leftGroups []net.IP, versio
Length: 20 + m.Len(),
Data: m,
}
pkt.Data = protocol.Ethernet{
pkt.Data = &protocol.Ethernet{
HWDst: pktInDstMAC,
HWSrc: pktInSrcMAC,
Ethertype: protocol.IPv4_MSG,
Expand Down
9 changes: 5 additions & 4 deletions pkg/agent/multicast/mcast_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net"
"time"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/openflow15"
"antrea.io/libOpenflow/protocol"
"antrea.io/libOpenflow/util"
"antrea.io/ofnet/ofctrl"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (s *IGMPSnooper) HandlePacketIn(pktIn *ofctrl.PacketIn) error {
return nil
}

func getInfoInReg(regMatch *ofctrl.MatchField, rng *openflow13.NXRange) (uint32, error) {
func getInfoInReg(regMatch *ofctrl.MatchField, rng *openflow15.NXRange) (uint32, error) {
regValue, ok := regMatch.GetValue().(*ofctrl.NXRegister)
if !ok {
return 0, errors.New("register value cannot be retrieved")
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *IGMPSnooper) queryIGMP(group net.IP, versions []uint8) error {
if err != nil {
return err
}
if err := s.ofClient.SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, openflow13.P_NORMAL, igmp); err != nil {
if err := s.ofClient.SendIGMPQueryPacketOut(igmpQueryDstMac, mcastAllHosts, openflow15.P_NORMAL, igmp); err != nil {
return err
}
klog.V(2).InfoS("Sent packetOut for IGMP query", "group", group.String(), "version", version)
Expand All @@ -122,7 +122,8 @@ func (s *IGMPSnooper) processPacketIn(pktIn *ofctrl.PacketIn) error {
if iface.Type == interfacestore.ContainerInterface {
podName = iface.PodName
}
igmp, err := parseIGMPPacket(pktIn.Data)
pktData := pktIn.Data.(*protocol.Ethernet)
igmp, err := parseIGMPPacket(*pktData)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/openflow/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sync"
"time"

"antrea.io/libOpenflow/openflow13"
"antrea.io/libOpenflow/openflow15"
"antrea.io/libOpenflow/protocol"
"antrea.io/ofnet/ofctrl"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -2826,7 +2826,7 @@ func (f *featurePodConnectivity) hostBridgeLocalFlows() []binding.Flow {

// hostBridgeUplinkVLANFlows generates the flows to match VLAN packets from uplink port.
func (f *featurePodConnectivity) hostBridgeUplinkVLANFlows() []binding.Flow {
vlanMask := uint16(openflow13.OFPVID_PRESENT)
vlanMask := uint16(openflow15.OFPVID_PRESENT)
return []binding.Flow{
VLANTable.ofTable.BuildFlow(priorityLow).
Cookie(f.cookieAllocator.Request(f.category).Raw()).
Expand Down
26 changes: 18 additions & 8 deletions pkg/ovs/openflow/ofctrl_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ func (a *ofCTAction) load(field *openflow15.MatchField, value uint64, rng *Range

// MoveToLabel is an action to move data into ct_label.
func (a *ofCTAction) MoveToLabel(fromName string, fromRng, labelRng *Range) CTAction {
fromField, _ := openflow15.FindFieldHeaderByName(fromName, false)
toField, _ := openflow15.FindFieldHeaderByName(NxmFieldCtLabel, false)
fromField := getOxmIdByFieldName(fromName)
toField := getOxmIdByFieldName((NxmFieldCtLabel)
a.move(fromField, toField, uint16(fromRng.Length()), uint16(fromRng[0]), uint16(labelRng[0]))
return a
}

// MoveToCtMarkField is an action to move data into ct_mark.
func (a *ofCTAction) MoveToCtMarkField(fromRegField *RegField, ctMarkField *CtMarkField) CTAction {
fromField, _ := openflow15.FindFieldHeaderByName(fromRegField.GetNXFieldName(), false)
toField, _ := openflow15.FindFieldHeaderByName(NxmFieldCtMark, false)
fromField := getOxmIdByFieldName(fromRegField.GetNXFieldName())
toField:= getOxmIdByFieldName(NxmFieldCtMark)
a.move(fromField, toField, uint16(fromRegField.GetRange().Length()), uint16(fromRegField.GetRange()[0]), uint16(ctMarkField.rng[0]))
return a
}

func (a *ofCTAction) move(fromField *openflow15.MatchField, toField *openflow15.MatchField, nBits, fromStart, toStart uint16) {
action := openflow15.NewNXActionRegMove(nBits, fromStart, toStart, fromField, toField)
func (a *ofCTAction) move(fromField *openflow15.OxmId, toField *openflow15.OxmId, nBits, fromStart, toStart uint16) {
action := openflow15.NewActionCopyField(nBits, fromStart, toStart, *fromField, *toField)
a.actions = append(a.actions, action)
}

Expand Down Expand Up @@ -271,7 +271,7 @@ func (a *ofFlowAction) SetVLAN(vlanID uint16) FlowBuilder {

// LoadARPOperation is an action to Load data to NXM_OF_ARP_OP field.
func (a *ofFlowAction) LoadARPOperation(value uint16) FlowBuilder {
loadAct, _ := ofctrl.NewNXLoadAction(NxmFieldARPOp, uint64(value), openflow15.NewNXRange(0, 15))
loadAct := &ofctrl.SetARPOpAction{Value: value}
a.builder.ApplyAction(loadAct)
return a.builder
}
Expand Down Expand Up @@ -322,7 +322,12 @@ func (a *ofFlowAction) Move(fromField, toField string) FlowBuilder {

// MoveRange is an action to move data from "fromField" at "fromRange" to "toField" at "toRange".
func (a *ofFlowAction) MoveRange(fromField, toField string, fromRange, toRange Range) FlowBuilder {
moveAct, _ := ofctrl.NewNXMoveAction(fromField, toField, fromRange.ToNXRange(), toRange.ToNXRange())
nBits := fromRange.ToNXRange().GetNbits()
srcOffset := fromRange.ToNXRange().GetOfs()
dstOffset := toRange.ToNXRange().GetOfs()
srcOxmId := getOxmIdByFieldName(fromField)
dstOxmId := getOxmIdByFieldName(toField)
moveAct, _ := ofctrl.NewCopyFieldAction(nBits, srcOffset, dstOffset, srcOxmId, dstOxmId)
if a.builder.ofFlow.Table != nil && a.builder.ofFlow.Table.Switch != nil {
moveAct.ResetFieldsLength(a.builder.ofFlow.Table.Switch)
}
Expand Down Expand Up @@ -625,3 +630,8 @@ func (a *ofFlowAction) GotoStage(stage StageID) FlowBuilder {
a.builder.ofFlow.Goto(table.GetID())
return a.builder
}

func getOxmIdByFieldName(fieldName string) *openflow15.OxmId {
field, _ := openflow15.FindFieldHeaderByName(fieldName, false)
return openflow15.NewOxmId(field.Class, field.Field, field.HasMask, field.Length, field.ExperimenterID)
}
6 changes: 2 additions & 4 deletions pkg/ovs/ovsconfig/ovs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const (
openvSwitchSchema = "Open_vSwitch"
// Openflow protocol version 1.0.
openflowProtoVersion10 = "OpenFlow10"
// Openflow protocol version 1.3.
openflowProtoVersion13 = "OpenFlow13"
// Openflow protocol version 1.5.
openflowProtoVersion15 = "OpenFlow15"
// Maximum allowed value of ofPortRequest.
Expand Down Expand Up @@ -156,7 +154,7 @@ func (br *OVSBridge) updateBridgeConfiguration() Error {
Where: [][]interface{}{{"name", "==", br.name}},
Row: map[string]interface{}{
"protocols": makeOVSDBSetFromList([]string{openflowProtoVersion10,
openflowProtoVersion13, openflowProtoVersion15}),
openflowProtoVersion15}),
"datapath_type": br.datapathType,
},
})
Expand All @@ -174,7 +172,7 @@ func (br *OVSBridge) create() Error {
Name: br.name,
// Use Openflow protocol version 1.0 and 1.3.
Protocols: makeOVSDBSetFromList([]string{openflowProtoVersion10,
openflowProtoVersion13, openflowProtoVersion15}),
openflowProtoVersion15}),
DatapathType: string(br.datapathType),
}
namedUUID := tx.Insert(dbtransaction.Insert{
Expand Down
10 changes: 5 additions & 5 deletions pkg/ovs/ovsctl/ofctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *ovsCtlClient) DumpGroup(groupID uint32) (string, error) {
// versions of OpenFlow always dump all groups. But when OpenFlow
// version is not specified, ovs-ofctl defaults to use OpenFlow10 but
// with the Nicira extensions enabled, which can support dumping a
// single group too. So here, we do not specify Openflow13 to run the
// single group too. So here, we do not specify Openflow15 to run the
// command.
groupDump, err := c.runOfctlCmd(false, "dump-groups", strconv.FormatUint(uint64(groupID), 10))
if err != nil {
Expand Down Expand Up @@ -163,11 +163,11 @@ func (c *ovsCtlClient) SetPortNoFlood(ofport int) error {
return nil
}

func (c *ovsCtlClient) runOfctlCmd(openflow13 bool, cmd string, args ...string) ([]byte, error) {
func (c *ovsCtlClient) runOfctlCmd(openflow15 bool, cmd string, args ...string) ([]byte, error) {
cmdStr := fmt.Sprintf("ovs-ofctl %s %s", cmd, c.bridge)
cmdStr = cmdStr + " " + strings.Join(args, " ")
if openflow13 {
cmdStr += " -O Openflow13"
if openflow15 {
cmdStr += " -O Openflow15"
}
out, err := getOVSCommand(cmdStr).Output()
if err != nil {
Expand All @@ -177,7 +177,7 @@ func (c *ovsCtlClient) runOfctlCmd(openflow13 bool, cmd string, args ...string)
}

func (c *ovsCtlClient) RunOfctlCmd(cmd string, args ...string) ([]byte, error) {
// Default to use Openflow13.
// Default to use Openflow15.
return c.runOfctlCmd(true, cmd, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/ovs/openflow_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func PrepareOVSBridge(brName string) error {
// using the netdev datapath type does not impact test coverage but
// ensures that the integration tests can be run with Docker Desktop on
// macOS.
cmdStr := fmt.Sprintf("ovs-vsctl --may-exist add-br %s -- set Bridge %s protocols='OpenFlow10,OpenFlow13' datapath_type=netdev", brName, brName)
cmdStr := fmt.Sprintf("ovs-vsctl --may-exist add-br %s -- set Bridge %s protocols='OpenFlow10,OpenFlow15' datapath_type=netdev", brName, brName)
err := exec.Command("/bin/sh", "-c", cmdStr).Run()
if err != nil {
return err
Expand Down

0 comments on commit 672cfb1

Please sign in to comment.