Code Monkey home page Code Monkey logo

bitradix's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitradix's Issues

Errors and wrong values with masks (bits) smaller than 2

During the use of the bitradix library, I encountered several problems using masks smaller than 0, there is maybe a problem in how the first bit is handled or how the root of the tree is initialized.

mask == 0
I added a default route 0.0.0.0/0 and checked serveral routes. Routes with the first bit set to 1 will fail:

	AddRoute 0.0.0.0/0 (00000000000000000000000000000000), AS 10
	(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 0): 00000000000000000000000000000000/0 -> 10
	( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	Search       230.0.0.1/32 11100110000000000000000000000001/32
	Expected 10, got %!d(<nil>) for 230.0.0.1/32s
	Search       10.20.1.2/32 00001010000101000000000100000010/32
	Search       10.21.0.1/32 00001010000101010000000000000001/32
	Search     192.168.2.3/32 11000000101010000000001000000011/32
	Expected 10, got %!d(<nil>) for 192.168.2.3/32s

mask == 1
Also a split range case produces a strange tree:

	AddRoute 0.0.0.0/1 (00000000000000000000000000000000), AS 10
	AddRoute 128.0.0.0/1 (10000000000000000000000000000000), AS 20
	(-1): 00000000000000000000000000000000/1 -> 10
	( 0): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 1): 10000000000000000000000000000000/1 -> 20
	Search       10.20.1.2/32 00001010000101000000000100000010/32
	Expected 10, got %!d(<nil>) for 10.20.1.2/32s
	Search       10.21.0.1/32 00001010000101010000000000000001/32
	Expected 10, got %!d(<nil>) for 10.21.0.1/32s
	Search     192.168.2.3/32 11000000101010000000001000000011/32
	Search       230.0.0.1/32 11100110000000000000000000000001/32

mask >= 2
(works as expected)

	AddRoute 0.0.0.0/2 (00000000000000000000000000000000), AS 10
	AddRoute 64.0.0.0/2 (01000000000000000000000000000000), AS 20
	AddRoute 128.0.0.0/2 (10000000000000000000000000000000), AS 30
	AddRoute 255.0.0.0/2 (11000000000000000000000000000000), AS 41
	(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 0): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 0): 00000000000000000000000000000000/2 -> 10
	( 1): 01000000000000000000000000000000/2 -> 20
	( 0): 10000000000000000000000000000000/2 -> 30
	( 1): 11000000000000000000000000000000/2 -> 41
	Search       10.44.2.2/32 00001010001011000000001000000010/32
	Search    100.44.231.1/32 01100100001011001110011100000001/32
	Search      140.44.0.3/32 10001100001011000000000000000011/32
	Search      210.44.1.1/32 11010010001011000000000100000001/32

Does anyone have an idea how to solve this problem?

Wrong values for using the same key with different masks

If routes have the same key but different ranges, the first route will be removed from the tree (or overwritten), but if and only if the range of the previous rule was larger than the range of the newer rule:

OK

	AddRoute 10.0.0.0/14 (00001010000000000000000000000000), AS 11
	AddRoute 10.20.0.0/14 (00001010000101000000000000000000), AS 20
	AddRoute 10.0.0.2/8 (00001010000000000000000000000000), AS 10

NOT OK
This case produces wrong values for routes matching only the route with a larger range.:

	AddRoute 10.0.0.2/8 (00001010000000000000000000000000), AS 10
	AddRoute 10.0.0.0/14 (00001010000000000000000000000000), AS 11
	AddRoute 10.20.0.0/14 (00001010000101000000000000000000), AS 20
	(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 0): 00001010000000000000000000000000/14 -> 11
	( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
	( 0): 00001010000101000000000000000000/14 -> 20
	Search        10.1.0.1/32 00001010000000010000000000000001/32
	Search       10.20.1.2/32 00001010000101000000000100000010/32
	Search       10.19.0.1/32 00001010000100110000000000000001/32
	Expected 10, got 0 for 10.19.0.1/32  -- (10.19.0.1/32 should be in AS 10 - 10.0.0.2/8 but was 0)

Was the insert() function designed to work like this?

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.