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