@@ -604,7 +604,7 @@ type svcConfig struct {
604604 withSessionAffinity bool
605605}
606606
607- func TestProxyServiceFlows (t * testing.T ) {
607+ func TestProxyServiceFlowsAntreaPolicyDisabled (t * testing.T ) {
608608 // Reset OVS metrics (Prometheus) and reinitialize them to test.
609609 legacyregistry .Reset ()
610610 metrics .InitializeOVSMetrics ()
@@ -679,7 +679,77 @@ func TestProxyServiceFlows(t *testing.T) {
679679
680680 for _ , tc := range tcs {
681681 groupID := ofconfig .GroupIDType (tc .gid )
682- expTableFlows , expGroupBuckets := expectedProxyServiceGroupAndFlows (tc .gid , tc .svc , tc .endpoints , tc .stickyAge )
682+ expTableFlows , expGroupBuckets := expectedProxyServiceGroupAndFlows (tc .gid , tc .svc , tc .endpoints , tc .stickyAge , false )
683+ installServiceFlows (t , tc .gid , tc .svc , tc .endpoints , tc .stickyAge )
684+ for _ , tableFlow := range expTableFlows {
685+ ofTestUtils .CheckFlowExists (t , ovsCtlClient , tableFlow .tableName , 0 , true , tableFlow .flows )
686+ }
687+ ofTestUtils .CheckGroupExists (t , ovsCtlClient , groupID , "select" , expGroupBuckets , true )
688+
689+ uninstallServiceFlowsFunc (t , tc .gid , tc .svc , tc .endpoints )
690+ for _ , tableFlow := range expTableFlows {
691+ ofTestUtils .CheckFlowExists (t , ovsCtlClient , tableFlow .tableName , 0 , false , tableFlow .flows )
692+ }
693+ ofTestUtils .CheckGroupExists (t , ovsCtlClient , groupID , "select" , expGroupBuckets , false )
694+ }
695+ }
696+
697+ func TestProxyServiceFlowsAntreaPoilcyEnabled (t * testing.T ) {
698+ // Reset OVS metrics (Prometheus) and reinitialize them to test.
699+ legacyregistry .Reset ()
700+ metrics .InitializeOVSMetrics ()
701+
702+ c = ofClient .NewClient (br , bridgeMgmtAddr , true , true , false , false , false , false , false , false , false )
703+ err := ofTestUtils .PrepareOVSBridge (br )
704+ require .Nil (t , err , fmt .Sprintf ("Failed to prepare OVS bridge %s" , br ))
705+
706+ config := prepareConfiguration (true , false )
707+ _ , err = c .Initialize (roundInfo , config .nodeConfig , & agentconfig.NetworkConfig {TrafficEncapMode : agentconfig .TrafficEncapModeEncap , IPv4Enabled : true }, & agentconfig.EgressConfig {}, & agentconfig.ServiceConfig {})
708+ require .Nil (t , err , "Failed to initialize OFClient" )
709+
710+ defer func () {
711+ err = c .Disconnect ()
712+ assert .Nil (t , err , fmt .Sprintf ("Error while disconnecting from OVS bridge: %v" , err ))
713+ err = ofTestUtils .DeleteOVSBridge (br )
714+ assert .Nil (t , err , fmt .Sprintf ("Error while deleting OVS bridge: %v" , err ))
715+ ofClient .CleanOFTableCache ()
716+ ofClient .ResetOFTable ()
717+ }()
718+
719+ endpoints := []k8sproxy.Endpoint {
720+ k8stypes .NewEndpointInfo (& k8sproxy.BaseEndpointInfo {
721+ Endpoint : net .JoinHostPort ("192.168.1.2" , "8081" ),
722+ IsLocal : true ,
723+ }),
724+ k8stypes .NewEndpointInfo (& k8sproxy.BaseEndpointInfo {
725+ Endpoint : net .JoinHostPort ("10.20.1.11" , "8081" ),
726+ IsLocal : false ,
727+ }),
728+ }
729+
730+ stickyMaxAgeSeconds := uint16 (30 )
731+
732+ tcs := []struct {
733+ svc svcConfig
734+ gid uint32
735+ endpoints []k8sproxy.Endpoint
736+ stickyAge uint16
737+ }{
738+ {
739+ svc : svcConfig {
740+ protocol : ofconfig .ProtocolTCP ,
741+ ip : net .ParseIP ("10.20.30.41" ),
742+ port : uint16 (8000 ),
743+ },
744+ gid : 2 ,
745+ endpoints : endpoints ,
746+ stickyAge : stickyMaxAgeSeconds ,
747+ },
748+ }
749+
750+ for _ , tc := range tcs {
751+ groupID := ofconfig .GroupIDType (tc .gid )
752+ expTableFlows , expGroupBuckets := expectedProxyServiceGroupAndFlows (tc .gid , tc .svc , tc .endpoints , tc .stickyAge , true )
683753 installServiceFlows (t , tc .gid , tc .svc , tc .endpoints , tc .stickyAge )
684754 for _ , tableFlow := range expTableFlows {
685755 ofTestUtils .CheckFlowExists (t , ovsCtlClient , tableFlow .tableName , 0 , true , tableFlow .flows )
@@ -716,7 +786,7 @@ func uninstallServiceFlowsFunc(t *testing.T, gid uint32, svc svcConfig, endpoint
716786 }
717787}
718788
719- func expectedProxyServiceGroupAndFlows (gid uint32 , svc svcConfig , endpointList []k8sproxy.Endpoint , stickyAge uint16 ) (tableFlows []expectTableFlows , groupBuckets []string ) {
789+ func expectedProxyServiceGroupAndFlows (gid uint32 , svc svcConfig , endpointList []k8sproxy.Endpoint , stickyAge uint16 , antreaPolicyEnabled bool ) (tableFlows []expectTableFlows , groupBuckets []string ) {
720790 nw_proto := 6
721791 learnProtoField := "NXM_OF_TCP_DST[]"
722792 if svc .protocol == ofconfig .ProtocolUDP {
@@ -732,10 +802,17 @@ func expectedProxyServiceGroupAndFlows(gid uint32, svc svcConfig, endpointList [
732802 serviceLearnReg = 3
733803 }
734804 cookieAllocator := cookie .NewAllocator (roundInfo .RoundNum )
805+
806+ loadGourpID := ""
807+ ctTable := "EgressRule"
808+ if antreaPolicyEnabled {
809+ loadGourpID = fmt .Sprintf ("set_field:0x%x->reg7," , gid )
810+ ctTable = "AntreaPolicyEgressRule"
811+ }
735812 svcFlows := expectTableFlows {tableName : "ServiceLB" , flows : []* ofTestUtils.ExpectFlow {
736813 {
737814 MatchStr : fmt .Sprintf ("priority=200,%s,reg4=0x10000/0x70000,nw_dst=%s,tp_dst=%d" , string (svc .protocol ), svc .ip .String (), svc .port ),
738- ActStr : fmt .Sprintf ("set_field:0x%x/0x70000->reg4,set_field:0x200/0x200->reg0,set_field:0x%x->reg7,group :%d" , serviceLearnReg << 16 , gid , gid ),
815+ ActStr : fmt .Sprintf ("set_field:0x%x/0x70000->reg4,set_field:0x200/0x200->reg0,%sgroup :%d" , serviceLearnReg << 16 , loadGourpID , gid ),
739816 },
740817 {
741818 MatchStr : fmt .Sprintf ("priority=190,%s,reg4=0x30000/0x70000,nw_dst=%s,tp_dst=%d" , string (svc .protocol ), svc .ip .String (), svc .port ),
@@ -754,7 +831,7 @@ func expectedProxyServiceGroupAndFlows(gid uint32, svc svcConfig, endpointList [
754831 unionVal := (0b010 << 16 ) + uint32 (epPort )
755832 epDNATFlows .flows = append (epDNATFlows .flows , & ofTestUtils.ExpectFlow {
756833 MatchStr : fmt .Sprintf ("priority=200,%s,reg3=%s,reg4=0x%x/0x7ffff" , string (svc .protocol ), epIP , unionVal ),
757- ActStr : fmt .Sprintf ("ct(commit,table=EgressRule ,zone=65520,nat(dst=%s:%d),exec(set_field:0x10/0x10->ct_mark,move:NXM_NX_REG0[0..3]->NXM_NX_CT_MARK[0..3])" , ep .IP (), epPort ),
834+ ActStr : fmt .Sprintf ("ct(commit,table=%s ,zone=65520,nat(dst=%s:%d),exec(set_field:0x10/0x10->ct_mark,move:NXM_NX_REG0[0..3]->NXM_NX_CT_MARK[0..3])" , ctTable , ep .IP (), epPort ),
758835 })
759836
760837 if ep .GetIsLocal () {
0 commit comments