Code Monkey home page Code Monkey logo

router's Introduction

router

For exp3, use the following command to generate rip executable file:

g++ rip.cpp -orip -O2 -lpthread -DRIP_MAIN

# RUN:
./rip

The rip output log may seem like this:

get 192.168.  4.  1	iface enp7s0
get 172. 16.  9.  1	iface vmnet1
get 172. 16.181.  1	iface vmnet8
get 192.168.  3.  2	iface enx000ec6aa5f42
-----------------------------------------------------
   |        Network       |   Nexthop Addr  | Metric 
-----------------------------------------------------
 C | 192.168.  4.  1 / 24 |   0.  0.  0.  0 |    1
 C |   3.  0.  0.  0 / 24 |   0.  0.  0.  0 |   16
 C | 172. 16.  9.  1 / 24 |   0.  0.  0.  0 |    1
 C | 172. 16.181.  1 / 24 |   0.  0.  0.  0 |    1
 C | 192.168.  3.  2 / 24 |   0.  0.  0.  0 |    1
-----------------------------------------------------
send to 192.168.  4.  1 succeed! packet len: 64
send to 172. 16.  9.  1 succeed! packet len: 64
send to 172. 16.181.  1 succeed! packet len: 64
send to 192.168.  3.  2 succeed! packet len: 64
receive len: 64	cmd: 2	ver: 2	from 192.168.3.1
get 192.168.  4.  1	iface enp7s0
get 172. 16.  9.  1	iface vmnet1
get 172. 16.181.  1	iface vmnet8
get 192.168.  3.  2	iface enx000ec6aa5f42
-----------------------------------------------------
   |        Network       |   Nexthop Addr  | Metric 
-----------------------------------------------------
 C | 192.168.  4.  1 / 24 |   0.  0.  0.  0 |    1
 C |   3.  0.  0.  0 / 24 |   0.  0.  0.  0 |   16
 C | 172. 16.  9.  1 / 24 |   0.  0.  0.  0 |    1
 C | 172. 16.181.  1 / 24 |   0.  0.  0.  0 |    1
 C | 192.168.  3.  2 / 24 |   0.  0.  0.  0 |    1
 R | 192.168.  1.  0 / 24 | 192.168.  3.  1 |    2
 R | 192.168.198.  0 / 24 | 192.168.  3.  1 |    3
 R | 192.168. 10.  0 / 24 | 192.168.  3.  1 |    3
-----------------------------------------------------
--- 192.168.  1.  0/24 192.168.  3.  1
--- 192.168.198.  0/24 192.168.  3.  1
--- 192.168. 10.  0/24 192.168.  3.  1
send to 192.168.  4.  1 succeed! packet len: 124
send to 172. 16.  9.  1 succeed! packet len: 124
send to 172. 16.181.  1 succeed! packet len: 124
send to 192.168.  3.  2 succeed! packet len: 64
--- 192.168.  1.  0/24 192.168.  3.  1
--- 192.168.198.  0/24 192.168.  3.  1
--- 192.168. 10.  0/24 192.168.  3.  1
receive len: 24	cmd: 1	ver: 2	from 192.168.4.2
send to 192.168.  4.  1 succeed! packet len: 144
--- 192.168.  1.  0/24 192.168.  3.  1
--- 192.168.198.  0/24 192.168.  3.  1
--- 192.168. 10.  0/24 192.168.  3.  1
get 192.168.  4.  1	iface enp7s0
get 172. 16.  9.  1	iface vmnet1
get 172. 16.181.  1	iface vmnet8
get 192.168.  3.  2	iface enx000ec6aa5f42

For exp4, just type mv lookuproute_simple.cpp.bak lookuproute.cpp; make -j and run sudo ./main.

由于为了后续性能,把输出的部分给注释掉了。

Additional exp

编译:直接 make -j

就写了个哈希边表,每次从/32查到/1,看看有没有对应的路由表项

可以理解为我开了32个数组,但是存的时候存得紧凑了点

该算法代码位于 lookuproute.cpp 中,不到30行(后面常数优化了一波,循环展开,做到差不多和4位trie一样快了,代码翻了一倍)

事实上是/32到/13存hash,/12到/1直接数组存下来

如果要单独测试性能的话:

mv test.cpp.bak test.cpp
g++ test.cpp lookuproute.cpp -oa -O2
# insert 1000 and query 10^7
time ./a 10000000

本机i7-8750H差不多0.27s,找了个i7-7700HQ大概0.45s

router's People

Contributors

trinkle23897 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.