mirror of
https://github.com/openp2p-cn/openp2p.git
synced 2025-11-03 02:33:25 +08:00
3.18.4 virtual private network
This commit is contained in:
@@ -41,14 +41,14 @@ func TestAllInputFormat(t *testing.T) {
|
||||
|
||||
func TestSingleIP(t *testing.T) {
|
||||
iptree := NewIPTree("")
|
||||
iptree.Add("219.137.185.70", "219.137.185.70")
|
||||
iptree.Add("219.137.185.70", "219.137.185.70", nil)
|
||||
wrapTestContains(t, iptree, "219.137.185.70", true)
|
||||
wrapTestContains(t, iptree, "219.137.185.71", false)
|
||||
}
|
||||
|
||||
func TestWrongSegment(t *testing.T) {
|
||||
iptree := NewIPTree("")
|
||||
inserted := iptree.Add("87.251.75.0", "82.251.75.255")
|
||||
inserted := iptree.Add("87.251.75.0", "82.251.75.255", nil)
|
||||
if inserted {
|
||||
t.Errorf("TestWrongSegment failed\n")
|
||||
}
|
||||
@@ -57,20 +57,20 @@ func TestWrongSegment(t *testing.T) {
|
||||
func TestSegment2(t *testing.T) {
|
||||
iptree := NewIPTree("")
|
||||
iptree.Clear()
|
||||
iptree.Add("10.1.5.50", "10.1.5.100")
|
||||
iptree.Add("10.1.1.50", "10.1.1.100")
|
||||
iptree.Add("10.1.2.50", "10.1.2.100")
|
||||
iptree.Add("10.1.6.50", "10.1.6.100")
|
||||
iptree.Add("10.1.7.50", "10.1.7.100")
|
||||
iptree.Add("10.1.3.50", "10.1.3.100")
|
||||
iptree.Add("10.1.1.1", "10.1.1.10") // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250") // no interset
|
||||
iptree.Add("10.1.5.50", "10.1.5.100", nil)
|
||||
iptree.Add("10.1.1.50", "10.1.1.100", nil)
|
||||
iptree.Add("10.1.2.50", "10.1.2.100", nil)
|
||||
iptree.Add("10.1.6.50", "10.1.6.100", nil)
|
||||
iptree.Add("10.1.7.50", "10.1.7.100", nil)
|
||||
iptree.Add("10.1.3.50", "10.1.3.100", nil)
|
||||
iptree.Add("10.1.1.1", "10.1.1.10", nil) // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250", nil) // no interset
|
||||
iptree.Print()
|
||||
|
||||
iptree.Add("10.1.1.80", "10.1.1.90") // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60") // interset
|
||||
iptree.Add("10.1.1.80", "10.1.1.90", nil) // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60", nil) // interset
|
||||
iptree.Print()
|
||||
iptree.Add("10.1.1.90", "10.1.1.110") // interset
|
||||
iptree.Add("10.1.1.90", "10.1.1.110", nil) // interset
|
||||
iptree.Print()
|
||||
t.Logf("ipTree size:%d\n", iptree.Size())
|
||||
wrapTestContains(t, iptree, "10.1.1.40", true)
|
||||
@@ -87,7 +87,7 @@ func TestSegment2(t *testing.T) {
|
||||
wrapTestContains(t, iptree, "10.1.100.30", false)
|
||||
wrapTestContains(t, iptree, "10.1.200.30", false)
|
||||
|
||||
iptree.Add("10.0.0.0", "10.255.255.255") // will merge all segment
|
||||
iptree.Add("10.0.0.0", "10.255.255.255", nil) // will merge all segment
|
||||
iptree.Print()
|
||||
if iptree.Size() != 1 {
|
||||
t.Errorf("merge ip segment error\n")
|
||||
@@ -98,17 +98,17 @@ func TestSegment2(t *testing.T) {
|
||||
func BenchmarkBuildipTree20k(t *testing.B) {
|
||||
iptree := NewIPTree("")
|
||||
iptree.Clear()
|
||||
iptree.Add("10.1.5.50", "10.1.5.100")
|
||||
iptree.Add("10.1.1.50", "10.1.1.100")
|
||||
iptree.Add("10.1.2.50", "10.1.2.100")
|
||||
iptree.Add("10.1.6.50", "10.1.6.100")
|
||||
iptree.Add("10.1.7.50", "10.1.7.100")
|
||||
iptree.Add("10.1.3.50", "10.1.3.100")
|
||||
iptree.Add("10.1.1.1", "10.1.1.10") // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250") // no interset
|
||||
iptree.Add("10.1.1.80", "10.1.1.90") // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60") // interset
|
||||
iptree.Add("10.1.1.90", "10.1.1.110") // interset
|
||||
iptree.Add("10.1.5.50", "10.1.5.100", nil)
|
||||
iptree.Add("10.1.1.50", "10.1.1.100", nil)
|
||||
iptree.Add("10.1.2.50", "10.1.2.100", nil)
|
||||
iptree.Add("10.1.6.50", "10.1.6.100", nil)
|
||||
iptree.Add("10.1.7.50", "10.1.7.100", nil)
|
||||
iptree.Add("10.1.3.50", "10.1.3.100", nil)
|
||||
iptree.Add("10.1.1.1", "10.1.1.10", nil) // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250", nil) // no interset
|
||||
iptree.Add("10.1.1.80", "10.1.1.90", nil) // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60", nil) // interset
|
||||
iptree.Add("10.1.1.90", "10.1.1.110", nil) // interset
|
||||
var minIP uint32
|
||||
binary.Read(bytes.NewBuffer(net.ParseIP("10.1.1.1").To4()), binary.BigEndian, &minIP)
|
||||
|
||||
@@ -116,13 +116,13 @@ func BenchmarkBuildipTree20k(t *testing.B) {
|
||||
nodeNum := uint32(10000 * 1)
|
||||
gap := uint32(10)
|
||||
for i := minIP; i < minIP+nodeNum*gap; i += gap {
|
||||
iptree.AddIntIP(i, i)
|
||||
iptree.AddIntIP(i, i, nil)
|
||||
// t.Logf("ipTree size:%d\n", iptree.Size())
|
||||
}
|
||||
binary.Read(bytes.NewBuffer(net.ParseIP("100.1.1.1").To4()), binary.BigEndian, &minIP)
|
||||
// insert 100k block ip segment
|
||||
for i := minIP; i < minIP+nodeNum*gap; i += gap {
|
||||
iptree.AddIntIP(i, i+5)
|
||||
iptree.AddIntIP(i, i+5, nil)
|
||||
}
|
||||
t.Logf("ipTree size:%d\n", iptree.Size())
|
||||
iptree.Clear()
|
||||
@@ -132,17 +132,17 @@ func BenchmarkQuery(t *testing.B) {
|
||||
ts := time.Now()
|
||||
iptree := NewIPTree("")
|
||||
iptree.Clear()
|
||||
iptree.Add("10.1.5.50", "10.1.5.100")
|
||||
iptree.Add("10.1.1.50", "10.1.1.100")
|
||||
iptree.Add("10.1.2.50", "10.1.2.100")
|
||||
iptree.Add("10.1.6.50", "10.1.6.100")
|
||||
iptree.Add("10.1.7.50", "10.1.7.100")
|
||||
iptree.Add("10.1.3.50", "10.1.3.100")
|
||||
iptree.Add("10.1.1.1", "10.1.1.10") // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250") // no interset
|
||||
iptree.Add("10.1.1.80", "10.1.1.90") // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60") // interset
|
||||
iptree.Add("10.1.1.90", "10.1.1.110") // interset
|
||||
iptree.Add("10.1.5.50", "10.1.5.100", nil)
|
||||
iptree.Add("10.1.1.50", "10.1.1.100", nil)
|
||||
iptree.Add("10.1.2.50", "10.1.2.100", nil)
|
||||
iptree.Add("10.1.6.50", "10.1.6.100", nil)
|
||||
iptree.Add("10.1.7.50", "10.1.7.100", nil)
|
||||
iptree.Add("10.1.3.50", "10.1.3.100", nil)
|
||||
iptree.Add("10.1.1.1", "10.1.1.10", nil) // no interset
|
||||
iptree.Add("10.1.1.200", "10.1.1.250", nil) // no interset
|
||||
iptree.Add("10.1.1.80", "10.1.1.90", nil) // all in
|
||||
iptree.Add("10.1.1.40", "10.1.1.60", nil) // interset
|
||||
iptree.Add("10.1.1.90", "10.1.1.110", nil) // interset
|
||||
var minIP uint32
|
||||
binary.Read(bytes.NewBuffer(net.ParseIP("10.1.1.1").To4()), binary.BigEndian, &minIP)
|
||||
|
||||
@@ -150,20 +150,20 @@ func BenchmarkQuery(t *testing.B) {
|
||||
nodeNum := uint32(10000 * 1000)
|
||||
gap := uint32(10)
|
||||
for i := minIP; i < minIP+nodeNum*gap; i += gap {
|
||||
iptree.AddIntIP(i, i)
|
||||
iptree.AddIntIP(i, i, nil)
|
||||
// t.Logf("ipTree size:%d\n", iptree.Size())
|
||||
}
|
||||
binary.Read(bytes.NewBuffer(net.ParseIP("100.1.1.1").To4()), binary.BigEndian, &minIP)
|
||||
// insert 100k block ip segment
|
||||
for i := minIP; i < minIP+nodeNum*gap; i += gap {
|
||||
iptree.AddIntIP(i, i+5)
|
||||
iptree.AddIntIP(i, i+5, nil)
|
||||
}
|
||||
t.Logf("ipTree size:%d cost:%dms\n", iptree.Size(), time.Since(ts)/time.Millisecond)
|
||||
ts = time.Now()
|
||||
// t.ResetTimer()
|
||||
queryNum := 100 * 10000
|
||||
for i := 0; i < queryNum; i++ {
|
||||
iptree.ContainsInt(minIP + uint32(i))
|
||||
iptree.Load(minIP + uint32(i))
|
||||
wrapBenchmarkContains(t, iptree, "10.1.5.55", true)
|
||||
wrapBenchmarkContains(t, iptree, "10.1.1.1", true)
|
||||
wrapBenchmarkContains(t, iptree, "10.1.5.200", false)
|
||||
|
||||
Reference in New Issue
Block a user