[ATS_IPv4_00372]组播地址不能用作源地址

Multicast address MUST NOT be used as Source address

测试目标

  • 目标:验证IUT在收到源IP地址为组播地址(Multicast Address)的ICMPv4 Echo请求时,不发送ICMPv4 Echo Reply;以避免网络混乱。

测试步骤

  1. LT(测试脚本):
  • LT发送一个ICMPv4 Echo请求给IUT。

  • 源IP地址(Source IP)设置为一个组播地址(AUTOSAR规范中未指定具体地址,我们可以选择一个常见的组播地址,例如224.0.0.1)。

  • 其他字段使用默认值。

  1. IUT:
  • 验证IUT不发送ICMPv4 Echo Reply。

  • 通过标准:IUT不回复,测试通过;如果IUT回复,测试失败

CAPL代码

cpp 复制代码
/*@!Encoding:65001*/
/*
 * This code tests if a device (IUT) correctly ignores an ICMPv4 Echo Request with a multicast source IP 
 * by sending such a request and checking for an unexpected reply.
 * 20250325 v1
 */
variables
{ 
//  const dword iutIP = 0xC0A8B239; // IUT IP: 192.168.178.57
//  const dword multicastIP = 0xE0000001; // Multicast IP: 224.0.0.1
  ethernetPacket txPacket; 

  dword gLastSequenceNumber; 
  dword SPECIAL_IDENTIFIER = 0x1234; // ICMP Echo identifier (example)

  timer testTimer; 
  byte testFailed = 0; 
}

on start
{
  // Step 1: Send ICMPv4 Echo Request with multicast source IP
  char sourceMac[18] = "00:11:22:33:44:55"; // LT MAC (example)
  char destMac[18] = "AA:BB:CC:DD:00:39";   // IUT MAC
  char sourceIP[16] = "224.0.0.1";          // Source IP: Multicast (test requirement)
  char destIP[16] = "192.168.178.57";       // Dest IP: IUT IP

  write("Starting Test ATS_IPv4_00372: Sending ICMPv4 Echo Request with multicast source IP...");

  testFailed = 0;

  sendICMPEchoRequest_Def(1, 2500, sourceMac, destMac, sourceIP, destIP);
  setTimer(testTimer, 5000);
}

void sendICMPEchoRequest_Def(
                    byte channelNum, 
                    word vlanID, 
                    char sourceMac[], 
                    char destMac[], 
                    char sourceIP[], 
                    char destIP[]
)
{
  ethernetPacket txPacket; 
  IP_Address iPaddr_Dest;  
  IP_Address iPaddr_Source; 

  txPacket.msgChannel = channelNum; 

  // Set Ethernet header
  txPacket.source = ethGetMacAddressAsNumber(sourceMac); 
  txPacket.destination = ethGetMacAddressAsNumber(destMac); 
  txPacket.type = 0x0800; 

  // Set VLAN (VLAN ID 2500, PCP=0, DEI=0)
  // 0x8100 = IEEE 802.1Q, 0x09C4 = VLAN ID 2500
  txPacket.SetVlan(0x8100, 0x09C4); 

  // Init IPv4 header
  txPacket.IPv4.Init();
  iPaddr_Source.ParseAddressFromString(sourceIP);
  iPaddr_Dest.ParseAddressFromString(destIP);   
  txPacket.IPv4.Source = iPaddr_Source.IPV4Address; 
  txPacket.IPv4.Destination = iPaddr_Dest.IPV4Address; 

  // Init ICMPv4 Echo Request
  txPacket.ICMPv4.Init();
  txPacket.ICMPv4.Echo.Init();
  gLastSequenceNumber++; // Increment sequence number
  txPacket.ICMPv4.Echo.Identifier = SPECIAL_IDENTIFIER; // Set identifier
  txPacket.ICMPv4.Echo.Sequence = gLastSequenceNumber;  // Set sequence number

  // Complete and send packet
  txPacket.CompletePacket();
  output(txPacket);
  write("Sent ICMPv4 Echo Request, Source IP: %s, Dest IP: %s", sourceIP, destIP);
}

// Listen for responses on Ethernet1
on ethernetPacket msgChannel1.*
{
  if(this.type == 0x0800 && this.Length >= 28) // IPv4 packet
  {
    if(this.Byte(9) == 0x01) // ICMP protocol
    {
      if(this.Byte(20) == 0x00) // ICMP Type: Echo Reply
      {
        if(this.source == EthGetMacAddressAsNumber("AA:BB:CC:DD:00:39")) // From IUT
        {
          write("ERROR: IUT sent ICMPv4 Echo Reply, which is NOT expected!");

          testFailed = 1;
          cancelTimer(testTimer); 
        }
      }
    }
  }
  else
  {
    write("Received packet, but not an IPv4 ICMP Echo Reply.");
  }
}

on timer testTimer
{
  if (testFailed == 0)
  {
    write("Test ATS_IPv4_00372 Passed: IUT did not send ICMPv4 Echo Reply as expected.");
  }
  else
  {
    write("Test ATS_IPv4_00372 Failed: IUT sent an unexpected ICMPv4 Echo Reply.");
  }
}
相关推荐
车端域控测试工程师1 个月前
【ISO 14229-1:2023 UDS诊断(ECU复位0x11服务)测试用例CAPL代码全解析⑰】
经验分享·学习·汽车·测试用例·capl
车端域控测试工程师1 个月前
【ISO 14229-1:2023 UDS诊断(ECU复位0x11服务)测试用例CAPL代码全解析⑪】
经验分享·学习·汽车·测试用例·capl
车端域控测试工程师1 个月前
【ISO 14229-1:2023 UDS诊断(ECU复位0x11服务)测试用例CAPL代码全解析⑩】
经验分享·学习·汽车·测试用例·capl
汽车电子工具智慧库1 个月前
汽车通信未来新趋势:Eclipse uProtocol
汽车·autosar·通信
车端域控测试工程师1 个月前
【ISO 14229-1:2023 UDS诊断(会话控制0x10服务)测试用例CAPL代码全解析⑤】
经验分享·学习·汽车·测试用例·capl·canoe
车端域控测试工程师2 个月前
【ISO 14229-1:2023 UDS诊断(会话控制0x10服务)测试用例CAPL代码全解析⑩】
经验分享·学习·汽车·测试用例·capl·canoe
车端域控测试工程师2 个月前
【ISO 14229-1:2023 UDS诊断(ECU复位0x11服务)测试用例CAPL代码全解析⑫】
经验分享·学习·汽车·测试用例·capl
车端域控测试工程师2 个月前
【ISO 14229-1:2023 UDS诊断全量测试用例清单系列:第十七节】
服务器·经验分享·学习·汽车·测试用例·capl
车端域控测试工程师2 个月前
【ISO 14229-1:2023 UDS诊断(ECU复位0x11服务)测试用例CAPL代码全解析⑧】
经验分享·学习·汽车·测试用例·capl·canoe