Skip to content

Commit

Permalink
Test enhancements (#7)
Browse files Browse the repository at this point in the history
1. Add test case to check the order of Multipart Reply message
2. Fix an issue in IPv6 PacketIn test

Signed-off-by: wenying <[email protected]>
  • Loading branch information
wenyingd authored Sep 29, 2021
1 parent b81189e commit 253a50b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.2
v0.2.3
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module antrea.io/ofnet
go 1.15

require (
antrea.io/libOpenflow v0.3.1
antrea.io/libOpenflow v0.5.2
github.com/Microsoft/go-winio v0.4.14
github.com/cenkalti/hub v1.0.1-0.20140529221144-7be60e186e66 // indirect
github.com/cenkalti/rpc2 v0.0.0-20140912135055-44d0d95e4f52 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
antrea.io/libOpenflow v0.3.1 h1:zDu2TGxZYbrBCHxHq4o4TKgA7iRk+PfSW6y+nJSBsu4=
antrea.io/libOpenflow v0.3.1/go.mod h1:CzEJZxDNAupiGxeL5VOw92PsxfyvehEAvE3PiC6gr8o=
antrea.io/libOpenflow v0.5.2 h1:EFTyAHlG6UH8ZHpiPi6QPVPETqoIk0eB2B6i88VqacM=
antrea.io/libOpenflow v0.5.2/go.mod h1:CzEJZxDNAupiGxeL5VOw92PsxfyvehEAvE3PiC6gr8o=
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/cenkalti/hub v1.0.1-0.20140529221144-7be60e186e66 h1:mqwgWF7yBJ/zOFlWZk84IRFG/FhMG0f7aZWvcTx/JHA=
Expand Down
67 changes: 67 additions & 0 deletions ofctrl/multipart_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// #nosec G404: random number generator not used for security purposes
package ofctrl

import (
"testing"

"github.com/stretchr/testify/assert"

"antrea.io/libOpenflow/openflow13"
)

type multipartActor struct {
*OfActor
expectedTxs map[uint32]chan *openflow13.MultipartReply
}

func (o *multipartActor) MultipartReply(sw *OFSwitch, rep *openflow13.MultipartReply) {
if ch, found := o.expectedTxs[rep.Xid]; found {
ch <- rep
}
}
func TestMultipartReply(t *testing.T) {
app := new(multipartActor)
app.OfActor = new(OfActor)
app.expectedTxs = make(map[uint32]chan *openflow13.MultipartReply)
ctrl := NewController(app)
brName := "brMultipart"
ovsBr := prepareControllerAndSwitch(t, app.OfActor, ctrl, brName)
defer func() {
assert.Nilf(t, ovsBr.DeleteBridge(brName), "Failed to delete br %s", brName)
ctrl.Delete()
}()
testTableFeatures(t, app)
}

func testTableFeatures(t *testing.T, app *multipartActor) {
app.Switch.EnableMonitor()
ofSwitch := app.Switch
mpartRequest := &openflow13.MultipartRequest{
Header: openflow13.NewOfp13Header(),
Type: openflow13.MultipartType_TableFeatures,
Flags: 0,
}
mpartRequest.Header.Type = openflow13.Type_MultiPartRequest
mpartRequest.Header.Length = mpartRequest.Len()
ch := make(chan *openflow13.MultipartReply)
xid := mpartRequest.Xid
app.expectedTxs[xid] = ch
ofSwitch.Send(mpartRequest)

getTableCount := func() int {
tableCount := 0
for rep := range ch {
flags := rep.Flags
tableLen := len(rep.Body)
tableCount += tableLen
if flags == 0 {
break
}
}
return tableCount
}
tableCount := getTableCount()
assert.Equal(t, 254, tableCount)
delete(app.expectedTxs, xid)
close(ch)
}
4 changes: 3 additions & 1 deletion ofctrl/ofpacket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func testPacketInOut(t *testing.T, ofApp *packetApp, brName string, ipv6 bool) {
if ipv6 {
assert.Equal(t, uint16(protocol.IPv6_MSG), pktIn.Data.Ethertype)
var ipv6Obj protocol.IPv6
assert.Nil(t, ipv6Obj.UnmarshalBinary(pktIn.Data.Data.(*util.Buffer).Bytes()))
ipv6Bytes, err := pktIn.Data.Data.(*protocol.IPv6).MarshalBinary()
assert.Nil(t, err)
assert.Nil(t, ipv6Obj.UnmarshalBinary(ipv6Bytes))
assert.Equal(t, srcIP, ipv6Obj.NWSrc)
assert.Equal(t, dstIP, ipv6Obj.NWDst)
assert.Equal(t, uint8(IP_PROTO_TCP), ipv6Obj.NextHeader)
Expand Down

0 comments on commit 253a50b

Please sign in to comment.