Monday, December 11, 2023

how vmware player run or develop with f-stack(dpdk)

 

f_stack office here

what is this:

    I develop in windows 11, wsl2 and hyper can not support virtual net interface for dpdk, so i installed VMware Workstation 17 Player in windows, and it installed ubuntu 22.04 in vmware to develop my c++ project with f-stack(dpdk). ide is vscode.

why select f_stack:

   no found ipv6 keywords in mtcp, so selected f_stack.


1. for my ubuntu 22.04 in VMware Workstation 17 Player

install 2 virtual net interfaces, 1 for normal, 2 bind for dpdk develop


> modify vmware net driver profile in windows file: {your vm os installed path}\Ubuntu 64.vmx

ethernet0.virtualDev = "vmxnet3"

ethernet1.virtualDev = "vmxnet3"

2. check out f-stack(with dpdk) in ubuntu 22.04

$ sudo -i 

$ git clone https://github.com/F-Stack/f-stack.git

2. prepare install tools

for first timer: 

$ apt-get install libnuma-dev python3 python3-pip meson -y && pip3 install pyelftools gawk gcc make libssl-dev pkg-config  

3. build and install

for dpdk:

$ cd f-stack/dpdk && meson --buildtype=debug -Denable_kmods=true -Ddisable_libs=flow_classify build --debug && ninja -C build && sudo ninja -C build install

(if for release opts: [--buildtype=release])


for f_stack:

for debug uncomment f-stack/lib/Makefile: 

DEBUG=-O0 -gdwarf-2 -g3 -Wno-format-truncation

Compile F-Stack

$ export FF_PATH=/home/lian/work/cppbot/third/repos/f-stack

$ export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/lib/pkgconfig

$ cd $FF_PATH/lib/

$ make

$ make install


prepare dpdk environment(run again after restart os):

$ cd f-stack/dpdk

$ echo 0 > /proc/sys/kernel/randomize_va_space 

$ echo 192 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

$ modprobe uio

$ insmod $(pwd)/build/kernel/linux/igb_uio/igb_uio.ko

$ insmod $(pwd)/build/kernel/linux/kni/rte_kni.ko carrier=on

$ mkdir -p /mnt/huge && sudo mount -t hugetlbfs nodev /mnt/huge


$ python3 usertools/dpdk-devbind.py --status

Network devices using kernel driver

===================================

0000:03:00.0 'VMXNET3 Ethernet Controller 07b0' if=ens160 drv=vmxnet3 unused=igb_uio *Active*

0000:0b:00.0 'VMXNET3 Ethernet Controller 07b0' if=ens192 drv=vmxnet3 unused=igb_uio *Active*


$ ifconfig ens192 down

$ python3 usertools/dpdk-devbind.py --bind=igb_uio ens192 

if your want revert to default driver:

$ python3 usertools/dpdk-devbind.py --bind=ens37 0000:0b:00.0

below is my vmware ubuntu normal route and net information:

$ route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0         192.168.136.2   0.0.0.0         UG    100    0        0 ens160

169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens160

192.168.136.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160

$ ifconfig

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.136.128  netmask 255.255.255.0  broadcast 192.168.136.255

        inet6 fe80::1039:ef57:1f16:fa53  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:a0:2e:30  txqueuelen 1000  (Ethernet)

        RX packets 33198  bytes 7402078 (7.4 MB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 34172  bytes 8247888 (8.2 MB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1000  (Local Loopback)

        RX packets 50593  bytes 9439452 (9.4 MB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 50593  bytes 9439452 (9.4 MB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ copy from f-stack/config.ini to your project, and change port0:

[port0]

addr=192.168.136.129

netmask=255.255.255.0

broadcast=192.168.136.255

gateway=192.168.136.2

must sure [port0] gateway network info like with normal route and ifconfig, else can not access internet. 

4. My little socket client connect code:


#define MAX_EVENTS 64

/* kevent set */

struct kevent kevSet;

/* events */

struct kevent events[MAX_EVENTS];

/* kq */

int kq;


memset(&kevSet, 0, sizeof(struct kevent));

memset(&events, 0, sizeof(struct kevent) * MAX_EVENTS);

kq = ff_kqueue();

 

ff_socket(domain, type, protocol);


ff_setsockopt(sockfd, level, optname, optval, (socklen_t)optlen);


ff_connect(fd, (struct linux_sockaddr *)addr, len);

 

EV_SET(&kevSet, fd, filter, EV_ADD, 0, 0, NULL);

res = ff_kevent(kq, &kevSet, 1, NULL, 0, NULL);

 

int do_loop_once() {

    short revents;

    int i, res, res2;

    socklen_t len;

    sdk_op op;

    pollfd* b,*e;

    timespec ts{0, 100'000'000}; // 100 ms

    kevent* event;


    if ( app_running ) { // not while

        res= ff_kevent(kq, NULL, 0, events, MAX_EVENTS, &ts);


        for (i = 0; i < res; ++i) {

            event = &events[i];


            op = op_none;

            res2 = 0;


            if(event->flags & (EV_EOF|EV_ERROR)){

                op = (sdk_op) (op | op_in | op_out);

                len = sizeof(res2);

                res2 = 0;

                ff_getsockopt(event->ident, SOL_SOCKET, SO_ERROR, &res2, &len);

                if(res2 == 0)

                    res2 = -1;

                else if(res2 > 0)

                    res2 = -res2;

            } else if (event->filter == EVFILT_READ) {

                op = (sdk_op) (op | op_in);

            } else if (event->filter == EVFILT_WRITE) {

                op = (sdk_op) (op | op_out);

            }

            // call cb(ctx, event->ident, op, res2);

        }


        if(res < 0)

            printf("poll ret faled: %d %s", res, error_to_string(res));


        //...

    }else{

        exit(-1); // dpdk loop is dead loop

    }

    return 0;

}


ff_run(do_loop_once, arg);


ff_recv(fd, buf, n, flags);


ff_send(fd, buf, n, flags);


X. Last

then develop your project, some net api likes ff_connect(),ff_xxx in f-stack/lib/ff_api.h, attention your app ip is 192.168.136.129.

Thanks.




Tuesday, November 20, 2018

txt2rss software publish

txt to rss software, it can start one rss server to response rss style content from txt file.

 useage 

put your multiple content to html/txt/{fileName}.txt, txt template your can see html/txt/1.txt, 

then access your url:

http://127.0.0.1:28081/rss/?file={fileName}

if your want random access rss item:

http://127.0.0.1:28081/rss/?random=1&file={fileName}

startup 


$ ./txt2rss

or custom bind address:
$ ./txt2rss -addr=127.0.0.1:28081


advance

usage this tool with pkrss: https://sourceforge.net/projects/pkrss/
add http://127.0.0.1:28081/rss/?file=1 to your custom rss source, then listen and see lyric in windows.

download

in here: https://github.com/pkrss/txt2rss/releases

Wednesday, June 20, 2018

china futures ctp realtime server docker image description

what
used this docker image,to receive china futures ctp realtime data.

How

1. docker:
docker image see: https://hub.docker.com/r/pkrss/ctp-market/

docker template:
    image: docker.io/pkrss/ctp-market:latest
    environment: (change below values if your need)
      - users.simnow.mdInvesterID="{your account id, liked 065206}"
      - users.simnow.mdInvesterPassword="{your simnow password}"
      - users.simnow.mdBrokerID="9999"
      - users.simnow.mdFrontAddr="tcp://218.202.237.33:10012"
      - users.simnow.mdInvesterPassword="tcp://218.202.237.33:10002"
      - sys_log_filePath=
      - sys_wsSrv_port=8086

2. web socket client:
websocket client docker ip:8086, send json string to regist realtime data:
{"cat": "quote","oper": "realtime", "data", {"stk":"*"}}
you can change * to your want symbol, liked: "rb1809".
After that your can receive multiple realtime data liked:
{"data":{"time":1529452800,"id":"rb1809","name":"螺纹钢1809","price":3911.0,"open":3850.0,"prevClose":3861.0,"close":null,"difVol":0,"vol":4810,"updnPrice":28,"updnPricePer":0.721,"positions":6408,"settlement":3881.0,"prevSettlement":3883.0,"high":3915.0,"low":3845.0,"buy1":3900.0,"sell1":3912.0,"buy1vol":5,"sell1vol":2},"cat":"quote","oper":"realtime"}


Last
Thanks!

Sunday, April 29, 2018

Error: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found

error:

root@DESKTOP-OLCMPRJ:/mnt/d/setup/download/0xbtcminer-linux_2.10.2$ ./0xbitcoin-miner
pkg/prelude/bootstrap.js:1172
      throw error;
      ^
Error: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /mnt/d/setup/download/0xbtcminer-linux_2.10.2/hybridminer.node)
    at Object.Module._extensions..node (module.js:668:18)
    at Module.load (module.js:558:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Module.require (module.js:583:17)
    at Module.require (pkg/prelude/bootstrap.js:1153:31)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/snapshot/0xbitcoin-gpuminer/0xbitcoinminer-accel.js:0:0)
    at Module._compile (pkg/prelude/bootstrap.js:1243:22)
    at Object.Module._extensions..js (module.js:650:10)

How:
Ubuntu:
wget http://ftp.de.debian.org/debian/pool/main/g/gcc-8/libstdc++6_8-20180425-1_amd64.debar -x libstdc++6_8-20180425-1_amd64.deb && tar xvJf data.tar.xzsudo cp usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25 /usr/lib
sudo mv /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.baksudo ln /usr/lib/libstdc++.so.6.0.25 /usr/lib/x86_64-linux-gnu/libstdc++.so.6


Last
Thanks

Tuesday, April 24, 2018

how to get cpp boost ptree json array root json string

Why
because default cpp boost ptree json not support root array json format.
there is so many other json parse engine on internet.
buy i want to reused boost ptree.

my code:
ptree r, r0, p1, p2;
ptree p0, p, c1, c2;

c1.put("c1a", "a");
c1.put("c1b", "b");
c2.put("c2a", "a");
c2.put("c2b", "b");

p.push_back(std::make_pair("", c1));
p.push_back(std::make_pair("", c2));
p0.push_back(std::make_pair("", p));
std::string s;
std::stringstream ss;
write_json(ss, p0);
s = ss.str();



i want to get below string format:
[
   {...},
   {...}
  ]


but boost ptree generate string like this:
{
  "":[
   {...},
   {...}
  ]
}

How:
remove string above of '[' and after ']':
std::string getJArrayString(const ptree& p) {
ptree p0;
p0.push_back(std::make_pair("", p));

std::stringstream ss;
write_json(ss, p0);
std::string s = ss.str();

do {
auto b = s.find_first_of('[');
if (b == std::string::npos)
break;

auto e = s.find_last_of(']');
if (e == std::string::npos)
break;
s = s.substr(b, e + 1 - b);

return s;
} while (false);

return "[]";

}

and call this:

ptree r, r0, p1, p2;
ptree p0, p, c1, c2;

c1.put("c1a", "a");
c1.put("c1b", "b");
c2.put("c2a", "a");
c2.put("c2b", "b");

p.push_back(std::make_pair("", c1));
p.push_back(std::make_pair("", c2));
p0.push_back(std::make_pair("", p));
std::string s = getJArrayString(p0);

Sunday, April 22, 2018

fixed error to get the value of VCTargetsPath:



Error:
E:\work\git\third\grpc\grpc\.build>cmake .. -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE=Release
CMake Error at CMakeLists.txt:31 (project):
  Failed to run MSBuild command:
    MSBuild.exe
  to get the value of VCTargetsPath:
    system can not find the file specified.

How fixed it:

open "Developer Command Prompt for VS 2017" in start menu. or it's content is:
%comspec% /k "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"

Last:
 can run now. 

2018 q2 crypto coin research and test draft

1. gift.one
one airdrop crypto coin, test start in 2018.4.20

Gift.ONE, the global biggest airdrop organization of cryptocurrency, is airdropping million Tokens! 1GIFT = US$0.2,get 100GIFT by registration, Gain more 100000GIFT from any activities, Click link to get GIFT: https://gift.one/i/yPaX3s Win lottery for iPhoneX、BTC、ETH、GIFT everyday!

2. wait...