美文网首页
在虚拟机编译运行dpvs

在虚拟机编译运行dpvs

作者: 分享放大价值 | 来源:发表于2022-01-24 21:38 被阅读0次

    安装依赖库

    apt install libnuma-dev
    apt-get install libpopt-dev
    

    编译dpvs

    #编译dpdk
    ./scripts/dpdk-build.sh
    
    #编译dpvs
    export PKG_CONFIG_PATH=/root/dpvs/dpdk/dpdklib/lib/x86_64-linux-gnu/pkgconfig
    make
    
    #编译后,dpvs在src下,dpip在tools/dpip/build下
    root@ubuntu:~/dpvs# ls src/dpvs
    src/dpvs
    root@ubuntu:~/dpvs# ls tools/dpip/build/dpip
    tools/dpip/build/dpip
    root@ubuntu:~/dpvs# ls tools/ipvsadm/ipvsadm
    tools/ipvsadm/ipvsadm
    root@ubuntu:~/dpvs# ls tools/keepalived/keepalived/keepalived
    tools/keepalived/keepalived/keepalived
    

    执行

    echo 2048 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
    mkdir -p /mnt/huge
    mount -t hugetlbfs nodev /mnt/huge
    
    modprobe uio_pci_generic
    
    insmod dpdk/dpdklib/rte_kni.ko carrier=on
    ./dpdk/dpdk-stable-20.11.1/usertools/dpdk-devbind.py -b uio_pci_generic  0000:00:09.0
    
    
    #修改配置文件,队列个数为1,并且关闭flow
    cp conf/dpvs.conf.single-nic.sample /etc/dpvs.conf
    ! netif config
    netif_defs {
        <init> pktpool_size     524287
        <init> pktpool_cache    256
    
        <init> device dpdk0 {
            rx {
                queue_number        1  -->flom 8 to 1
                descriptor_number   1024
                rss                 all
            }
            tx {
                queue_number        1  -->flom 8 to 1
                descriptor_number   1024
            }
            ! mtu                   1500
            ! promisc_mode
            kni_name                dpdk0.kni
        }
    }
    
    ! worker config (lcores)
    worker_defs {
        <init> worker cpu0 {
            type    master
            cpu_id  0
        }
    
        <init> worker cpu1 {
            type    slave
            cpu_id  1
            port    dpdk0 {
                rx_queue_ids     0
                tx_queue_ids     0
                ! isol_rx_cpu_ids  9
                ! isol_rxq_ring_sz 1048576
            }
        }
        -->只保留一个worker
    }
    
    ! ipvs config
    ipvs_defs {
        conn {
            <init> conn_pool_size       209715 -- from 2097152 to 209715
            <init> conn_pool_cache      256
            conn_init_timeout           3
            ! expire_quiescent_template
            ! fast_xmit_close
            ! <init> redirect           off
        }
        ...
    }
    
    ! sa_pool config
    sa_pool {
        pool_hash_size  16
        flow_enable     off --> from on to off
    }
    
    #运行dpvs
    ./src/dpvs
    

    检查运行结果

    #使用dpvs自带的dpip工具查看
    root@ubuntu:~/dpvs# ./tools/dpip/build/dpip link show
    1: dpdk0: socket 0 mtu 1500 rx-queue 1 tx-queue 1
        UP 1000 Mbps full-duplex auto-nego
        addr 08:00:27:F0:18:59 OF_RX_IP_CSUM OF_TX_IP_CSUM OF_TX_TCP_CSUM OF_TX_UDP_CSUM
    
    #使用ip命令查看,会有一个kni接口
    root@ubuntu:~/dpvs# ip link show
    ...
    32: dpdk0.kni: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    

    编译遇到的问题

    1. 按照官网步骤设置PKG_CONFIG_PATH后,执行make报错如下
    root@ubuntu:~/dpvs# export PKG_CONFIG_PATH=/root/dpvs/dpdk/dpdklib/lib/x86_64-linux-gnu/pkgconfig/libdpdk.pc
    root@ubuntu:~/dpvs# make
    for i in src tools; do make -C $i || exit 1; done
    make[1]: Entering directory '/root/dpvs/src'
    /root/dpvs/src//dpdk.mk:47: *** DPDK library was not found.
    If dpdk has installed already, please ensure the libdpdk.pc file could be found by `pkg-config`.
    You may fix the problem by setting LIBDPDKPC_PATH (in file src/dpdk.mk) to the path of libdpdk.pc file explicitly.  Stop.
    make[1]: Leaving directory '/root/dpvs/src'
    make: *** [Makefile:33: all] Error 1
    

    修改:PKG_CONFIG_PATH应该是*.pc所在目录,如下设置即可。
    export PKG_CONFIG_PATH=/root/dpvs/dpdk/dpdklib/lib/x86_64-linux-gnu/pkgconfig

    1. 没有numa头文件
    /root/dpvs/src/common.c:24:10: fatal error: numa.h: No such file or directory
       24 | #include <numa.h>
    

    修改:安装libnuma-dev即可。apt install libnuma-dev

    1. all warnings being treated as errors
    /root/dpvs/src/ipv4.c: In function ‘ipv4_rcv_fin’:
    /root/dpvs/src/ipv4.c:334:47: error: taking address of packed member of ‘struct rte_ipv4_hdr’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
      334 |     rt = route4_input(mbuf, (struct in_addr *)&iph->dst_addr,
          |                                               ^~~~~~~~~~~~~~
    /root/dpvs/src/ipv4.c:335:31: error: taking address of packed member of ‘struct rte_ipv4_hdr’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
      335 |             (struct in_addr *)&iph->src_addr,
          |                               ^~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    

    修改:src/Makefile 中加上 -Wno-address-of-packed-member
    CFLAGS += -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -Wno-address-of-packed-member -mcmodel=medium

    root@ubuntu:~/dpvs# make
    for i in src tools; do make -C $i || exit 1; done
    make[1]: Entering directory '/root/dpvs/src'
      ndisc.o
    cc -c -D DPVS_MAX_SOCKET=2 -D DPVS_MAX_LCORE=64 -D CONFIG_DPVS_FDIR -D CONFIG_DPVS_PDUMP -DALLOW_EXPERIMENTAL_API -include rte_config.h -march=native -I/root/dpvs/dpdk/dpdklib/include -D __DPVS__ -DDPVS_VERSION=\"1.9-0\" -DDPVS_BUILD_DATE=\"2021.11.01.07:14:13\" -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -Wno-address-of-packed-member -mcmodel=medium -Wno-format-truncation -Wno-stringop-truncation -Wstringop-overflow=0 -O3 -I /root/dpvs/src//../include /root/dpvs/src/ipv6/ndisc.c -o /root/dpvs/src/ipv6/ndisc.o
    In file included from /root/dpvs/src/ipv6/ndisc.c:29:
    /root/dpvs/src//../include/conf/neigh.h:48:1: error: alignment 1 of ‘struct dp_vs_neigh_conf’ is less than 2 [-Werror=packed-not-aligned]
       48 | }__attribute__((__packed__));
          | ^
    cc1: all warnings being treated as errors
    

    修改:src/Makefile 中加上 -Wno-packed-not-aligned
    CFLAGS += -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -Wno-address-of-packed-member -Wno-packed-not-aligned -mcmodel=medium

    1. 编译keepalived时报错如下
    check_data.c: In function ‘dump_forwarding_method’:
    check_data.c:368:33: error: ‘IP_VS_CONN_F_TUNNEL_TYPE_IPIP’ undeclared (first use in this function); did you mean ‘IP_VS_CONN_F_TUNNEL’?
      368 |             if (rs->tun_type == IP_VS_CONN_F_TUNNEL_TYPE_IPIP)
          |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                                 IP_VS_CONN_F_TUNNEL
    

    修改:注释掉下面两行

    if test $ac_have_decl = 1; then :
    
    
    #$as_echo "#define _HAVE_IPVS_TUN_TYPE_  1 " >>confdefs.h
    
    #      SYSTEM_OPTIONS="$SYSTEM_OPTIONS IPVS_TUN_TYPE"
    fi
    
    1. 缺少依赖库
    ipvsadm.c:114:10: fatal error: popt.h: No such file or directory
      114 | #include "popt.h"
          |          ^~~~~~~~
    

    修改:安装 apt-get install libpopt-dev

    1. 编译dpip报错
    route.c: In function ‘route6_dump’:
    route.c:148:27: error: taking address of packed member of ‘struct dp_vs_route6_conf’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
      148 |         if (ipv6_addr_any(&rt6_cfg->gateway))
    

    修改:修改dpip的makefile,添加CFLAGS += $(DEFS) -Wno-address-of-packed-member

    相关文章

      网友评论

          本文标题:在虚拟机编译运行dpvs

          本文链接:https://www.haomeiwen.com/subject/cppmhrtx.html