0:安装环境基础命令(vmware+ubuntu 16)
hlp@ubuntu:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.7 LTS Release: 16.04 Codename: xenial #环境安装前 sudo apt-get update sudo apt-get upgrade sudo apt-get install python //sudo apt install python-is-python3 sudo apt-get install build-essential sudo apt-get install make sudo apt-get install cmake sudo apt-get install libnuma-dev #修改网卡名称 #修改grub配置文件 GRUB_CMDLINE_LINUX_DEFAULT sudo vi /etc/default/grub net.ifnames=0 biosdevname=0 default_hugepages=1G hugepagesz=2M hugepages=1024 isolcpus=0-2 sudo update-grub #修改使网卡生效 sudo vi /etc/network/interfaces #sudo service networking restart #配置文件中信息,对应四个网络适配器,都显示 auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet dhcp auto eth2 iface eth2 inet dhcp auto eth3 iface eth3 inet dhcp #关机,在虚拟机中增加内存和处理器 ===》一定要做,可能导致环境启动不起来 #重启环境 可以用ifoncig查看网卡,已经生效 #修改虚拟机配置文件,使支持多队列网卡 ==》文本打卡虚拟机.vmx文件 ethernet1.virtualDev = "vmxnet3" ethernet1.wakeOnPcktRcv = "TRUE" #重启环境后,查看是否生效 cat /proc/interrupts |grep eth #把多队列网卡改成桥接方式启动吧,适合我们的dpdk环境测试(数据纯净) 修改虚拟机配置后重启服务就好 sudo service networking restart #安装dpdk环境 tar xvf dpdk-19.08.2.tar.xz #切换到su权限 sudo passwd root su root@ubuntu:/home/hlp/dpdk/dpdk-stable-19.08.2# ./usertools/dpdk-setup.sh #选择自己环境对应的编号进行编译目标交叉环境 这里我是ubuntu 64 选择39 #配置环境变量: export RTE_SDK=/home/hlp/dpdk/dpdk-stable-19.08.2 export RTE_TARGET=x86_64-native-linux-gcc #插入运行需要的各个模块 43, 44, 45 #使用uio模块(vmxnet3)进行绑定网卡 填入网卡对应的标识 一定要关闭状态 ifconfig eth0 down 49 0000:03:00.0 #对环境进行测试 53 7 show port info 0 #测试helloword ./build/helloworld -l 0-7 -n 8
1:DNS(域名系统)
将域名和ip相互映射,一般用于域名解析,使用udp端口53.
域名按层尽心管理,域名由’.'进行划分,最后一个.省略,默认由根管理。
全球由13个域名进行管理,(很多个服务器)管理所有节点。
输入一个网址(域名),首先会查找浏览器缓存,
dns有一些type类型,决定了dns报文的处理,如A记录
、AAAA记录
、CNAME记录
、MX记录
、NS记录
、TXT记录
、SRV记录
、URL转发
。
看到b站大佬的视频:DNS域名解析过程_哔哩哔哩_bilibili
hlp@ubuntu:~$ nslookup www.baidu.com Server: 192.168.0.1 Address: 192.168.0.1#53 Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 14.215.177.38 Name: www.a.shifen.com Address: 14.215.177.39 hlp@ubuntu:~$ nslookup www.bilibili.com Server: 192.168.0.1 Address: 192.168.0.1#53 Non-authoritative answer: www.bilibili.com canonical name = b.w.bilicdn1.com. Name: b.w.bilicdn1.com Address: 119.3.211.130 Name: b.w.bilicdn1.com Address: 119.3.238.64 Name: b.w.bilicdn1.com Address: 119.3.227.169 Name: b.w.bilicdn1.com Address: 119.3.231.166 Name: b.w.bilicdn1.com Address: 119.3.229.89 Name: b.w.bilicdn1.com Address: 119.3.234.165 #学习一下从根域名解析ip的流程 hlp@ubuntu:~$ nslookup > set type=ns #设置域名解析服务器记录 进行查看 > . #查看根域名服务记录 Server: 192.168.0.1 Address: 192.168.0.1#53 Non-authoritative answer: #中间缓存 不权威的 . nameserver = m.root-servers.net. . nameserver = a.root-servers.net. . nameserver = l.root-servers.net. . nameserver = c.root-servers.net. . nameserver = d.root-servers.net. . nameserver = k.root-servers.net. . nameserver = j.root-servers.net. . nameserver = e.root-servers.net. . nameserver = g.root-servers.net. . nameserver = f.root-servers.net. . nameserver = b.root-servers.net. . nameserver = i.root-servers.net. . nameserver = h.root-servers.net. Authoritative answers can be found from: a.root-servers.net internet address = 198.41.0.4 b.root-servers.net internet address = 199.9.14.201 c.root-servers.net internet address = 192.33.4.12 d.root-servers.net internet address = 199.7.91.13 e.root-servers.net internet address = 192.203.230.10 f.root-servers.net internet address = 192.5.5.241 g.root-servers.net internet address = 192.112.36.4 h.root-servers.net internet address = 198.97.190.53 i.root-servers.net internet address = 192.36.148.17 j.root-servers.net internet address = 192.58.128.30 k.root-servers.net internet address = 193.0.14.129 l.root-servers.net internet address = 199.7.83.42 m.root-servers.net internet address = 202.12.27.33 a.root-servers.net has AAAA address 2001:503:ba3e::2:30 b.root-servers.net has AAAA address 2001:500:200::b > set type=a #设置类型为a 查找ip > a.root-servers.net. #查看其中一个域名节点的ip Server: 192.168.0.1 Address: 192.168.0.1#53 Non-authoritative answer: Name: a.root-servers.net Address: 198.41.0.4 > server 198.41.0.4 #设置域名服务器 Default server: 198.41.0.4 Address: 198.41.0.4#53 > set type=ns #查看根域名服务器 > com. #在根域名服务器下请求,查看会发现只会去我们设置的server进行 Server: 198.41.0.4 Address: 198.41.0.4#53 Non-authoritative answer: *** Can't find com.: No answer Authoritative answers can be found from: com nameserver = a.gtld-servers.net. com nameserver = b.gtld-servers.net. com nameserver = c.gtld-servers.net. com nameserver = d.gtld-servers.net. com nameserver = e.gtld-servers.net. com nameserver = f.gtld-servers.net. com nameserver = g.gtld-servers.net. com nameserver = h.gtld-servers.net. com nameserver = i.gtld-servers.net. com nameserver = j.gtld-servers.net. com nameserver = k.gtld-servers.net. com nameserver = l.gtld-servers.net. com nameserver = m.gtld-servers.net. a.gtld-servers.net internet address = 192.5.6.30 b.gtld-servers.net internet address = 192.33.14.30 c.gtld-servers.net internet address = 192.26.92.30 d.gtld-servers.net internet address = 192.31.80.30 e.gtld-servers.net internet address = 192.12.94.30 f.gtld-servers.net internet address = 192.35.51.30 g.gtld-servers.net internet address = 192.42.93.30 h.gtld-servers.net internet address = 192.54.112.30 i.gtld-servers.net internet address = 192.43.172.30 j.gtld-servers.net internet address = 192.48.79.30 k.gtld-servers.net internet address = 192.52.178.30 l.gtld-servers.net internet address = 192.41.162.30 m.gtld-servers.net internet address = 192.55.83.30 a.gtld-servers.net has AAAA address 2001:503:a83e::2:30 b.gtld-servers.net has AAAA address 2001:503:231d::2:30 > server 192.5.6.30 Default server: 192.5.6.30 Address: 192.5.6.30#53 > set type=ns #测试一个实际的域名 > bilibili.com Server: 192.5.6.30 Address: 192.5.6.30#53 Non-authoritative answer: *** Can't find bilibili.com: No answer Authoritative answers can be found from: bilibili.com nameserver = ns3.dnsv5.com. bilibili.com nameserver = ns4.dnsv5.com. ns3.dnsv5.com internet address = 129.211.176.212 ns3.dnsv5.com internet address = 162.14.18.188 ns3.dnsv5.com internet address = 162.14.24.251 ns3.dnsv5.com internet address = 162.14.25.251 ns3.dnsv5.com internet address = 18.194.2.137 ns3.dnsv5.com internet address = 183.192.201.94 ns3.dnsv5.com internet address = 223.166.151.16 ns3.dnsv5.com has AAAA address 2402:4e00:1430:1102:0:9136:2b2b:ba61 ns3.dnsv5.com internet address = 52.77.238.92 ns3.dnsv5.com internet address = 61.151.180.51 ns4.dnsv5.com internet address = 101.226.220.12 ns4.dnsv5.com internet address = 129.211.176.151 ns4.dnsv5.com internet address = 162.14.24.248 ns4.dnsv5.com internet address = 162.14.25.248 ns4.dnsv5.com internet address = 183.192.164.119 ns4.dnsv5.com internet address = 223.166.151.126 ns4.dnsv5.com has AAAA address 2402:4e00:1020:1264:0:9136:29b6:fc32 ns4.dnsv5.com internet address = 52.198.159.146 ns4.dnsv5.com internet address = 59.36.120.147 > server 129.211.176.212 #设置com对应的顶级域名服务器 Default server: 129.211.176.212 Address: 129.211.176.212#53 > set type=a #设置类型为a,查找对应ip > www.bilibili.com. #查看ip,找到对应的内容分发域名 Server: 129.211.176.212 Address: 129.211.176.212#53 www.bilibili.com canonical name = b.w.bilicdn1.com. > b.w.bilicdn1.com. #查看内容分发域名对应的ip,即是我们需要的ip Server: 129.211.176.212 Address: 129.211.176.212#53 Name: b.w.bilicdn1.com Address: 119.3.211.130 Name: b.w.bilicdn1.com Address: 119.3.231.166 Name: b.w.bilicdn1.com Address: 119.3.238.64 Name: b.w.bilicdn1.com Address: 119.3.229.89 Name: b.w.bilicdn1.com Address: 119.3.234.165 Name: b.w.bilicdn1.com Address: 119.3.227.169 #这里获得的ip就会返回给我们本地的dns服务器并且缓存,发送给我们浏览器输入域名时,对应的程序,用ip进行实际请求。
ip和子网掩码:ip分为主机号和网络号,与子网掩码配合区分网络区域及网络。
2:dns实现
dns是基于udp实现的。
参考udp的协议头以及dns的协议头,构造对应的头结构,对DNS服务器进行数据请求,要能正常获取到返回的ip。
dns的测试思路:
===》直接使用udp socket api进行数据请求,构造符合dns协议的结构数据即可,
===》解析收到的udp回复报文数据。获取到需要的ip即可。
dns的协议头如下:
相关结构定义及协议栈对应如下:
直接请求固定的dns域名服务器114.114.114.114:53,构造请求报文,,解析获取到的报文获取ip即可,测试代码运行如下:
3:两个dns开源git库代码
3.1:dnspod-sr
简单使用,后期进行学习:
#编译并运行 root@ubuntu:/home/hlp/othertest/dnspod-sr-master/src# ./dnspod-sr [DBG:] dnspod-sr is successfully running now!! [DBG:] max_ele_size is 1000000 - 1808 [DBG:] server may contain 332730 useful records [DBG:] hash_table_size is 65536 [DBG:] we have 10 hash tables [DBG:] we have 2 fetchers,2 quizzers #在另外一个环境上用dig命令进行测试,dns服务器有学习的功能 root@ubuntu:/home/hlp# dig @192.168.105.143 www.bilibili.com ; <<>> DiG 9.10.3-P4-Ubuntu <<>> @192.168.105.143 www.bilibili.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8662 ;; flags: qr ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.bilibili.com. IN A ;; ANSWER SECTION: www.bilibili.com. 214 IN CNAME b.w.bilicdn1.com. b.w.bilicdn1.com. 104 IN A 120.92.113.99 b.w.bilicdn1.com. 104 IN A 120.92.108.182 b.w.bilicdn1.com. 104 IN A 120.92.83.126 b.w.bilicdn1.com. 104 IN A 120.92.82.179 b.w.bilicdn1.com. 104 IN A 120.92.211.159 b.w.bilicdn1.com. 104 IN A 120.131.2.207 b.w.bilicdn1.com. 104 IN A 120.92.78.97 ;; Query time: 2951 msec ;; SERVER: 192.168.105.143#53(192.168.105.143) ;; WHEN: Sat Dec 25 16:50:18 CST 2021 ;; MSG SIZE rcvd: 173
使用dnsperf测试性能:
#安装dnsperf https://gitee.com/mirrors_DNS-OARC/dnsperf?_from=gitee_search #注意按照第一种方式 版本包的安装,我用源码安装时有报错 #安装包下载地址https://www.dns-oarc.net/tools/dnsperf tar -xvf dnsperf-2.9.0.tar.gz cd dnsperf-2.9.0 ./configure make make install #写个配置文件 如下 root@ubuntu:/home/hlp/othertest/dnsperf-2.9.0# cat testfile www.baidu.com A www.bilibili.com A #执行测试,可以分析结果 ./src/dnsperf -d testfile -s 192.168.105.143 -c10000 -q10000 -l60
3.2: simpleDNS
直接去git中找到该库下载:https://github.com/mwarning/SimpleDNS.git
启动该代码可执行文件,用dig请求进行查看:
#dig @192.168.105.143 -p 9000 foo.bar.com A ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8362 ;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;foo.bar.com. IN A ;; ANSWER SECTION: foo.bar.com. 3600 IN A 192.168.1.1 #这个是测试代码中写死的域名(foo.bar.com)对应的ip ;; Query time: 0 msec ;; SERVER: 192.168.105.143#9000(192.168.105.143) ;; WHEN: Sat Dec 25 22:07:24 CST 2021 ;; MSG SIZE rcvd: 56
4:dpdk-dns
上述的接口,我们建立在内核处理udp协议栈的基础上(dns相当于udp的数据)。
===》使用dpdk提供的接口,接管udp的数据,对dns相关的请求做协议处理。
===》参考simpleDNS逻辑,在已有的dpdk处理arp,udp, tcp的逻辑基础上,增加udp报文时,dns相关数据的处理。
===》参考simpleDNS中的逻辑进行业务处理返回。
===》仅供测试实例
(这里是初步预习学习,相关代码只是使用,再编码)