[VOL-3461] Lowering flow chunk size because of lager flow size in TT workflow
Change-Id: I840619c3a153cf3106f333198fbca809c1c4cca9
diff --git a/internal/pkg/openflow/client.go b/internal/pkg/openflow/client.go
index ca8121c..b7d5a28 100644
--- a/internal/pkg/openflow/client.go
+++ b/internal/pkg/openflow/client.go
@@ -53,7 +53,7 @@
// according to testing this is the maximum content of an
// openflow message to remain under 64KB
- ofcFlowsChunkSize = 450 // this amount of flows is around 57KB
+ ofcFlowsChunkSize = 400 // this amount of flows is around 40KB for DT, 47KB ATT and 61KB for TT
ofcPortsChunkSize = 550 // this amount of port stats is around 61KB
ofcPortsDescChunkSize = 900 // this amount of port desc is around 57KB
)
diff --git a/internal/pkg/openflow/stats.go b/internal/pkg/openflow/stats.go
index d50fc14..096e731 100644
--- a/internal/pkg/openflow/stats.go
+++ b/internal/pkg/openflow/stats.go
@@ -383,7 +383,9 @@
n := 0
for n <= total {
- chunk := flows[n*chunkSize : min((n*chunkSize)+chunkSize, len(flows))]
+ limit := (n * chunkSize) + chunkSize
+
+ chunk := flows[n*chunkSize : min(limit, len(flows))]
if len(chunk) == 0 {
break
@@ -393,7 +395,7 @@
response.SetXid(request.GetXid())
response.SetVersion(4)
response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
- if total != n {
+ if limit < len(flows) {
response.SetFlags(ofp.StatsReplyFlags(ofp.OFPSFReplyMore))
}
response.SetEntries(chunk)
diff --git a/internal/pkg/openflow/stats_test.go b/internal/pkg/openflow/stats_test.go
index e80d239..d618fe4 100644
--- a/internal/pkg/openflow/stats_test.go
+++ b/internal/pkg/openflow/stats_test.go
@@ -185,23 +185,29 @@
}
}
-func TestHandleFlowStatsRequest(t *testing.T) {
+func TestHandleFlowStatsRequestExactlyDivisible(t *testing.T) {
- generatedFlowsCount := 2000
+ generatedFlowsCount := ofcFlowsChunkSize * 5
- ofc := newTestOFConnection(2000, 0)
+ testCorrectChunkAndReplyMoreFlag(t, generatedFlowsCount)
+}
+func TestHandleFlowStatsRequestNotExactlyDivisible(t *testing.T) {
+
+ generatedFlowsCount := int(ofcFlowsChunkSize * 5.5)
+
+ testCorrectChunkAndReplyMoreFlag(t, generatedFlowsCount)
+}
+
+func testCorrectChunkAndReplyMoreFlag(t *testing.T, generatedFlowsCount int) {
+ ofc := newTestOFConnection(generatedFlowsCount, 0)
request := of13.NewFlowStatsRequest()
-
replies, err := ofc.handleFlowStatsRequest(context.Background(), request)
assert.Equal(t, err, nil)
-
// check that the correct number of messages is generated
assert.Equal(t, int(math.Ceil(float64(generatedFlowsCount)/ofcFlowsChunkSize)), len(replies))
-
n := 1
entriesCount := 0
-
for _, r := range replies {
json, _ := r.Flags.MarshalJSON()
@@ -226,7 +232,6 @@
entriesCount = entriesCount + len(r.GetEntries())
n++
}
-
// make sure all the generate item are included in the responses
assert.Equal(t, generatedFlowsCount, entriesCount)
}