@@ -1316,9 +1316,26 @@ func validateTaskNetworkConfig(taskNetworkConfig *state.TaskNetworkConfig) error
13161316 return nil
13171317}
13181318
1319- // startNetworkLatencyFault invokes the linux TC utility tool to start the network-latency fault.
1320- func (h * FaultHandler ) startNetworkLatencyFault (ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkLatencyRequest ) error {
1321- interfaceName := taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces [0 ].DeviceName
1319+ // startNetworkLatencyFault invokes the linux TC utility tool to start the
1320+ // network-latency fault for the given task.
1321+ func (h * FaultHandler ) startNetworkLatencyFault (
1322+ ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkLatencyRequest ,
1323+ ) error {
1324+ for _ , netInterface := range taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces {
1325+ err := h .startNetworkLatencyFaultForInterface (ctx , taskMetadata , request , netInterface .DeviceName )
1326+ if err != nil {
1327+ return err
1328+ }
1329+ }
1330+ return nil
1331+ }
1332+
1333+ // startNetworkLatencyFaultForInterface invokes the linux TC utility tool to start the
1334+ // network-latency fault for the given interface.
1335+ func (h * FaultHandler ) startNetworkLatencyFaultForInterface (
1336+ ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkLatencyRequest ,
1337+ interfaceName string ,
1338+ ) error {
13221339 networkMode := ecstypes .NetworkMode (taskMetadata .TaskNetworkConfig .NetworkMode )
13231340 // If task's network mode is awsvpc, we need to run nsenter to access the task's network namespace.
13241341 nsenterPrefix := ""
@@ -1378,8 +1395,24 @@ func (h *FaultHandler) startNetworkLatencyFault(ctx context.Context, taskMetadat
13781395}
13791396
13801397// startNetworkPacketLossFault invokes the linux TC utility tool to start the network-packet-loss fault.
1381- func (h * FaultHandler ) startNetworkPacketLossFault (ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkPacketLossRequest ) error {
1382- interfaceName := taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces [0 ].DeviceName
1398+ func (h * FaultHandler ) startNetworkPacketLossFault (
1399+ ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkPacketLossRequest ,
1400+ ) error {
1401+ for _ , netInterface := range taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces {
1402+ err := h .startNetworkPacketLossFaultForInterface (ctx , taskMetadata , request , netInterface .DeviceName )
1403+ if err != nil {
1404+ return err
1405+ }
1406+ }
1407+ return nil
1408+ }
1409+
1410+ // startNetworkPacketLossFault invokes the linux TC utility tool to start the network-packet-loss fault
1411+ // for the given network interface.
1412+ func (h * FaultHandler ) startNetworkPacketLossFaultForInterface (
1413+ ctx context.Context , taskMetadata * state.TaskResponse , request types.NetworkPacketLossRequest ,
1414+ interfaceName string ,
1415+ ) error {
13831416 networkMode := ecstypes .NetworkMode (taskMetadata .TaskNetworkConfig .NetworkMode )
13841417 // If task's network mode is awsvpc, we need to run nsenter to access the task's network namespace.
13851418 nsenterPrefix := ""
@@ -1439,7 +1472,20 @@ func (h *FaultHandler) startNetworkPacketLossFault(ctx context.Context, taskMeta
14391472// stopTCFault invokes the linux TC utility tool to stop the network fault started by TC,
14401473// including both network-latency fault and network-packet-loss fault.
14411474func (h * FaultHandler ) stopTCFault (ctx context.Context , taskMetadata * state.TaskResponse ) error {
1442- interfaceName := taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces [0 ].DeviceName
1475+ for _ , netInterface := range taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces {
1476+ err := h .stopTCFaultForInterface (ctx , taskMetadata , netInterface .DeviceName )
1477+ if err != nil {
1478+ return err
1479+ }
1480+ }
1481+ return nil
1482+ }
1483+
1484+ // stopTCFaultForInterface invokes the linux TC utility tool to stop the network fault started by TC,
1485+ // including both network-latency fault and network-packet-loss fault, for the given network interface.
1486+ func (h * FaultHandler ) stopTCFaultForInterface (
1487+ ctx context.Context , taskMetadata * state.TaskResponse , interfaceName string ,
1488+ ) error {
14431489 networkMode := ecstypes .NetworkMode (taskMetadata .TaskNetworkConfig .NetworkMode )
14441490 // If task's network mode is awsvpc, we need to run nsenter to access the task's network namespace.
14451491 nsenterPrefix := ""
@@ -1487,9 +1533,31 @@ func (h *FaultHandler) stopTCFault(ctx context.Context, taskMetadata *state.Task
14871533 return nil
14881534}
14891535
1490- // checkTCFault check if there's existing network-latency fault or network-packet-loss fault.
1491- func (h * FaultHandler ) checkTCFault (ctx context.Context , taskMetadata * state.TaskResponse ) (bool , bool , error ) {
1492- interfaceName := taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces [0 ].DeviceName
1536+ // checkTCFault checks if there's existing network-latency fault or network-packet-loss fault.
1537+ func (h * FaultHandler ) checkTCFault (
1538+ ctx context.Context , taskMetadata * state.TaskResponse ,
1539+ ) (bool , bool , error ) {
1540+ var latencyFound , packetLossFound bool
1541+ for _ , netInterface := range taskMetadata .TaskNetworkConfig .NetworkNamespaces [0 ].NetworkInterfaces {
1542+ hasLatency , hasPacketLoss , err := h .checkTCFaultForInterface (ctx , taskMetadata , netInterface .DeviceName )
1543+ if err != nil {
1544+ return false , false , err
1545+ }
1546+ if hasLatency {
1547+ latencyFound = true
1548+ }
1549+ if hasPacketLoss {
1550+ packetLossFound = true
1551+ }
1552+ }
1553+ return latencyFound , packetLossFound , nil
1554+ }
1555+
1556+ // checkTCFaultForInterface checks if there's existing network-latency fault or
1557+ // network-packet-loss fault for the given network interface.
1558+ func (h * FaultHandler ) checkTCFaultForInterface (
1559+ ctx context.Context , taskMetadata * state.TaskResponse , interfaceName string ,
1560+ ) (bool , bool , error ) {
14931561 networkMode := ecstypes .NetworkMode (taskMetadata .TaskNetworkConfig .NetworkMode )
14941562 // If task's network mode is awsvpc, we need to run nsenter to access the task's network namespace.
14951563 nsenterPrefix := ""
0 commit comments