github.com/sagernet/netlink@v0.0.0-20240612041022-b9a21c07ac6a/gtp_test.go (about) 1 //go:build linux 2 // +build linux 3 4 package netlink 5 6 import ( 7 "net" 8 "testing" 9 ) 10 11 func TestPDPv0AddDel(t *testing.T) { 12 tearDown := setUpNetlinkTestWithKModule(t, "gtp") 13 defer tearDown() 14 15 if err := LinkAdd(testGTPLink(t)); err != nil { 16 t.Fatal(err) 17 } 18 link, err := LinkByName("gtp0") 19 if err != nil { 20 t.Fatal(err) 21 } 22 err = GTPPDPAdd(link, &PDP{ 23 PeerAddress: net.ParseIP("1.1.1.1"), 24 MSAddress: net.ParseIP("2.2.2.2"), 25 TID: 10, 26 }) 27 if err != nil { 28 t.Fatal(err) 29 } 30 list, err := GTPPDPList() 31 if err != nil { 32 t.Fatal(err) 33 } 34 if len(list) != 1 { 35 t.Fatal("Failed to add v0 PDP") 36 } 37 pdp, err := GTPPDPByMSAddress(link, net.ParseIP("2.2.2.2")) 38 if err != nil { 39 t.Fatal(err) 40 } 41 if pdp == nil { 42 t.Fatal("failed to get v0 PDP by MS address") 43 } 44 pdp, err = GTPPDPByTID(link, 10) 45 if err != nil { 46 t.Fatal(err) 47 } 48 if pdp == nil { 49 t.Fatal("failed to get v0 PDP by TID") 50 } 51 err = GTPPDPDel(link, &PDP{TID: 10}) 52 if err != nil { 53 t.Fatal(err) 54 } 55 list, err = GTPPDPList() 56 if err != nil { 57 t.Fatal(err) 58 } 59 if len(list) != 0 { 60 t.Fatal("Failed to delete v0 PDP") 61 } 62 } 63 64 func TestPDPv1AddDel(t *testing.T) { 65 tearDown := setUpNetlinkTestWithKModule(t, "gtp") 66 defer tearDown() 67 68 if err := LinkAdd(testGTPLink(t)); err != nil { 69 t.Fatal(err) 70 } 71 link, err := LinkByName("gtp0") 72 if err != nil { 73 t.Fatal(err) 74 } 75 err = GTPPDPAdd(link, &PDP{ 76 PeerAddress: net.ParseIP("1.1.1.1"), 77 MSAddress: net.ParseIP("2.2.2.2"), 78 Version: 1, 79 ITEI: 10, 80 OTEI: 10, 81 }) 82 if err != nil { 83 t.Fatal(err) 84 } 85 list, err := GTPPDPList() 86 if err != nil { 87 t.Fatal(err) 88 } 89 if len(list) != 1 { 90 t.Fatal("Failed to add v1 PDP") 91 } 92 pdp, err := GTPPDPByMSAddress(link, net.ParseIP("2.2.2.2")) 93 if err != nil { 94 t.Fatal(err) 95 } 96 if pdp == nil { 97 t.Fatal("failed to get v1 PDP by MS address") 98 } 99 pdp, err = GTPPDPByITEI(link, 10) 100 if err != nil { 101 t.Fatal(err) 102 } 103 if pdp == nil { 104 t.Fatal("failed to get v1 PDP by ITEI") 105 } 106 err = GTPPDPDel(link, &PDP{Version: 1, ITEI: 10}) 107 if err != nil { 108 t.Fatal(err) 109 } 110 list, err = GTPPDPList() 111 if err != nil { 112 t.Fatal(err) 113 } 114 if len(list) != 0 { 115 t.Fatal("Failed to delete v1 PDP") 116 } 117 }