(http://doc.dpdk.org/guides/sample_app_ug/l3_forward.html)
使用hash路由
基于流的路由。流由五元组(protocol, sip, dip, sport, dport)定义。输入一个流,输出的是output端口(网卡)。
hash转发表是静态定义的。
使用LPM(Longest Prefix Match)路由
转发表是在程序中静态定义的:
static struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {
{IPv4(1, 1, 1, 0), 24, 0},
{IPv4(2, 1, 1, 0), 24, 1},
{IPv4(3, 1, 1, 0), 24, 2},
{IPv4(4, 1, 1, 0), 24, 3},
{IPv4(5, 1, 1, 0), 24, 4},
{IPv4(6, 1, 1, 0), 24, 5},
{IPv4(7, 1, 1, 0), 24, 6},
{IPv4(8, 1, 1, 0), 24, 7},
};
收到packet后,使用packet的目标IP在LPM转发表中查找,获取下一跳的output端口。
测试步骤
client1 <-----> l3fwd <----------> client2
./l3fwd -cf -- -p 0x3 --config="(0,0,1),(1,0,2)" --parse-ptype --eth-dest=0,00:0c:29:6b:7d:68 --eth-dest=1,00:0c:29:fc:42:2f
--eth-dest设置的是port对接的client的mac地址。不设置这个地址,l3fwd会用02:00:00:00:00:01填充包的dmac,导致不通。
client需要使用1.1.1.0/24和2.1.1.0/24。并且设置静态路由和静态arp。设置路由时网关IP可以随便写,arp的目标mac要写成l3fwd的对应口mac。