From a21258ece77e80dd9b9069ead4da6fd8774d0e66 Mon Sep 17 00:00:00 2001
From: Bing-Kai Hong <Bing-Kai.Hong@eurecom.fr>
Date: Tue, 26 Jun 2018 10:58:46 +0200
Subject: [PATCH] Update the F1 messages and build scripts for proper
 generation of F1 messages

---
 .gitignore                                    |  7 +++
 cmake_targets/CMakeLists.txt                  | 46 ++++++++++---------
 cmake_targets/build_oai                       | 12 +++--
 cmake_targets/tools/build_helper              | 15 ++++--
 cmake_targets/tools/fix_asn1                  | 19 ++++++++
 .../{R15 => R15.1.1}/F1AP-CommonDataTypes.asn |  2 +-
 .../ASN1/{R15 => R15.1.1}/F1AP-Constants.asn  |  4 +-
 .../ASN1/{R15 => R15.1.1}/F1AP-Containers.asn |  2 +-
 .../ASN1/{R15 => R15.1.1}/F1AP-IEs.asn        |  2 +-
 .../{R15 => R15.1.1}/F1AP-PDU-Contents.asn    |  0
 .../F1AP-PDU-Descriptions.asn                 |  0
 .../ASN1/{R15 => R15.1.1}/asn1_constants.h    |  0
 openair2/F1AP/MESSAGES/ASN1/asn1tostruct.py   |  2 +-
 13 files changed, 76 insertions(+), 35 deletions(-)
 create mode 100644 .gitignore
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-CommonDataTypes.asn (99%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-Constants.asn (99%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-Containers.asn (99%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-IEs.asn (99%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-PDU-Contents.asn (100%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/F1AP-PDU-Descriptions.asn (100%)
 mode change 100755 => 100644
 rename openair2/F1AP/MESSAGES/ASN1/{R15 => R15.1.1}/asn1_constants.h (100%)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..35696f4cbf1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+# vim swp
+*.swp
+
+# log and exec file
+log/
+lte_build_oai/
+targets/bin/
diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 4d154fc34e9..ecf03c81ca5 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -507,11 +507,13 @@ include_directories ("${X2AP_DIR}")
 # Same limitation as described in RRC/S1AP: unknown generated file list
 # so we generate it at cmake time
 ##############
-add_list1_option(F1AP_VERSION R15 "F1AP Asn.1 grammar version" R15)
+add_list1_option(F1AP_RELEASE R15 "F1AP ASN.1 grammar version" R15)
 set(F1AP_DIR ${OPENAIR2_DIR}/F1AP)
-#if (${F1AP_VERSION} STREQUAL "R15")
-  set (ASN1RELDIR R15)
-#endif(${F1AP_VERSION} STREQUAL "R15")
+if (${F1AP_RELEASE} STREQUAL "R15")
+  make_version(F1AP_VERSION 15 1 1)
+  set (ASN1RELDIR R15.1.1)
+endif(${F1AP_RELEASE} STREQUAL "R15")
+add_definitions(-DF1AP_VERSION=${F1AP_VERSION})
 set(F1AP_ASN_DIR ${F1AP_DIR}/MESSAGES/ASN1/${ASN1RELDIR})
 set(F1AP_ASN_FILES
   ${F1AP_ASN_DIR}/F1AP-CommonDataTypes.asn
@@ -522,22 +524,24 @@ set(F1AP_ASN_FILES
   ${F1AP_ASN_DIR}/F1AP-Containers.asn
   )
 
-set(F1AP_C_DIR ${asn1_generated_dir}/${ASN1RELDIR})
+set(F1AP_C_DIR ${asn1_generated_dir}/F1AP_${ASN1RELDIR})
+set(ENV{ASN1C_PREFIX} F1AP_)
 execute_process(COMMAND ${asn1c_call} ${F1AP_C_DIR} ${F1AP_ASN_FILES}
-                RESULT_VARIABLE ret)
+                RESULT_VARIABLE reti)
+unset(ENV{ASN1C_PREFIX})
 if (NOT ${ret} STREQUAL 0)
   message(FATAL_ERROR "${asn1c_call}: error")
 endif (NOT ${ret} STREQUAL 0)
-execute_process(COMMAND python ${F1AP_DIR}/MESSAGES/ASN1/asn1tostruct.py -f ${F1AP_ASN_DIR}/F1AP-PDU-Contents.asn -o ${F1AP_C_DIR}
-                RESULT_VARIABLE ret)
-if (NOT ${ret} STREQUAL 0)
-  message(FATAL_ERROR "asn1tostruct.py: error")
-endif (NOT ${ret} STREQUAL 0)
-execute_process(COMMAND ${fix_asn1c_call} ${F1AP_C_DIR} F1AP ${F1AP_VERSION}
-                RESULT_VARIABLE ret)
-if (NOT ${ret} STREQUAL 0)
-  message(FATAL_ERROR "${fix_asn1c_call}: error")
-endif (NOT ${ret} STREQUAL 0)
+#execute_process(COMMAND python ${F1AP_DIR}/MESSAGES/ASN1/asn1tostruct.py -f ${F1AP_ASN_DIR}/F1AP-PDU-Contents.asn -o ${F1AP_C_DIR}
+#                RESULT_VARIABLE ret)
+#if (NOT ${ret} STREQUAL 0)
+#  message(FATAL_ERROR "asn1tostruct.py: error")
+#endif (NOT ${ret} STREQUAL 0)
+#execute_process(COMMAND ${fix_asn1c_call} ${F1AP_C_DIR} F1AP ${F1AP_VERSION}
+#                RESULT_VARIABLE ret)
+#if (NOT ${ret} STREQUAL 0)
+#  message(FATAL_ERROR "${fix_asn1c_call}: error")
+#endif (NOT ${ret} STREQUAL 0)
 file(GLOB F1AP_source ${F1AP_C_DIR}/*.c)
 
 #set(F1AP_OAI_generated
@@ -907,8 +911,8 @@ set(FLPT_MSG_FILES
   ${FLPT_MSG_DIR}/control_delegation.proto
   )
 
-set(FLPT_C_DIR ${protobuf_generated_dir}/${FLPTDIR})
-message("calling protoc_call=${protoc_call} FLPT_C_DIR=${FLPT_C_DIR} FLPT_MSG_FILES=${FLPT_MSG_FILES}")
+set(FLPT_C_DIR ${protobuf_generated_dir}/FLPT_${FLPTDIR})
+#message("calling protoc_call=${protoc_call} FLPT_C_DIR=${FLPT_C_DIR} FLPT_MSG_FILES=${FLPT_MSG_FILES}")
 execute_process(COMMAND ${protoc_call} ${FLPT_C_DIR} ${FLPT_MSG_DIR} ${FLPT_MSG_FILES})
 file(GLOB FLPT_source ${FLPT_C_DIR}/*.c)
 set(FLPT_OAI_generated
@@ -988,10 +992,10 @@ if (PDCP_SPLIT)
     ${FSPT_MSG_DIR}/flexsplit.proto
     )
 
-  set(FSPT_C_DIR ${protobuf_generated_dir}/${FSPTDIR})
-  message("calling protoc_call=${protoc_call} FSPT_C_DIR=${FSPT_C_DIR} FSPT_MSG_FILES=${FSPT_MSG_FILES}")
+  set(FSPT_C_DIR ${protobuf_generated_dir}/FSPT_${FSPTDIR})
+  message("calling protoc_call=${protoc_call} FSPT_C_DIR=${FSPT_C_DIR} FSPT_MSG_DIR=${FSPT_MSG_DIR} FSPT_MSG_FILES=${FSPT_MSG_FILES}")
   execute_process(COMMAND ${protoc_call} ${FSPT_C_DIR} ${FSPT_MSG_DIR} ${FSPT_MSG_FILES})
-  file(GLOB FSPT_source ${FSPT_C_DIR}/*.c)  
+  file(GLOB FSPT_source ${FSPT_C_DIR}/*.c)
   set(FSPT_OAI_generated
     ${FSPT_C_DIR}/flexsplit.pb-c.c
     )
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index 60bf3951c27..743b1a53b57 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -105,6 +105,10 @@ Options
    Enables agent for software-defined control of the eNB
 --pdcp-split
    Enables PDCP-RLC U plane split
+--CU
+   Build the CU entity 
+--DU 
+   Build the CU entity 
 -r | --3gpp-release
    default is Rel14,
    Rel8 limits the implementation to 3GPP Release 8 version
@@ -214,9 +218,11 @@ function main() {
        -a | --agent)
 	    echo_info "FlexRAN support is always compiled into the eNB"
 	    shift;;
-       --pdcp-split)
+       --pdcp-split | --CU | --DU )
 	    PDCP_SPLIT=1
-	    echo_info "Will compile PDCP-RLC U plane split support"
+	    CU=1
+	    DU=1
+	    echo_info "Will compile for $1 with F1AP support "
 	    shift;;
        --UE)
             UE=1
@@ -473,7 +479,7 @@ function main() {
 
   if [ "$INSTALL_EXTERNAL" = "1" ] ; then
     echo_info "Installing packages"
-    check_install_oai_software
+    check_install_oai_software $PDCP_SPLIT
     if [ "$HW" == "OAI_USRP" ] ; then
       echo_info "installing packages for USRP support"
       check_install_usrp_uhd_driver
diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper
index 0270556b887..1f9ca5cd828 100755
--- a/cmake_targets/tools/build_helper
+++ b/cmake_targets/tools/build_helper
@@ -567,7 +567,8 @@ check_install_oai_software() {
 	pydb \
 	libyaml-dev \
 	wget \
-	libxpm-dev
+	libxpm-dev \
+        libboost-all-dev
 
     $SUDO update-alternatives --set "$LAPACK_LIBNAME" "$LAPACK_TARGET"
 
@@ -653,7 +654,7 @@ check_install_oai_software() {
       libyaml-devel
   fi
 
-    install_asn1c_from_source
+    install_asn1c_from_source $1
     $SUDO rm -fr /opt/ssh
     $SUDO git clone https://gist.github.com/2190472.git /opt/ssh
 }
@@ -663,10 +664,14 @@ install_asn1c_from_source(){
     echo_info "\nInstalling ASN1. The log file for ASN1 installation is here: $asn1_install_log "
     (
     $SUDO rm -rf /tmp/asn1c
-    GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/oai/asn1c.git /tmp/asn1c
+    if [ $1 -eq "1" ]; then
+             echo "building ASN1C from https://github.com/brchiu/asn1c branch"
+	GIT_SSL_NO_VERIFY=true git clone https://github.com/brchiu/asn1c.git --branch velichkov_s1ap_plus_option_group /tmp/asn1c
+    else
+        echo "building ASN1C from https://gitlab.eurecom.fr/oai/asn1c branch"
+	GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/oai/asn1c.git --branch master.aper /tmp/asn1c
+    fi
     cd /tmp/asn1c
-    git checkout master.aper
-    git pull
     test -f configure || autoreconf -iv
     ./configure
     make -j`nproc`
diff --git a/cmake_targets/tools/fix_asn1 b/cmake_targets/tools/fix_asn1
index 5fbb3bdbe94..1486589a0c5 100755
--- a/cmake_targets/tools/fix_asn1
+++ b/cmake_targets/tools/fix_asn1
@@ -140,6 +140,22 @@ function patch_s1ap()
   esac
 }
 
+function patch_f1ap()
+{
+  local directory="$1"
+  local version="$2"
+
+  case "$version" in
+    R15 )
+      #nothing to do anymore (fixes went to asn1c)
+      ;;
+    * )
+      error unknwon/unhandled F1AP version \'"$version"\'
+      ;;
+  esac
+}
+
+
 function main()
 {
   if [ $# -ne 3 ]
@@ -167,6 +183,9 @@ function main()
     S1AP )
       patch_s1ap "$directory" "$version"
       ;;
+    F1AP )
+      patch_f1ap "$directory" "$version"
+      ;;
     * )
       error unknown module "$module"
       ;;
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-CommonDataTypes.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-CommonDataTypes.asn
old mode 100755
new mode 100644
similarity index 99%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-CommonDataTypes.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-CommonDataTypes.asn
index 12dfbd12ff7..3e4e4178455
--- a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-CommonDataTypes.asn
+++ b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-CommonDataTypes.asn
@@ -29,4 +29,4 @@ ProtocolIE-ID		::= INTEGER (0..65535)
 
 TriggeringMessage	::= ENUMERATED { initiating-message, successful-outcome, unsuccessfull-outcome }
 
-END
+END
\ No newline at end of file
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Constants.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Constants.asn
old mode 100755
new mode 100644
similarity index 99%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Constants.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Constants.asn
index 4ec60632f0d..6840b00bf42
--- a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Constants.asn
+++ b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Constants.asn
@@ -157,7 +157,7 @@ id-SRBs-ToBeSetup-Item								ProtocolIE-ID ::= 73
 id-SRBs-ToBeSetup-List								ProtocolIE-ID ::= 74
 id-SRBs-ToBeSetupMod-Item							ProtocolIE-ID ::= 75
 id-SRBs-ToBeSetupMod-List							ProtocolIE-ID ::= 76
-id-TimeToWait										ProtocolIE-ID ::= 75
+id-TimeToWait										ProtocolIE-ID ::= 77
 id-TransactionID									ProtocolIE-ID ::= 78
 id-TransmissionStopIndicator						ProtocolIE-ID ::= 79
 id-UE-associatedLogicalF1-ConnectionItem 			ProtocolIE-ID ::= 80
@@ -176,4 +176,4 @@ id-Potential-SpCell-List							ProtocolIE-ID ::= 92
 id-Potential-SpCell-Item							ProtocolIE-ID ::= 93
 
 
-END
+END
\ No newline at end of file
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Containers.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Containers.asn
old mode 100755
new mode 100644
similarity index 99%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Containers.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Containers.asn
index ed5dfba961e..52c09d156ac
--- a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-Containers.asn
+++ b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-Containers.asn
@@ -181,4 +181,4 @@ PrivateIE-Field {F1AP-PRIVATE-IES : IEsSetParam} ::= SEQUENCE {
 	value				F1AP-PRIVATE-IES.&Value				({IEsSetParam}{@id})
 }
 
-END
+END
\ No newline at end of file
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-IEs.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-IEs.asn
old mode 100755
new mode 100644
similarity index 99%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-IEs.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-IEs.asn
index 672407d851a..4a0d2abdffd
--- a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-IEs.asn
+++ b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-IEs.asn
@@ -867,4 +867,4 @@ ULTunnels-ToBeSetup-ItemExtIEs 	F1AP-PROTOCOL-EXTENSION ::= {
 
 -- Z
 
-END
+END
\ No newline at end of file
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-PDU-Contents.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-PDU-Contents.asn
old mode 100755
new mode 100644
similarity index 100%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-PDU-Contents.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-PDU-Contents.asn
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/F1AP-PDU-Descriptions.asn b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-PDU-Descriptions.asn
old mode 100755
new mode 100644
similarity index 100%
rename from openair2/F1AP/MESSAGES/ASN1/R15/F1AP-PDU-Descriptions.asn
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/F1AP-PDU-Descriptions.asn
diff --git a/openair2/F1AP/MESSAGES/ASN1/R15/asn1_constants.h b/openair2/F1AP/MESSAGES/ASN1/R15.1.1/asn1_constants.h
similarity index 100%
rename from openair2/F1AP/MESSAGES/ASN1/R15/asn1_constants.h
rename to openair2/F1AP/MESSAGES/ASN1/R15.1.1/asn1_constants.h
diff --git a/openair2/F1AP/MESSAGES/ASN1/asn1tostruct.py b/openair2/F1AP/MESSAGES/ASN1/asn1tostruct.py
index 8c0f7e8a16a..b5f019f486e 100644
--- a/openair2/F1AP/MESSAGES/ASN1/asn1tostruct.py
+++ b/openair2/F1AP/MESSAGES/ASN1/asn1tostruct.py
@@ -132,7 +132,7 @@ for filename in filenames:
     for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+E-RAB-IE-ContainerList\s*\{\s*\{\s*([a-zA-Z0-9-]+)\s*\}\s*\}', lines, re.MULTILINE):
         ieofielist[m[0]] = m[1]
 
-    for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n', lines, re.MULTILINE):
+    for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n?', lines, re.MULTILINE):
         ies = []
         maxLength = 0
         # TODO: handle extensions
-- 
GitLab