Skip to content

Commit

Permalink
Fix ingress policy stats miscalculation(#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceclinux committed Apr 12, 2021
1 parent 599d663 commit 4ef6d95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/agent/openflow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (c *client) InstallGatewayFlows() error {
func (c *client) InstallDefaultTunnelFlows() error {
flows := []binding.Flow{
c.tunnelClassifierFlow(config.DefaultTunOFPort, cookie.Default),
c.l2ForwardCalcFlow(globalVirtualMAC, config.DefaultTunOFPort, true, cookie.Default),
c.l2ForwardCalcFlow(globalVirtualMAC, config.DefaultTunOFPort, false, cookie.Default),
}
if err := c.ofEntryOperations.AddAll(flows); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/networkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/stats/v1alpha1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -142,12 +143,23 @@ func TestNetworkPolicyStats(t *testing.T) {
}

if err := wait.Poll(5*time.Second, defaultTimeout, func() (bool, error) {
var ingressStats *v1alpha1.NetworkPolicyStats
for _, np := range []string{"test-networkpolicy-ingress", "test-networkpolicy-egress"} {
stats, err := data.crdClient.StatsV1alpha1().NetworkPolicyStats(testNamespace).Get(context.TODO(), np, metav1.GetOptions{})
if err != nil {
return false, err
}
t.Logf("Got NetworkPolicy stats: %v", stats)
if ingressStats != nil {
if stats.TrafficStats.Packets != ingressStats.TrafficStats.Packets {
return false, nil
}
if stats.TrafficStats.Bytes != ingressStats.TrafficStats.Bytes {
return false, nil
}
} else {
ingressStats = stats
}
if stats.TrafficStats.Sessions != int64(totalSessions) {
return false, nil
}
Expand Down

0 comments on commit 4ef6d95

Please sign in to comment.