1# GTPv2 unit tests 2# 3# Type the following command to launch start the tests: 4# $ test/run_tests -P "load_contrib('gtp_v2')" -t test/contrib/gtp_v2.uts 5 6+ GTPv2 7 8= GTPHeader v2, basic instantiation 9gtp = IP()/UDP(dport=2123)/GTPHeader(gtp_type=1) 10gtp.dport == 2123 and gtp.gtp_type == 1 11 12= GTPV2EchoRequest, basic instantiation 13gtp = IP()/UDP(dport=2123) / GTPHeader(seq=12345) / GTPV2EchoRequest() 14gtp.dport == 2123 and gtp.seq == 12345 and gtp.gtp_type == 1 and gtp.T == 0 15 16= GTPV2CreateSessionRequest, basic instantiation 17gtp = IP() / UDP(dport=2123) / \ 18 GTPHeader(gtp_type="create_session_req", teid=2807, seq=12345) / \ 19 GTPV2CreateSessionRequest(IE_list=[IE_IMSI(IMSI=b'001030000000356'),IE_APN(APN=b'super')]) 20 21assert gtp.dport == 2123 and gtp.teid == 2807 and gtp.seq == 12345 22ie = gtp.IE_list[1] 23assert ie.APN == b"super" 24 25= GTPV2EchoRequest, dissection 26h = "333333333333222222222222810080c808004588002937dd0000fd1115490a2a00010a2a0002084b084b00152d0e4001000900000100030001000daa000000003f1f382f" 27gtp = Ether(hex_bytes(h)) 28gtp.gtp_type == 1 29 30= GTPV2EchoResponse, dissection 31h = "3333333333332222222222228100e384080045fc002fd6d70000f21180d40a2a00010a2a0002084b084b001b00004002000f000001000300010001020002001000731cd7c5" 32gtp = Ether(hex_bytes(h)) 33gtp.gtp_type == 2 34 35= GTPV2ModifyBearerRequest, dissection 36h = "3333333333332222222222228100a384080045b8004300000000fc1185350a2a00010a2a00027a76084b002f6c344822002392e9e1143652540052000100065d00120049000100055700090080000010927f000002ac79a28e" 37gtp = Ether(hex_bytes(h)) 38gtp.gtp_type == 34 39 40= IE_IMSI, dissection 41h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd00000000661759000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100235700090385000010927f00000250001600580700000000000000000000000000000000000000007200020040005311004c" 42gtp = Ether(hex_bytes(h)) 43ie = gtp.IE_list[0] 44ie.IMSI == b"2080112345670000" 45 46= IE_IMSI, basic instantiation 47ie = IE_IMSI(ietype='IMSI', length=8, IMSI='2080112345670000') 48ie.ietype == 1 and ie.IMSI == b'2080112345670000' 49assert bytes(ie) == b'\x01\x00\x08\x00\x02\x08\x112Tv\x00\x00' 50 51= IE_Cause, dissection 52h = "3333333333332222222222228100838408004588004a00000000fd1193160a2a00010a2a0002084b824600366a744823002a45e679235ea151000200020010005d001800490001006c0200020010005700090081000010927f000002558d3b69" 53gtp = Ether(hex_bytes(h)) 54ie = gtp.IE_list[0] 55ie.Cause == 16 56 57= IE_Cause, basic instantiation 58ie = IE_Cause( 59 ietype='Cause', length=2, Cause='Request accepted', PCE=1, BCE=0, CS=0) 60ie.ietype == 2 and ie.Cause == 16 and ie.PCE == 1 and ie.BCE == 0 and ie.CS == 0 61 62= IE_Cause, basic instantiation 2 63ie = IE_Cause( 64 ietype='Cause', length=2, Cause='Request accepted', PCE=0, BCE=1, CS=0) 65ie.ietype == 2 and ie.Cause == 16 and ie.PCE == 0 and ie.BCE == 1 and ie.CS == 0 66 67= IE_Cause, basic instantiation 3 68ie = IE_Cause( 69 ietype='Cause', length=2, Cause='Request accepted', PCE=0, BCE=0, CS=1) 70ie.ietype == 2 and ie.Cause == 16 and ie.PCE == 0 and ie.BCE == 0 and ie.CS == 1 71 72= IE_RecoveryRestart, dissection 73h = "3333333333332222222222228100838408004588002937dd0000fd1115490a2a00010a2a0002084b084b00152d0e400100095e4b1f00030001000daa000000003f1f382f" 74gtp = Ether(hex_bytes(h)) 75ie = gtp.IE_list[0] 76ie.ietype == 3 and ie.restart_counter == 13 77 78= IE_RecoveryRestart, basic instantiation 79ie = IE_RecoveryRestart( 80 ietype='Recovery Restart', length=1, restart_counter=17) 81ie.ietype == 3 and ie.restart_counter == 17 82 83= IE_APN, dissection 84h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 85gtp = Ether(hex_bytes(h)) 86ie = gtp.IE_list[7] 87ie.APN == b'aaaaaaaaaaaaaaaaaaaaaaaaa' 88 89= IE_APN, basic instantiation 90ie = IE_APN(ietype='APN', length=26, APN='aaaaaaaaaaaaaaaaaaaaaaaaa') 91ie.ietype == 71 and ie.APN == b'aaaaaaaaaaaaaaaaaaaaaaaaa' 92assert bytes(ie) == b'G\x00\x1a\x00\x19aaaaaaaaaaaaaaaaaaaaaaaaa' 93 94= IE_AMBR, dissection 95h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 96gtp = Ether(hex_bytes(h)) 97ie = gtp.IE_list[11] 98ie.AMBR_Uplink == 5888 and ie.AMBR_Downlink == 42000 99 100= IE_AMBR, basic instantiation 101ie = IE_AMBR( 102 ietype='AMBR', length=8, AMBR_Uplink=5888, AMBR_Downlink=42000) 103ie.ietype == 72 and ie.AMBR_Uplink == 5888 and ie.AMBR_Downlink == 42000 104 105= IE_EPSBearerID, dissection 106h = "3333333333332222222222228100838408004580006d00000000f31180d20a2a00010a2a0002084b85930059e49a4823004d55819f6500ede7000200020010004c000600111111111111490001003248000800000061a8000249f07f000100005d001300490001000b0200020010005e00040039004f454a0004007f00000436f73a63" 107gtp = Ether(hex_bytes(h)) 108ie = gtp.IE_list[2] 109ie.EBI == 50 110 111= IE_EPSBearerID, basic instantiation 112ie = IE_EPSBearerID(ietype='EPS Bearer ID', length=1, EBI=50) 113ie.ietype == 73 and ie.EBI == 50 114 115= IE_IP_Address, dissection 116h = "3333333333332222222222228100838408004580006d00000000f31180d20a2a00010a2a0002084b85930059e49a4823004d84530d5a4cdee2000200020010004c00060011111111111149000100b248000800000061a8000249f07f000100005d00130049000100da0200020010005e00040039004f454a0004007f00000436f73a63" 117gtp = Ether(hex_bytes(h)) 118ie = gtp.IE_list[6] 119ie.address == '127.0.0.4' 120 121= IE_IP_Address, basic instantiation 122ie = IE_IP_Address(ietype='IP Address', length=4, address='127.0.0.4') 123ie.ietype == 74 and ie.address == '127.0.0.4' 124 125= IE_MEI, dissection 126h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b00080071655774980786ff56000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 127gtp = Ether(hex_bytes(h)) 128ie = gtp.IE_list[1] 129ie.MEI == b"17567547897068" 130 131= IE_MEI, basic instantiation 132ie = IE_MEI(ietype='MEI', length=1, MEI=175675478970685) 133ie.ietype == 75 and ie.MEI == 175675478970685 134 135= IE_MSISDN, dissection 136h = "3333333333332222222222228100838408004580006d00000000f31180d20a2a00010a2a0002084b85930059e49a4823004d55819f6500ede7000200020010004c000600111111111111490001003248000800000061a8000249f07f000100005d001300490001000b0200020010005e00040039004f454a0004007f00000436f73a63" 137gtp = Ether(hex_bytes(h)) 138ie = gtp.IE_list[1] 139ie.digits == b'111111111111' 140 141= IE_MSISDN, basic instantiation 142ie = IE_MSISDN(ietype='MSISDN', length=6, digits='111111111111') 143ie.ietype == 76 and ie.digits == b'111111111111' 144assert bytes(ie) == b'L\x00\x06\x00\x11\x11\x11\x11\x11\x11' 145 146= IE_Indication, dissection 147h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b00080071655774980786ff56000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 148gtp = Ether(hex_bytes(h)) 149ie = gtp.IE_list[10] 150ie.DAF == 0 and ie.DTF == 0 and ie.PS == 1 and ie.CCRSI == 0 and ie.CPRAI == 0 and ie.PPON == 0 and ie.CLII == 0 and ie.CPSR == 0 151 152= IE_Indication, basic instantiation 153ie = IE_Indication(ietype='Indication', length=8, PS=1, CPRAI=1) 154ie.ietype == 77 and ie.PS == 1 and ie.CPRAI == 1 155 156= IE_Indication, basic instantiation 2 157ie = IE_Indication(ietype='Indication', length=8, DTF=1, PPSI=1) 158ie.ietype == 77 and ie.DTF == 1 and ie.PPSI == 1 159 160= IE_PCO, dissection 161h = "333333333333222222222222810083840800458800a500000000fd1183bb0a2a00010a2a0002084b76a00091cf0b48210085bd574af24c68e300020002001000570009008b000010927f0000025700090187000010927f0000024f000500017f0000037f000100004e00220080000d040a2a0003000d040a2a00038021100300001081060a2a000483060a2a00045d00250049000100660200020010005700090081000010927f0000025700090285000010927f000002dd9f22c6" 162gtp = Ether(hex_bytes(h)) 163ie = gtp.IE_list[5] 164ie.Protocols[0].address == '10.42.0.3' 165 166= IE_PCO, basic instantiation 167ie = IE_PCO(ietype='Protocol Configuration Options', length=8, Extension=1, PPP=3, Protocols=[ 168 PCO_DNS_Server_IPv4(type='DNS Server IPv4 Address Request', length=4, address='10.42.0.3')]) 169ie.Extension == 1 and ie.PPP == 3 and ie.Protocols[0].address == '10.42.0.3' 170 171= IE_EPCO, dissection 172h = "d89ef3da40e2fa163e956dce08004500003000010000401144e10a0f0f3d0a0f1281084b084b001c0c154821000c0000000100000100c500040080001b00" 173gtp = Ether(hex_bytes(h)) 174ie = gtp.IE_list[0] 175ie.Protocols[0].type == 27 176 177= IE_EPCO, basic instantiation 178ie = IE_EPCO(Protocols=[PCO_S_Nssai(type=27, length=0)], ietype=197, length=4, CR_flag=0, instance=0, Extension=1, SPARE=0, PPP=0) 179ie.Extension == 1 and ie.ietype == 197 and ie.Protocols[0].type == 27 and ie.Protocols[0].length == 0 180 181= IE_APCO, dissection 182h = "d89ef3da40e2fa163e956dce0800450000360001000040115d650a0f0f3d01020304084b084b00220000482000160000000100000100a3000a0080000c00001200000d00" 183gtp = Ether(hex_bytes(h)) 184ie = gtp.IE_list[0] 185ie.Protocols[0].type == 12 and ie.Protocols[1].type == 18 and ie.Protocols[2].type == 13 186 187= IE_APCO, basic instantiation 188ie = IE_APCO(Protocols=[PCO_P_CSCF_IPv4_Address_Request(address=None, type=12, length=0),PCO_P_CSCF_Re_selection_Support(type=18, length=0),PCO_DNS_Server_IPv4(address=None, type=13, length=0)], ietype=163, length=10, CR_flag=0, instance=0, extension=1, SPARE=0, PPP=0) 189ie.extension == 1 and ie.ietype == 163 and ie.length == 10 and ie.Protocols[0].type == 12 and ie.Protocols[1].type == 18 and ie.Protocols[2].type == 13 190 191= IE_MMContext_EPS, dissection 192h = "d89ef3da40e2fa163e956dce08004500007f0001000040114bbd0a0a0f3d0a0f0b5b084b084b006b5a234883005f0000180f76d163006b0046008800910000020000021890aa80be385102083701a2907066f8bd9f2a28b717671c71c71c71c71c71c70100003d090002625a00028040000812345678900000000000000000006d000900880005000470677731" 193gtp = Ether(hex_bytes(h)) 194ie = gtp.IE_list[0] 195ie.Sec_Mode == 4 and ie.Nhi == 0 and ie.Drxi == 1 and ie.Ksi == 0 and ie.Num_quint == 0 and ie.Num_Quad == 0 and ie.Uambri == 0 and ie.Osci == 0 and ie.Sambri == 1 and ie.Nas_algo == 1 and ie.Nas_cipher == 1 and ie.Nas_dl_count == 2 and ie.Nas_ul_count == 2 and ie.Kasme == 11111111111111111111111111111111111111111111111111111111111111111111111111111 196 197= IE_MMContext_EPS, basic instantiation 198ie = IE_MMContext_EPS(ietype=107, length=70, CR_flag=0, instance=0, Sec_Mode=4, Nhi=0, Drxi=1, Ksi=0, Num_quint=0, Num_Quad=0, Uambri=0, Osci=0, Sambri=1, Nas_algo=1, Nas_cipher=1, Nas_dl_count=2, Nas_ul_count=2, Kasme=11111111111111111111111111111111111111111111111111111111111111111111111111111) 199ie.Sec_Mode == 4 and ie.Nhi == 0 and ie.Drxi == 1 and ie.Ksi == 0 and ie.Num_quint == 0 and ie.Num_Quad == 0 and ie.Uambri == 0 and ie.Osci == 0 and ie.Sambri == 1 and ie.Nas_algo == 1 and ie.Nas_cipher == 1 and ie.Nas_dl_count == 2 and ie.Nas_ul_count == 2 and ie.Kasme == 11111111111111111111111111111111111111111111111111111111111111111111111111111 200 201= IE_PDNConnection, IE_FQDN, dissection 202h = "d89ef3da40e2fa163e956dce08004500007f0001000040114bbd0a0a0f3d0a0f0b5b084b084b006b5a234883005f0000180f76d163006b0046008800910000020000021890aa80be385102083701a2907066f8bd9f2a28b717671c71c71c71c71c71c70100003d090002625a00028040000812345678900000000000000000006d000900880005000470677731" 203gtp = Ether(hex_bytes(h)) 204ie = gtp.IE_list[1].IE_list[0] 205ie.fqdn_tr_bit == 4 and ie.fqdn == b'pgw1' 206 207= IE_PDNConnection, IE_FQDN, basic instantiation 208ie = IE_PDNConnection(IE_list=[IE_FQDN(ietype=136, length=5, CR_flag=0, instance=0, fqdn_tr_bit=4, fqdn=b'pgw1')], ietype=109, length=9, CR_flag=0, instance=0) 209ie2 = ie.IE_list[0] 210ie2.fqdn_tr_bit == 4 and ie2.fqdn == b'pgw1' 211 212= IE_PAA, dissection 213h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 214gtp = Ether(hex_bytes(h)) 215ie = gtp.IE_list[9] 216ie.PDN_type == 1 and ie.ipv4 == '127.0.0.3' 217 218= IE_PAA, basic instantiation 219ie = IE_PAA(ietype='PAA', length=5, PDN_type='IPv4', ipv4='127.0.0.3') 220ie.ietype == 79 and ie.PDN_type == 1 and ie.ipv4 == '127.0.0.3' 221 222= IE_Bearer_QoS, dissection 223h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 224gtp = Ether(hex_bytes(h)) 225ie = gtp.IE_list[12].IE_list[2] 226ie.MaxBitRateForUplink == 0 and ie.MaxBitRateForDownlink == 0 and ie.QCI == 7 227 228= IE_Bearer_QoS, basic instantiation 229ie = IE_Bearer_QoS(ietype='Bearer QoS', length=22, PCI=4, PriorityLevel=5, PVI=6, QCI=7, 230 MaxBitRateForUplink=1, MaxBitRateForDownlink=2, GuaranteedBitRateForUplink=3, GuaranteedBitRateForDownlink=4) 231ie.ietype == 80 and ie.PCI == 4 and ie.PriorityLevel == 5 and ie.PVI == 6 and ie.QCI == 7 and ie.MaxBitRateForUplink == 1 and ie.MaxBitRateForDownlink == 2 and ie.GuaranteedBitRateForUplink == 3 and ie.GuaranteedBitRateForDownlink == 4 232 233= IE_RAT, dissection 234h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 235gtp = Ether(hex_bytes(h)) 236ie = gtp.IE_list[4] 237ie.RAT_type == 6 238 239= IE_RAT, basic instantiation 240ie = IE_RAT(ietype='RAT', length=1, RAT_type='EUTRAN') 241ie.ietype == 82 and ie.RAT_type == 6 242 243= IE_ServingNetwork, dissection 244h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 245gtp = Ether(hex_bytes(h)) 246ie = gtp.IE_list[3] 247ie.MCC == b'234' and ie.MNC == b'02' 248 249= IE_ServingNetwork, basic instantiation 250ie = IE_ServingNetwork( 251 ietype='Serving Network', length=3, MCC='234', MNC='02') 252ie.ietype == 83 and ie.MCC == b'234' and ie.MNC == b'02' 253 254= IE_ULI, dissection 255h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 256gtp = Ether(hex_bytes(h)) 257ie = gtp.IE_list[2] 258ie.TAI_Present == 1 and ie.ECGI_Present == 1 and ie.TAI.MCC == b'234' and ie.TAI.MNC == b'02' and ie.TAI.TAC == 12345 and ie.ECGI.MCC == b'234' and ie.ECGI.MNC == b'02' and ie.ECGI.ECI == 123456 259 260= IE_ULI, basic instantiation 261ie = IE_ULI(ietype='ULI', length=13, LAI_Present=0, ECGI_Present=1, TAI_Present=1, RAI_Present=0, SAI_Present=0, 262 CGI_Present=0, TAI=ULI_TAI(MCC='234', MNC='02', TAC=12345), ECGI=ULI_ECGI(MCC='234', MNC='02', ECI=123456)) 263ie.ietype == 86 and ie.LAI_Present == 0 and ie.ECGI_Present == 1 and ie.TAI_Present == 1 and ie.RAI_Present == 0 and ie.SAI_Present == 0 and ie.CGI_Present == 0 and ie.TAI.MCC == b'234' and ie.TAI.MNC == b'02' and ie.TAI.TAC == 12345 and ie.ECGI.MCC == b'234' and ie.ECGI.MNC == b'02' and ie.ECGI.ECI == 123456 264 265= IE_UCI, dissection 266h = "fe1d70fa717ceeeeeeeeeeee080045000127a4f500003c11e9aec0a8ee80c0a87f50084b23a301131aa1482001070000000001020f009100080021f3540000001602" 267gtp = Ether(hex_bytes(h)) 268ie = gtp.IE_list[0] 269ie.CSG_ID == 22 and ie.AccessMode == 0 and ie.LCSG == 1 and ie.CMI == 0 and ie.MCC == b'123' and ie.MNC == b'45' 270 271= IE_UCI, basic instantiation 272ie = IE_UCI(ietype='UCI', length=8, CR_flag=0, instance=0, MCC=b'123', MNC=b'45', SPARE1=0, SPARE2=0, CSG_ID=22, AccessMode=0, LCSG=1, CMI=0) 273ie.ietype == 145 and ie.CSG_ID == 22 and ie.AccessMode == 0 and ie.LCSG == 1 and ie.CMI == 0 and ie.MCC == b'123' and ie.MNC == b'45' 274 275= IE_BearerFlags, dissection 276h = "0026f126c100000c29b131dd81004d040800450000d8a6010000401118680a2180350a212735084b138800c47f8248210011000023f2000001005d006200610001000a" 277gtp = Ether(hex_bytes(h)) 278ie = gtp.IE_list[0].IE_list[0] 279ie.ASI == 1 and ie.Vind == 0 and ie.VB == 1 and ie.PPC == 0 280 281= IE_BearerFlags, basic instantiation 282ie = IE_BearerFlags(ietype='Bearer Flags', length=1, CR_flag=0, instance=0, SPARE=0, ASI=1, Vind=0, VB=1, PPC=0) 283ie.ietype == 97 and ie.ASI == 1 and ie.Vind == 0 and ie.VB == 1 and ie.PPC == 0 284 285= IE_UPF_SelInd_Flags, dissection 286h = "000c29b131dd0026f126c10081000d04080045000112608940003f111ea60a2127350a2180351388084b00fe0ec44820000d0000000000000100ca00010000" 287gtp = Ether(hex_bytes(h)) 288ie = gtp.IE_list[0] 289ie.DCNR == 0 290 291= IE_UPF_SelInd_Flags, basic instantiation 292ie = IE_UPF_SelInd_Flags(ietype='UP Function Selection Indication Flags', length=1, CR_flag=0, instance=0, SPARE=0, DCNR=0) 293ie.ietype == 202 and ie.DCNR == 0 294 295= IE_Ran_Nas_Cause, dissection 296h = "00000000000000000000000008004500005a0000000040114d390101010101010102084b084b0046bf694824000e000ba0df00002300ac0002003011" 297gtp = Ether(hex_bytes(h)) 298ie = gtp.IE_list[0] 299ie.protocol_type == 3 and ie.cause_type == 0 and ie.cause_value == 17 300 301= IE_Ran_Nas_Cause, basic instantiation 302ie = IE_Ran_Nas_Cause(ietype='RAN/NAS Cause', length=2, CR_flag=0, instance=0, protocol_type=3, cause_type=0, cause_value=17) 303ie.ietype == 172 and ie.protocol_type == 3 and ie.cause_type == 0 and ie.cause_value == 17 304 305= IE_FQCSID, dissection 306h = "d89ef3da40e2fa163e956dce0800450000330001000040117a2a0a0f0f3d0a09dd3a084b084b001f454648240013000000010000010084000700010a01010b00c8" 307gtp = Ether(hex_bytes(h)) 308ie = gtp.IE_list[0] 309ie.ietype == 132 and ie.nodeid_type == 0 and ie.num_csid == 1 and ie.nodeid_v4 == '10.1.1.11' and ie.csid == 200 310 311= IE_FQCSID, basic instantiation 312ie = IE_FQCSID(ietype=132, length=19, CR_flag=0, instance=0, nodeid_type=1, num_csid=1, nodeid_v4=None, nodeid_v6=42540578207381523466529575969228128257, nodeid_nonip=None, csid=0) 313ie.ietype == 132 and ie.nodeid_type == 1 and ie.num_csid == 1 and ie.nodeid_v6 == 42540578207381523466529575969228128257 and ie.csid == 0 314 315= IE_FTEID, dissection 316h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 317gtp = Ether(hex_bytes(h)) 318ie = gtp.IE_list[5] 319ie.GRE_Key == 4242 and ie.ipv4 == '127.0.0.2' 320 321= IE_FTEID, basic instantiation 322ie = IE_FTEID(ietype='F-TEID', length=9, ipv4_present=1, 323 InterfaceType=10, GRE_Key=0x1092, ipv4='127.0.0.2') 324ie.ietype == 87 and ie.ipv4_present == 1 and ie.InterfaceType == 10 and ie.GRE_Key == 0x1092 and ie.ipv4 == '127.0.0.2' 325 326= IE_BearerContext, dissection 327h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 328gtp = Ether(hex_bytes(h)) 329ie = gtp.IE_list[12] 330len(ie.IE_list) == 3 and ie.IE_list[0].ietype == 73 and ie.IE_list[0].EBI == 229 and ie.IE_list[ 331 1].ietype == 87 and ie.IE_list[1].ipv4 == '127.0.0.2' and ie.IE_list[2].ietype == 80 and ie.IE_list[2].QCI == 7 332 333= IE_BearerContext, basic instantiation 334ie = IE_BearerContext(ietype='Bearer Context', length=44, IE_list=[ 335 IE_EPSBearerID(ietype='EPS Bearer ID', length=1, EBI=229)]) 336ie.ietype == 93 and len(ie.IE_list) == 1 and ie.IE_list[ 337 0].ietype == 73 and ie.IE_list[0].EBI == 229 338 339= IE_ChargingID, dissection 340h = "3333333333332222222222228100838408004580006d00000000f31180d20a2a00010a2a0002084b85930059e49a4823004da0316b4d96ac2c000200020010004c00060011111111111149000100c348000800000061a8000249f07f000100005d001300490001003f0200020010005e00040039004f454a0004007f00000436f73a63" 341gtp = Ether(hex_bytes(h)) 342ie = gtp.IE_list[5].IE_list[2] 343ie.ChargingID == 956321605 344 345= IE_ChargingID, basic instantiation 346ie = IE_ChargingID(ietype='Charging ID', length=4, ChargingID=956321605) 347ie.ietype == 94 and ie.ChargingID == 956321605 348 349= IE_ChargingCharacteristics, dissection 350h = "3333333333332222222222228100a384080045b8011800000000fc1193150a2a00010a2a00027be5084b010444c4482000f82fd783953790a2000100080002081132547600004c0006001111111111114b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a001961616161616161616161616161616161616161616161616161800001000063000100014f000500017f0000034d000400000800007f00010000480008000000c3500002e6304e001a008080211001000010810600000000830600000000000d00000a005d001f00490001000750001600190700000000000000000000000000000000000000007200020014005f0002000a008e80b09f" 351gtp = Ether(hex_bytes(h)) 352ie = gtp.IE_list[18] 353ie.ChargingCharacteristic == 0xa00 354 355= IE_ChargingCharacteristics, basic instantiation 356ie = IE_ChargingCharacteristics( 357 ietype='Charging Characteristics', length=2, ChargingCharacteristic=0xa00) 358ie.ietype == 95 and ie.ChargingCharacteristic == 0xa00 359 360= IE_PDN_type, dissection 361h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 362gtp = Ether(hex_bytes(h)) 363ie = gtp.IE_list[8] 364ie.PDN_type == 1 365 366= IE_PDN_type, basic instantiation 367ie = IE_PDN_type(ietype='PDN Type', length=1, PDN_type='IPv4') 368ie.ietype == 99 and ie.PDN_type == 1 369 370= IE_UE_Timezone, dissection 371h = "3333333333332222222222228100a384080045b800ed00000000fc1193430a2a00010a2a00027f61084b00d91c47482000cd140339f4d99f66000100080002081132547600004b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a00196161616161616161616161616161616161616161616161616163000100014f000500017f0000034d0004000808000048000800000017000000a4105d002c0049000100e55700090385000010927f00000250001600580700000000000000000000000000000000000000007200020014005311004c" 372gtp = Ether(hex_bytes(h)) 373ie = gtp.IE_list[13] 374ie.Timezone == 20 and ie.DST == 0 375 376= IE_UE_Timezone, basic instantiation 377ie = IE_UE_Timezone(ietype='UE Time zone', length=2, Timezone=20, DST=0) 378ie.ietype == 114 and ie.Timezone == 20 and ie.DST == 0 379 380= IE_UE_Timezone, basic instantiation 381ie = IE_UE_Timezone(ietype='UE Time zone', length=2, Timezone=20, DST=1) 382ie.ietype == 114 and ie.Timezone == 20 and ie.DST == 1 383 384= IE_Port_Number, dissection 385h = "00010203040800808e8f8ab608004500004100010000401169140b00019705000001ec45084b002da8524820001d00000000006e400001000700420061896453f44a0004005f1e1d737e0002004532" 386gtp = Ether(hex_bytes(h)) 387ie = gtp.IE_list[2] 388ie.PortNumber == 17714 389 390= IE_Port_Number, basic instantiation 391ie = IE_Port_Number( 392 ietype='Port Number', length=2, PortNumber=17714) 393ie.ietype == 126 and ie.PortNumber == 17714 394 395= IE_APN_Restriction, dissection 396h = "3333333333332222222222228100838408004580006d00000000f31180d20a2a00010a2a0002084b85930059e49a4823004d55819f6500ede7000200020010004c000600111111111111490001003248000800000061a8000249f07f000100005d001300490001000b0200020010005e00040039004f454a0004007f00000436f73a63" 397gtp = Ether(hex_bytes(h)) 398ie = gtp.IE_list[4] 399ie.APN_Restriction == 0 400 401= IE_APN_Restriction, basic instantiation 402ie = IE_APN_Restriction( 403 ietype='APN Restriction', length=1, APN_Restriction=0) 404ie.ietype == 127 and ie.APN_Restriction == 0 405 406= IE_SelectionMode, dissection 407h = "3333333333332222222222228100a384080045b8011800000000fc1193150a2a00010a2a00027be5084b010444c4482000f8093ca4cc47fa69000100080002081132547600004c0006001111111111114b000800000000000001e24056000d001832f420303932f4200001e2405300030032f4205200010006570009008a000010927f0000025700090187000010927f00000247001a001961616161616161616161616161616161616161616161616161800001000063000100014f000500017f0000034d000400000800007f00010000480008000000c3500002e6304e001a008080211001000010810600000000830600000000000d00000a005d001f00490001004850001600190700000000000000000000000000000000000000007200020014005f0002000a008e80b09f" 408gtp = Ether(hex_bytes(h)) 409ie = gtp.IE_list[9] 410ie.SelectionMode == 0 411 412= IE_SelectionMode, basic instantiation 413ie = IE_SelectionMode( 414 ietype='Selection Mode', length=1, SelectionMode=4) 415ie.ietype == 128 and ie.SelectionMode == 4 416 417= IE_MMBR, dissection 418h = "3333333333332222222222228100838408004580014c97af0000f011830e0a2a00010a2a000282d5084b013876a74820012c29694a667f4a0b000100080002081132547600004c0006001111111111114b000800000000000001e24056000f000632f42030391a8532f42030391a855300030032f420520001000157001900c6000010927f0000020000000000000000000000000000fe8247001a001961616161616161616161616161616161616161616161616161800001000063000100014f000500017f0000034d000400000000007f000100004800080000001640000052084e00200080c02306010000060000802110010000108106000000008306000000000005005d003c00490001006057001902c4000010927f0000020000000000000000000000000000fe825000160029080000000000000000000000000000000000000000720002006e005f0002000a00a10008000000164000005208e4701ad2" 419gtp = Ether(hex_bytes(h)) 420ie = gtp.IE_list[18] 421ie.uplink_rate == 5696 and ie.downlink_rate == 21000 422 423= IE_MMBR, basic instantiation 424ie = IE_MMBR(ietype='Max MBR/APN-AMBR (MMBR)', 425 length=8, uplink_rate=5696, downlink_rate=21000) 426ie.ietype == 161 and ie.uplink_rate == 5696 and ie.downlink_rate == 21000 427 428= GTPHeader isn't an answer to not GTPHeader instance 429GTPHeader(gtp_type=2).answers(Ether()) == False 430 431= GTPHeader is an answer to a message with the same sequence number 432GTPHeader(seq=42).answers(GTPHeader(seq=42)) == True 433 434= GTPHeader isn't an answer to a message with a different sequence number 435GTPHeader(seq=42).answers(GTPHeader(seq=24)) == False 436 437= GTPV2EchoResponse answers 438assert (GTPHeader(seq=1)/GTPV2EchoResponse()).answers(GTPHeader(seq=1)/GTPV2EchoRequest()) 439assert not (GTPHeader(seq=1)/GTPV2EchoResponse()).answers(GTPHeader(seq=1)/GTPV2EchoResponse()) 440 441= GTPHeader post_build 442gtp = GTPHeader(gtp_type="create_session_req") / ("X"*32) 443gtp.show2() 444 445= GTPHeader length calculation 446h = GTPHeader(seq=12345, version=2, T=1, teid=1234)/("X"*32) 447h = GTPHeader(h.do_build()) 448h[GTPHeader].length == len(bytes(h)) - 4 449 450= GTPHeader hashret 451req = GTPHeader(gtp_type="create_session_req", seq=1) / ("X"*32) 452res = GTPHeader(gtp_type="create_session_res", seq=1) / ("Y"*32) 453req.hashret() == res.hashret() 454 455= IE_NotImplementedTLV 456h = "333333333333222222222222810080c808004588002937dd0000fd1115490a2a00010a2a0002084b084b00152d0e4001000900000100fe0001000daa000000003f1f382f" 457gtp = Ether(hex_bytes(h)) 458isinstance(gtp.IE_list[0], IE_NotImplementedTLV) 459isinstance(gtp.IE_list[0].payload, NoPayload) 460 461= IE_PrivateExtension, dissection 462h = "d89ef3da40e2fa163e956dce08004500005b0001000040115d400a0f0f3d01020304084b084b00470000482000620000000100000100ff0015000137020046462d46462d46462d46462d46462d4646ff00160001370100000100000000000000000000000000000000" 463gtp = Ether(hex_bytes(h)) 464ie1 = gtp.IE_list[0] 465ie2 = gtp.IE_list[1] 466ie1.enterprisenum == 311 and bytes_hex(ie1.proprietaryvalue) == b'020046462d46462d46462d46462d46462d4646' 467ie2.enterprisenum == 311 and bytes_hex(ie2.proprietaryvalue) == b'0100000100000000000000000000000000000000' 468 469= IE_PrivateExtension, basic instantiation 470ie1 = IE_PrivateExtension(ietype=255, length=21, SPARE=0, instance=0, enterprisenum=311, proprietaryvalue=hex_bytes('020046462d46462d46462d46462d46462d4646')) 471ie2 = IE_PrivateExtension(ietype=255, length=22, SPARE=0, instance=0, enterprisenum=311, proprietaryvalue=hex_bytes('0100000100000000000000000000000000000000')) 472ie1.enterprisenum == 311 and bytes_hex(ie1.proprietaryvalue) == b'020046462d46462d46462d46462d46462d4646' 473ie2.enterprisenum == 311 and bytes_hex(ie2.proprietaryvalue) == b'0100000100000000000000000000000000000000' 474