diff --git a/pkg/agent/controller/trafficcontrol/controller.go b/pkg/agent/controller/trafficcontrol/controller.go index 04408bd23b6..77f8891c078 100644 --- a/pkg/agent/controller/trafficcontrol/controller.go +++ b/pkg/agent/controller/trafficcontrol/controller.go @@ -374,7 +374,7 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort var ofPortTmp int32 createUDPTunnel := func(tunnelType ovsconfig.TunnelType, portName, remoteIP string, dstPort int32) error { externalIDs := map[string]interface{}{ - interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTunnel, + interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, } if dstPort != 0 { externalIDs["dst_port"] = strconv.Itoa(int(dstPort)) @@ -402,7 +402,7 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort return uint32(ofPort), nil } externalIDs := map[string]interface{}{ - interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset, + interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, } c.ovsPortUpdateMutex.Lock() defer c.ovsPortUpdateMutex.Unlock() @@ -415,6 +415,9 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort _ = c.ovsBridgeClient.DeletePort(portUUID) } }() + if _, _, err := util.SetLinkUp(device.OVSInternal.Name); err != nil { + return 0, err + } ofPortTmp, err = c.ovsBridgeClient.GetOFPort(device.OVSInternal.Name, false) if err != nil { return 0, err @@ -430,7 +433,7 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort return uint32(itf.OFPort), nil } externalIDs := map[string]interface{}{ - interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset, + interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, } c.ovsPortUpdateMutex.Lock() defer c.ovsPortUpdateMutex.Unlock() @@ -505,7 +508,7 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort portName := strings.Join([]string{portNamePrefixERSPAN, genPortNameERSPANTunnel(device.ERSPAN)}, "-") externalIDs := map[string]interface{}{ - interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset, + interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, "erspan_ver": strconv.Itoa(int(version)), "key": strconv.Itoa(1), } @@ -533,8 +536,7 @@ func (c *Controller) getDevicePort(device *v1alpha2.TrafficControlPort) (ofPort c.interfaceStore.AddInterface(itf) ofPort = uint32(ofPortTmp) - klog.V(2).InfoS("Created ERSPAN port", "remoteIP", remoteIP, "version", version, "index", index, - "dir", dir, "hardwareID", hardwareID) + klog.V(2).InfoS("Created ERSPAN port", "config", device.ERSPAN) } return } diff --git a/pkg/agent/controller/trafficcontrol/controller_test.go b/pkg/agent/controller/trafficcontrol/controller_test.go index 592f5a42cdb..f7ddbda598f 100644 --- a/pkg/agent/controller/trafficcontrol/controller_test.go +++ b/pkg/agent/controller/trafficcontrol/controller_test.go @@ -164,7 +164,7 @@ func TestSyncTrafficControl(t *testing.T) { mockOVSBridgeClient.EXPECT().GetOFPort("test-device", false).Return(int32(0), ovsconfig.NewTransactionError(fmt.Errorf("failed to get OVS port"), true)).Times(1) mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateInternalPort("test-device", int32(0), - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl}) mockOVSBridgeClient.EXPECT().GetOFPort("test-device", false).Times(1) }, }, @@ -241,7 +241,7 @@ func TestSyncTrafficControl(t *testing.T) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().GetOFPort("fake-internal-device", false).Return(int32(0), ovsconfig.NewTransactionError(fmt.Errorf("failed to get OVS port"), true)).Times(1) mockOVSBridgeClient.EXPECT().CreateInternalPort("fake-internal-device", int32(0), - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl}) mockOVSBridgeClient.EXPECT().GetOFPort("fake-internal-device", false).Times(1) }, }, @@ -259,7 +259,7 @@ func TestSyncTrafficControl(t *testing.T) { expectedCalls: func(mockOFClient *openflowtest.MockClient, mockOVSBridgeClient *ovsconfigtest.MockOVSBridgeClient) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreatePort("fake-device", "fake-device", - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl}) mockOVSBridgeClient.EXPECT().GetOFPort("fake-device", false) }, }, @@ -280,7 +280,7 @@ func TestSyncTrafficControl(t *testing.T) { expectedCalls: func(mockOFClient *openflowtest.MockClient, mockOVSBridgeClient *ovsconfigtest.MockOVSBridgeClient) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateTunnelPortExt("gre-27a193", ovsconfig.TunnelType(ovsconfig.GRETunnel), int32(0), false, "", "1.1.1.1", "", - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTunnel}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl}) mockOVSBridgeClient.EXPECT().GetOFPort("gre-27a193", false).Times(1) }, }, @@ -302,7 +302,7 @@ func TestSyncTrafficControl(t *testing.T) { expectedCalls: func(mockOFClient *openflowtest.MockClient, mockOVSBridgeClient *ovsconfigtest.MockOVSBridgeClient) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateTunnelPortExt("vxlan-0ec8dd", ovsconfig.TunnelType(ovsconfig.VXLANTunnel), int32(0), false, "", "1.1.1.1", "", - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTunnel, "dst_port": strconv.Itoa(int(defaultVXLANTunnelDestinationPort))}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, "dst_port": strconv.Itoa(int(defaultVXLANTunnelDestinationPort))}) mockOVSBridgeClient.EXPECT().GetOFPort("vxlan-0ec8dd", false).Times(1) }, }, @@ -324,7 +324,7 @@ func TestSyncTrafficControl(t *testing.T) { expectedCalls: func(mockOFClient *openflowtest.MockClient, mockOVSBridgeClient *ovsconfigtest.MockOVSBridgeClient) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl-GENEVE", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateTunnelPortExt("geneve-ecd278", ovsconfig.TunnelType(ovsconfig.GeneveTunnel), int32(0), false, "", "1.1.1.1", "", - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTunnel, "dst_port": strconv.Itoa(int(defaultGENEVEdstPort))}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, "dst_port": strconv.Itoa(int(defaultGENEVEdstPort))}) mockOVSBridgeClient.EXPECT().GetOFPort("geneve-ecd278", false).Times(1) }, }, @@ -345,7 +345,7 @@ func TestSyncTrafficControl(t *testing.T) { expectedCalls: func(mockOFClient *openflowtest.MockClient, mockOVSBridgeClient *ovsconfigtest.MockOVSBridgeClient) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl-GENEVE", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateTunnelPortExt("geneve-ecd278", ovsconfig.TunnelType(ovsconfig.GeneveTunnel), int32(0), false, "", "1.1.1.1", "", - map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTunnel, "dst_port": strconv.Itoa(int(defaultGENEVEdstPort))}) + map[string]interface{}{interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, "dst_port": strconv.Itoa(int(defaultGENEVEdstPort))}) mockOVSBridgeClient.EXPECT().GetOFPort("geneve-ecd278", false).Times(1) }, }, @@ -369,7 +369,7 @@ func TestSyncTrafficControl(t *testing.T) { mockOFClient.EXPECT().InstallTrafficControlMarkFlows("trafficControl1", []uint32{1}, uint32(0), v1alpha2.DirectionIngress, v1alpha2.ActionMirror) mockOVSBridgeClient.EXPECT().CreateTunnelPortExt("erspan-da39a3", ovsconfig.TunnelType(ovsconfig.ERSpanTunnel), int32(0), false, "", "", "", map[string]interface{}{ - interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaUnset, + interfacestore.AntreaInterfaceTypeKey: interfacestore.AntreaTrafficControl, "erspan_ver": strconv.Itoa(1), "key": strconv.Itoa(1), }) diff --git a/pkg/agent/interfacestore/types.go b/pkg/agent/interfacestore/types.go index a443dd6dd6d..ce841c1acc7 100644 --- a/pkg/agent/interfacestore/types.go +++ b/pkg/agent/interfacestore/types.go @@ -40,6 +40,7 @@ const ( AntreaTunnel = "tunnel" AntreaUplink = "uplink" AntreaHost = "host" + AntreaTrafficControl = "traffic-control" AntreaUnset = "" )