Skip to content

Commit df6ab35

Browse files
committed
FIXUP: feat(gtpv2): implement more IEs
1 parent dd4efc7 commit df6ab35

File tree

12 files changed

+849
-0
lines changed

12 files changed

+849
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.sipgate.udpproxy.udp.payload.gtpv2.ie;
2+
3+
public class AccessPointName extends InformationElement {
4+
public AccessPointName(final byte type, final byte spare, final byte instance, final byte[] payload) {
5+
super(type, spare, instance, payload);
6+
}
7+
8+
public String getApn() {
9+
// Encoding: TS 123.003, Clause 9.1: Each label is encoded as a length octet followed by that number of octets
10+
final var apn = new StringBuilder();
11+
var nextLengthIndex = 0;
12+
for (int i = 0; i < payload.length; i++) {
13+
if (i != nextLengthIndex) {
14+
apn.append((char) payload[i]);
15+
continue;
16+
}
17+
18+
if (i != 0) {
19+
apn.append(".");
20+
}
21+
nextLengthIndex = i + (payload[i] & 0xff) + 1;
22+
}
23+
24+
25+
return apn.toString();
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "AccessPointName{" +
31+
"apn='" + getApn() + '\'' +
32+
'}';
33+
}
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.sipgate.udpproxy.udp.payload.gtpv2.ie;
2+
3+
import com.sipgate.udpproxy.udp.payload.gtpv2.ie.decoder.BitHelper;
4+
5+
public class AggregateMaximumBitRate extends InformationElement {
6+
public AggregateMaximumBitRate(final byte type, final byte spare, final byte instance, final byte[] payload) {
7+
super(type, spare, instance, payload);
8+
}
9+
10+
public int getUpLinkBitRate() {
11+
return BitHelper.toInt32(payload[0], payload[1], payload[2], payload[3]);
12+
}
13+
14+
public int getDownLinkBitRate() {
15+
return BitHelper.toInt32(payload[4], payload[5], payload[6], payload[7]);
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return "AggregateMaximumBitRate{" +
21+
"upLinkBitRate=" + getUpLinkBitRate() +
22+
", downLinkBitRate=" + getDownLinkBitRate() +
23+
'}';
24+
}
25+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.sipgate.udpproxy.udp.payload.gtpv2.ie;
2+
3+
public class ApnRestriction extends InformationElement {
4+
public ApnRestriction(final byte type, final byte spare, final byte instance, final byte[] payload) {
5+
super(type, spare, instance, payload);
6+
}
7+
8+
public int getRestriction() {
9+
return payload[0];
10+
}
11+
12+
public Restriction getRestrictionValue() {
13+
return Restriction.fromValue(payload[0]);
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return "ApnRestriction{" +
19+
"restriction=" + getRestrictionValue() +
20+
'}';
21+
}
22+
23+
public enum Restriction {
24+
NO_RESTRICTION(0),
25+
PUBLIC_1(1),
26+
PUBLIC_2(2),
27+
PRIVATE_1(3),
28+
PRIVATE_2(4);
29+
30+
private final int value;
31+
32+
Restriction(final int value) {
33+
this.value = value;
34+
}
35+
36+
public int getValue() {
37+
return value;
38+
}
39+
40+
public static Restriction fromValue(final int value) {
41+
for (final var restriction : Restriction.values()) {
42+
if (restriction.getValue() == value) {
43+
return restriction;
44+
}
45+
}
46+
return null;
47+
}
48+
}
49+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.sipgate.udpproxy.udp.payload.gtpv2.ie;
2+
3+
import com.sipgate.udpproxy.udp.payload.gtpv2.ie.decoder.BitHelper;
4+
import com.sipgate.udpproxy.udp.payload.gtpv2.ie.decoder.IpV4V6;
5+
6+
import static com.sipgate.udpproxy.udp.payload.gtpv2.ie.decoder.BitHelper.isBitSet;
7+
8+
public class FullyQualifiedTunnelEndpointIdentifier extends InformationElement {
9+
10+
public FullyQualifiedTunnelEndpointIdentifier(final byte type, final byte spare, final byte instance, final byte[] payload) {
11+
super(type, spare, instance, payload);
12+
}
13+
14+
public boolean isIpv4Present() {
15+
return payload.length >= 1 && isBitSet(payload[0], 8);
16+
}
17+
18+
public boolean isIpv6Present() {
19+
return payload.length >= 1 && isBitSet(payload[0], 7);
20+
}
21+
22+
public int getInterfaceType() {
23+
return BitHelper.toInt(payload[0], 1, 6);
24+
}
25+
26+
public InterfaceType getInterfaceTypeValue() {
27+
return InterfaceType.fromValue(getInterfaceType());
28+
}
29+
30+
public int getTeidGreKey() {
31+
return BitHelper.toInt32(payload[1], payload[2], payload[3], payload[4]);
32+
}
33+
34+
public String getIpv4Address() {
35+
if (!isIpv4Present()) {
36+
return null;
37+
}
38+
39+
final byte[] ipv4 = new byte[4];
40+
System.arraycopy(this.payload, 5, ipv4, 0, 4);
41+
return IpV4V6.decodeV4(ipv4);
42+
}
43+
44+
public String getIpv6Address() {
45+
if (!isIpv6Present()) {
46+
return null;
47+
}
48+
49+
final byte[] ipv6 = new byte[16];
50+
System.arraycopy(this.payload, 5, ipv6, 0, 16);
51+
return IpV4V6.decodeV6(ipv6);
52+
}
53+
54+
@Override
55+
public String toString() {
56+
return "FullyQualifiedTunnelEndpointIdentifier{" +
57+
"ipv4Present=" + isIpv4Present() +
58+
", ipv6Present=" + isIpv6Present() +
59+
", interfaceType=" + getInterfaceTypeValue() +
60+
", teidGreKey=" + getTeidGreKey() +
61+
", ipv4Address='" + getIpv4Address() + '\'' +
62+
", ipv6Address='" + getIpv6Address() + '\'' +
63+
'}';
64+
}
65+
66+
public enum InterfaceType {
67+
S1_U_ENODEB_GTP_U(0),
68+
S1_U_SGW_GTP_U(1),
69+
S12_RNC_GTP_U(2),
70+
S12_SGW_GTP_U(3),
71+
S5_S8_SGW_GTP_U(4),
72+
S5_S8_PGW_GTP_U(5),
73+
S5_S8_SGW_GTP_C(6),
74+
S5_S8_PGW_GTP_C(7),
75+
S5_S8_SGW_PMIPV6(8),
76+
S5_S8_PGW_PMIPV6_ALT(9),
77+
S11_MME_GTP_C(10),
78+
S11_S4_SGW_GTP_C(11),
79+
S10_N26_MME_GTP_C(12),
80+
S3_MME_GTP_C(13),
81+
S3_SGSN_GTP_C(14),
82+
S4_SGSN_GTP_U(15),
83+
S4_SGW_GTP_U(16),
84+
S4_SGSN_GTP_C(17),
85+
S16_SGSN_GTP_C(18),
86+
ENODEB_GNODEB_GTP_U_FOR_DL_FORWARDING(19),
87+
ENODEB_GNODEB_GTP_U_FOR_UL_FORWARDING(20),
88+
RNC_GTP_U_FOR_DATA_FORWARDING(21),
89+
SGSN_GTP_U_FOR_DATA_FORWARDING(22),
90+
SGW_UPF_GTP_U_FOR_DL_FORWARDING(23),
91+
SM_MBMS_GW_GTP_C(24),
92+
SN_MBMS_GW_GTP_C(25),
93+
SM_MME_GTP_C(26),
94+
SN_SGSN_GTP_C(27),
95+
SGW_GTPU_FOR_UL_FORWARDING(28),
96+
SN_SGSN_GTP_U(29),
97+
S2B_EPDG_GTP_C(30),
98+
S2B_U_EPDG_GTP_U(31),
99+
S2B_PGW_GTP_C(32),
100+
S2B_U_PGW_GTP_U(33),
101+
S2A_TWAN_GTP_U(34),
102+
S2A_TWAN_GTP_C(35),
103+
S2A_PGW_GTP_C(36),
104+
S2A_PGW_GTP_U(37),
105+
S11_MME_GTP_U(38),
106+
S11_SGW_GTP_U(39),
107+
N26_AMF_GTP_C(40),
108+
N19MB_UPF_GTP_U(41),
109+
;
110+
111+
private final int value;
112+
113+
InterfaceType(final int value) {
114+
this.value = value;
115+
}
116+
117+
public static InterfaceType fromValue(final int value) {
118+
for (final InterfaceType interfaceType : InterfaceType.values()) {
119+
if (interfaceType.value == value) {
120+
return interfaceType;
121+
}
122+
}
123+
return null;
124+
}
125+
126+
public int getValue() {
127+
return value;
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)