查看: 1600|回复: 2

[分享] 【测试项目开源】基于LwIP实现在一个网口上同时支持IPv6+IP...

[复制链接]
  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3298

    主题

    6545

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32003
    最后登录
    2024-4-9
    发表于 2021-12-23 13:36:39 | 显示全部楼层 |阅读模式
    【测试项目开源】基于LwIP实现在一个网口上同时支持IPv6+IPv4通信
    本文基于恩智浦的i.MX RT1170 EVK及SDK,讨论如何在一个以太网口上同时实现IPv6和IPv4通信。


    测试环境:
    SDK:2.10.1
    IDE: MCUXpresso 11.4.0
    EVK: i.MX RT1170
    PC: Windows10


    1. 实现步骤
    1、下载i.MX RT1170 SDK 2.10.1导入lwip_udpecho_bm_cm7工程到MCUXpresso。
    2、在lwipopts.h文件中, 参考本文提供的代码链接, 添加以下代码:
    1. #define LWIP_IPV6 1
    复制代码
    3、在lwip_udpecho_bm.c文件中, 参考本文提供的代码链接,添加以下代码:
    1. ip6_addr_t ipaddr_v6;
    2. s8_t chosen_idx;
    3. // IPv6
    4. IP6_ADDR(&ipaddr_v6,PP_HTONL(0xFE800000),PP_HTONL(0x0),PP_HTONL(0x3DD79303),PP_HTONL(0x126c0df0));
    5. netif_add_ip6_address(&netif, &ipaddr_v6, &chosen_idx);
    6. netif.ip6_addr_state[chosen_idx] = IP6_ADDR_VALID;
    7. ip6_addr_assign_zone(ip_2_ip6(&netif.ip6_addr[0]), IP6_UNICAST, &netif);
    8. netif_ip6_addr_set_state(&netif, 0, IP6_ADDR_TENTATIVE);
    复制代码
    4、编译并下载到目标板运行。
    5、参考下图用网线连接PC机和目标板。
    21.png
    6、ICMP测试
    打开CMD窗口,参照下面的log分别进行IPv6和IPv4的测试。
    1. C:\Users\nxa16038>ping 192.168.0.102
    2. Pinging 192.168.0.102 with 32 bytes of data:
    3. Reply from 192.168.0.102: bytes=32 time=2ms TTL=255
    4. Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
    5. Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
    6. Reply from 192.168.0.102: bytes=32 time=1ms TTL=255
    7. Ping statistics for 192.168.0.102:
    8.     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    9. Approximate round trip times in milli-seconds:
    10.     Minimum = 1ms, Maximum = 2ms, Average = 1ms

    11. C:\Users\nxa16038>ping -6 FE80::3DD7:9303:126c:0df0
    12. Pinging fe80::3dd7:9303:126c:df0 with 32 bytes of data:
    13. Reply from fe80::3dd7:9303:126c:df0: time=1ms
    14. Reply from fe80::3dd7:9303:126c:df0: time=1ms
    15. Reply from fe80::3dd7:9303:126c:df0: time=1ms
    16. Reply from fe80::3dd7:9303:126c:df0: time=2ms
    17. Ping statistics for fe80::3dd7:9303:126c:df0:
    18.     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    19. Approximate round trip times in milli-seconds:
    20.     Minimum = 1ms, Maximum = 2ms, Average = 1ms
    复制代码
    7、UDP测试
    UDP测试需要使用相关的工具,在本文提供的代码链接中附带了此工具,测试命令和log如下所示:
    1. C:\Users\nxa16038\Desktop\tt2\udp_test_tool\x64\Debug>udp_test.exe -6 FE80::3DD7:9303:126c:df0 7 5001 test_string_12345
    2. Build date and time: Oct 22 2021, 18:50:48
    3. arc = 6
    4. arg[0] = udp_test.exe
    5. arg[1] = -6
    6. arg[2] = FE80::3DD7:9303:126c:df0
    7. arg[3] = 7
    8. arg[4] = 5001
    9. arg[5] = test_string_12345
    10. Send ok.
    11. Receiving...
    12. Get connection.
    13. Get string: test_string_12345
    14. Remote addr: fe80:0000:0000:0000:3dd7:9303:126c:0df0

    15. C:\Users\nxa16038\Desktop\tt2\udp_test_tool\x64\Debug>udp_test.exe -4 192.168.0.102 7 5001 test_string_12345
    16. Build date and time: Oct 22 2021, 18:50:48
    17. arc = 6
    18. arg[0] = udp_test.exe
    19. arg[1] = -4
    20. arg[2] = 192.168.0.102
    21. arg[3] = 7
    22. arg[4] = 5001
    23. arg[5] = test_string_12345
    24. Send ok.
    25. Receiving...
    26. Get connection.
    27. Get string: test_string_12345, len = 17
    28. Remote addr: 192.168.0.102
    复制代码
    2. 获取源代码
    本文的原代码可以从github.com进行下载,无需密码,下载链接为:
    https://github.com/jiaguonxpcom/lwip_ipv6_ipv4
    该代码编译后可以直接下载到i.MX RT1170 EVK运行。


    相关阅读:
    RT1170硬件资料:点击下载


    签到签到
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2024-4-9 17:01
  • 签到天数: 1478 天

    [LV.10]以坛为家III

    203

    主题

    2万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    92609
    最后登录
    2024-4-9
    发表于 2021-12-23 16:41:38 | 显示全部楼层
    这板子看的流口水了~~
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 08:23
  • 签到天数: 316 天

    [LV.8]以坛为家I

    4

    主题

    598

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2473
    最后登录
    2024-4-19
    发表于 2021-12-25 22:09:05 | 显示全部楼层
    流口水了
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-20 02:52 , Processed in 0.117478 second(s), 21 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表