Skip to content

Commit

Permalink
Rebase and address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed May 6, 2022
1 parent dd0804c commit fc4e3ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
14 changes: 8 additions & 6 deletions pkg/agent/controller/trafficcontrol/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/agent/controller/trafficcontrol/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
Expand Down Expand Up @@ -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)
},
},
Expand All @@ -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)
},
},
Expand All @@ -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)
},
},
Expand All @@ -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)
},
},
Expand All @@ -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)
},
},
Expand All @@ -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)
},
},
Expand All @@ -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),
})
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/interfacestore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
AntreaTunnel = "tunnel"
AntreaUplink = "uplink"
AntreaHost = "host"
AntreaTrafficControl = "traffic-control"
AntreaUnset = ""
)

Expand Down

0 comments on commit fc4e3ec

Please sign in to comment.