how to run EuhatOfp

create three vmware guest machine for example,
ip of no.1 guest machine is 192.168.204.33
ip of no.2 guest machine is 192.168.204.34
ip of no.3 guest machine is 192.168.204.35

setup dpdk in every machine, all script and binary is in setup directory, refer to <5. setup dpdk> in

compile ofp over dpdk in vmware

modify test/servers.cfg

1
2
3
192.168.204.33:8061
192.168.204.34:8062
192.168.204.35:8063

for every guest machine modify self ip setting in test/ofp_netwrap.cli

1
2
3
debug 0
loglevel set debug
ifconfig fp0 192.168.204.33/24

in no.1 guest machine

1
2
cd test
./release/test 0

in no.2 guest machine

1
2
cd test
./release/test 1

in no.3 guest machine

1
2
cd test
./release/test 2

then you can check the log files in test/log directory.

how to build EuhatOfp

EuhatOfp is a library for peer to peers communication framework through user space tcp stack, now implemented in OFP over DPDK.

1. build ofp over dpdk

compile ofp over dpdk in vmware

2. build EuhatOfp

1
git clone https://github.com/euhat/EuhatOfp.git

modify the paths of dpdk, odp-dpdk and ofp in test/Makefile.

1
2
3
cd test
make clean
make

compile ofp over dpdk in vmware

1. get software

1
2
git libtool automake build-essential pkg-config libssl-dev doxygen libconfig-dev libnuma-dev libpcap-dev net-tools
ln -s /usr/bin/python3 /usr/bin/python

2. compile dpdk

1
git clone http://dpdk.org/git/dpdk-stable --branch 19.11 --depth 1 dpdk-19.11

run dpdk-19.11/usertools/dpdk-setup.sh
>>> select and run "x86_64-native-linuxapp-gcc"
>>> Exit Script

3. compile odp-dpdk

1
git clone https://github.com/OpenDataPlane/odp-dpdk.git

odp-dpdk/m4/odp_dpdk.m4

1
2
3
4
5
6
7
8
9
10
11
12
13
# _ODP_DPDK_LEGACY(PATH, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
# ------------------------------------------------------------------------
# Locate DPDK installation
AC_DEFUN([_ODP_DPDK_LEGACY], [dnl
    DPDK_CFLAGS="-isystem $1/include"
    DPDK_LIB_PATH="$1/lib"
    DPDK_LDFLAGS="-L$DPDK_LIB_PATH"
    AS_IF([test -r "$DPDK_LIB_PATH"/libdpdk.so], [dnl
        DPDK_RPATH="-Wl,-rpath,$DPDK_LIB_PATH"
        DPDK_RPATH_LT="-R$DPDK_LIB_PATH"
        DPDK_SHARED=yes],
        [test ! -r "$DPDK_LIB_PATH"/libdpdk.a], [dnl
        AC_MSG_FAILURE([Could not find DPDK])])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
 
DPDK_PATH=/home/eu/work/dpdk/dpdk-19.11/x86_64-native-linuxapp-gcc
 
cd odp-dpdk
./bootstrap
#--enable-debug --enable-debug-print
#--without-openssl
./configure --with-dpdk-path=${DPDK_PATH} \
                --prefix=`pwd`/installed \
                --enable-debug=full \
                --enable-helper-debug \
                --enable-debug-print \
                --enable-helper-debug-print \
                --disable-shared
make install

4. compile ofp

1
git clone https://github.com/OpenFastPath/ofp.git
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh
 
ODP_DPDK_PATH=`pwd`/odp-dpdk/installed
 
cd ofp
./bootstrap
./configure --with-odp=${ODP_DPDK_PATH} \
        --with-odp-lib=odp-dpdk \
        --disable-shared \
        --enable-debug=yes \
        --enable-sp=no \
        --prefix=`pwd`/installed
make install

5. setup dpdk

1
2
3
4
cd dpdk-19.11/x86_64-native-linuxapp-gcc/kmod
modprobe uio
insmod igb_uio.ko
ifconfig ens33 down

run dpdk-19.11/usertools/dpdk-setup.sh
>>> select and run "Setup hugepage mappings for non-NUMA systems", enter 128
>>> select and run "Bind Ethernet/Baseband/Crypto device to IGB UIO module", will display like
0000:02:01.0 '82545EM Gigabit Ethernet Controller (Copper) 100f' if=ens33 drv=e1000 unused=igb_uio,vfio-pci
>>>>>> enter 02:01.0
>>> Exit Script

6. test

let the vmware guest machine use NAT.

use ipconfig check ip settings in host machine. for example, my ip for "VMware Network Adapter VMnet8" is 192.168.204.1.

ofp/example/webserver/ofp.cli

1
2
3
debug 0
loglevel set debug
ifconfig fp0 192.168.204.33/24

ofp/example/webserver/www/aa.txt

1
Hello, the world!

ofp/example/webserver/run.sh

1
2
export www_dir=`pwd`/www
./webserver -i 0 -f ofp.cli

using web browser access

1
http://192.168.204.33:2048/aa.txt

ipad充电变绿色但长时间电量不长

ipad插上充电后,屏幕右上角电池图标显示为绿色,但这样放着过了两三个小时,电量还是不长!

大概由于天气冷的原因。

解决方法,我称之谓点火充电。就是使ipad处在插电充电状态时,在ipad里运行一个3d游戏之类的app,这样cpu和gpu都处于高速运转状态,ipad很快会升温,过几分钟看看电量百分比长没长,正常情况是会长几个百分比的,这时要么一直让3d游戏跑着,要么关掉ipad,将ipad用被子盖好,就这么一直插线充电。

从频率角度说明音程的和协性

从频率角度讲,C与高一个八度的C相差2倍。一个八度被分成12项的等比数列,公比为2^(1/12),即2的12分之一次方。
以下是各音的国际标准频率值

1
2
3
4
5
6
7
C - do - 261.6 Hz
D - re - 293.6 Hz
E - mi - 329.6 Hz
F - fa - 349.2 Hz
G - so - 392 Hz
A - la - 440 Hz
B - si - 493.8 Hz

在钢琴键盘上可以看到,C与F相差5个半音,C与G相差7个半音,我们来验算一下

1
2
3
4
5
6
7
>>> import numpy as np
>>> 261.6 * np.power(2, 5/12)
349.19410585088104 # F - 349.2 Hz
>>> 261.6 * np.power(2, 7/12)
391.95713131093993 # G - 392 Hz
>>> 261.6 * np.power(2, 9/12)
439.95700446074346 # A - 440 Hz

乐理中说

1
2
3
八度(12个半音)极完全协和
纯四度(5个半音)、纯五度(7个半音)完全协和
三全音(6个半音)不协和

为什么纯四度、纯五度协和呢?
两个音之所以协和,是因为彼此之间是简单的倍数关系,如八度是2倍的关系。
纯四度是2^(5/12)倍关系,纯五度是2^(7/12)倍关系,不是简单倍数啊!
其实,2^(5/12)约等于1+1/3即4/3,2^(7/12)约等于1+1/2即3/2
我们在python中验算一下

1
2
3
4
5
6
7
8
>>> np.power(2, 5/12)
1.3348398541700344
>>> 1+1/3
1.3333333333333333
>>> np.power(2, 7/12)
1.4983070768766815
>>> 1+1/2
1.5

另外,
1+1/5即6/5靠近2^(3/12),所以相隔小三度(3个半音)比如C键与Eb键同时发声时不难听;
1+1/4即5/4靠近2^(4/12),所以相隔大三度(4个半音)比如C键与E键同时按下不难听;
1+2/3即5/3靠近2^(9/12),所以相隔大六度(9个半音)比如C键与A键同时发声时不难听。
这是三和弦、七和弦存在的理论前提。

而三全音是2^(6/12)倍即根号2倍的关系,是无理数,所以不协和,如C键与F#键同时按下,或者F键和B键同时按下就难听。

我们举一个生活中的例子,我们拉直一根弦,这时我们把此弦看成数轴,原点在固定弦一端的地方,随便手捏住弦的另一处,弹此弦定为C音,手捏的点则为数轴上刻度为1的位置;再手捏的刻度为4/3处则发出F(fa)音;手捏的刻度为3/2处发出G(so)音;手捏的刻度为2处发出高一个八度的C音;而手捏刻度为1/2处发出的是低八度的C音。

ofp segment fault的原因

1. 创建线程不要直接用pthread_create,而要用odph_odpthreads_create。
2. 每个线程函数的开始处都要调用ofp_init_local初始化。
3. 之前调用系统socket和epoll之类的函数都要替换成ofp定义的,包括宏和结构体。如

1
2
//	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	sock = ofp_socket(OFP_AF_INET, OFP_SOCK_STREAM, OFP_IPPROTO_TCP);

ofp中的慢平面

默认编译OpenFastPath时慢平面是启用的,慢平面的功能之一是通过netlink方式向内核查询路由表,这是用内核公开的接口,不需要另开发内核驱动。

慢平面的一个局限,比方电脑只有一张网卡,而这块网卡已被dpdk绑定,网络包就不会在内核中被解析,此时慢平面的路由功能也就无效,所以干脆通过

1
./configure ... --enable-sp=no

将慢平面功能去掉。

而此时我们跑在ofp上的应用就没有路由表了么?
不是的。首先应用的本机ip地址是通过

1
myApp -i 0 -f ofp.cli

中的ofp.cli配置的。如

1
2
3
debug 0
loglevel set debug
ifconfig fp0 192.168.56.33/24

中的192.168.56.33就是本机地址。
而通过arp协议获取其它机器ip与mac关系的路由表是由

1
	ofp_start_cli_thread(instance, app_init_params.linux_core_id, params.cli_file);

这个线程在dpdk绑定的网卡上进行解析维护。

一个很好的例子就是ofp/example/webserver。

ofp和dpdk都可完全编译成静态库运行,不要为了LD_PRELOAD的那一点便利一门心思去编译出动态库。在自已的源码中加一层宏翻译,静态库与epoll api兼容性也很好。

github上的odp与dpdk-odp的区别是前者现在只包含了odp-linux,一种对linux系统api的包装,后者是对dpdk的包装,所以高性能选后者。原话见
doc/users-guide/users-guide.adoc

refer to:
https://github.com/OpenFastPath/ofp
https://github.com/OpenDataPlane/odp-dpdk
https://my.oschina.net/u/4361425/blog/3269917

odp禁止ipsec

1
2
3
4
5
6
7
8
9
10
11
12
13
	odp_init_t init_param;
 
	odp_init_param_init(&init_param);
	init_param.not_used.feat.ipsec = 1;
	init_param.not_used.feat.crypto = 1;
	init_param.not_used.feat.compress = 1;
	init_param.not_used.feat.tm = 1;
 
	if (0 != odp_init_global(&instance, &init_param, NULL))
	{
		DBG(("init odp global failed.\n"));
		return 0;
	}