library: Add template helpers for AoIP Transport Layer Address
This way one can simply pass an IP addr in string format and return the
IE no matter the IP version.
Change-Id: I743dbb7c89e504762498b7f278c12e130352e5f0
diff --git a/library/BSSMAP_Templates.ttcn b/library/BSSMAP_Templates.ttcn
index 694e3e8..0ec5639 100644
--- a/library/BSSMAP_Templates.ttcn
+++ b/library/BSSMAP_Templates.ttcn
@@ -14,6 +14,8 @@
import from General_Types all;
import from Osmocom_Types all;
+import from Native_Functions all;
+import from Misc_Helpers all;
import from GSM_Types all;
import from BSSAP_Types all;
@@ -436,6 +438,17 @@
template (value) BSSMAP_IE_AoIP_TransportLayerAddress ts_BSSMAP_IE_AoIP_TLA6(OCT16 ip, uint16_t pt) :=
ts_BSSMAP_IE_AoIP_TLA({ipv6:=ip}, pt, 18);
+function f_ts_BSSMAP_IE_AoIP_TLA(charstring addr, uint16_t udp_port)
+ return template (value) BSSMAP_IE_AoIP_TransportLayerAddress {
+ if (f_addr_is_ipv6(addr)) {
+ var OCT16 ip6 := f_inet6_addr(addr);
+ return ts_BSSMAP_IE_AoIP_TLA6(ip6, udp_port);
+ } else {
+ var OCT4 ip := f_inet_addr(addr);
+ return ts_BSSMAP_IE_AoIP_TLA4(ip, udp_port);
+ }
+}
+
template BSSMAP_IE_AoIP_TransportLayerAddress tr_BSSMAP_IE_AoIP_TLA(template BSSMAP_FIELD_IPAddress addr,
template uint16_t udp_port,
template integer len := ?) := {
@@ -449,6 +462,17 @@
template BSSMAP_IE_AoIP_TransportLayerAddress tr_BSSMAP_IE_AoIP_TLA6(template OCT16 ip, template uint16_t pt) :=
tr_BSSMAP_IE_AoIP_TLA({ipv6:=ip}, pt, 18);
+function f_tr_BSSMAP_IE_AoIP_TLA(charstring addr, template uint16_t udp_port)
+ return template BSSMAP_IE_AoIP_TransportLayerAddress {
+ if (f_addr_is_ipv6(addr)) {
+ var OCT16 ip6 := f_inet6_addr(addr);
+ return tr_BSSMAP_IE_AoIP_TLA6(ip6, udp_port);
+ } else {
+ var OCT4 ip := f_inet_addr(addr);
+ return tr_BSSMAP_IE_AoIP_TLA4(ip, udp_port);
+ }
+}
+
template (value) BSSMAP_IE_KC128 ts_BSSMAP_IE_Kc128(OCT16 kc128) := {
elementIdentifier := '83'O,
kC128_Value := kc128
diff --git a/library/Misc_Helpers.ttcn b/library/Misc_Helpers.ttcn
index 1ca6491..a402525 100644
--- a/library/Misc_Helpers.ttcn
+++ b/library/Misc_Helpers.ttcn
@@ -25,4 +25,13 @@
mtc.stop
}
+function f_addr_is_ipv6(charstring addr) return boolean {
+ for (var integer i := 0; i < lengthof(addr); i := i + 1) {
+ if (addr[i] == ":") {
+ return true;
+ }
+ }
+ return false;
+}
+
}