Merge "Initial docs skeleton"
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/properties/global_properties.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/properties/global_properties.robot
index 58f22dd..3c15f62 100644
--- a/ric_robot_suite/helm/nanobot/configmap-src/public/properties/global_properties.robot
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/properties/global_properties.robot
@@ -1,3 +1,17 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
 {{- $domain := default "cluster.local" .Values.ric.cluster.domain }}
 {{- $ricpltNS := include "common.namespace.platform" . }}
 {{- $xappNS := include "common.namespace.xapp" . }}
@@ -21,24 +35,31 @@
 ${GLOBAL_APPLICATION_ID}              {{ default "r0" .Values.ric.robot.release | printf "nanobot-%s" }}
 ${GLOBAL_BUILD_NUMBER}                {{ default "0" .Values.ric.platform.build  }}
 ${GLOBAL_RICPLT_NAMESPACE}            {{ $ricpltNS  }}
+${GLOBAL_XAPP_NAMESPACE}              {{ $xappNS  }}
 #
+{{- if .Values.ric.platform.components.appmgr }}
 ${GLOBAL_APPMGR_SERVER_PROTOCOL}      {{ default "http" .Values.ric.platform.components.appmgr.protocol  }}
 ${GLOBAL_INJECTED_APPMGR_IP_ADDR}     {{ printf "%s.%s" (include "common.servicename.appmgr.http" .) $ricplt  }}
 ${GLOBAL_APPMGR_SERVER_PORT}          {{ include "common.serviceport.appmgr.http" .  }}
 ${GLOBAL_INJECTED_APPMGR_USER}        {{ .Values.ric.platform.components.appmgr.user  }}
 ${GLOBAL_INJECTED_APPMGR_PASSWORD}    {{ .Values.ric.platform.components.appmgr.password  }}
+{{- end }}
 #
+{{- if .Values.ric.platform.components.e2mgr }}
 ${GLOBAL_E2MGR_SERVER_PROTOCOL}       {{ default "http" .Values.ric.platform.components.e2mgr.protocol  }}
 ${GLOBAL_INJECTED_E2MGR_IP_ADDR}      {{ printf "%s.%s" (include "common.servicename.e2mgr.http" .) $ricplt  }}
 ${GLOBAL_E2MGR_SERVER_PORT}           {{ include "common.serviceport.e2mgr.http" .  }}
 ${GLOBAL_INJECTED_E2MGR_USER}         {{ .Values.ric.platform.components.e2mgr.user  }}
 ${GLOBAL_INJECTED_E2MGR_PASSWORD}     {{ .Values.ric.platform.components.e2mgr.password  }}
+{{- end }}
 #
+{{- if .Values.ric.platform.components.rtmgr }}
 ${GLOBAL_RTMGR_SERVER_PROTOCOL}       {{ default "http" .Values.ric.platform.components.rtmgr.protocol  }}
 ${GLOBAL_INJECTED_RTMGR_IP_ADDR}      {{ printf "%s.%s" (include "common.servicename.rtmgr.http" .) $ricplt  }}
 ${GLOBAL_RTMGR_SERVER_PORT}           {{ include "common.serviceport.e2mgr.http" .  }}
 ${GLOBAL_INJECTED_RTMGR_USER}         {{ .Values.ric.platform.components.rtmgr.user  }}
 ${GLOBAL_INJECTED_RTMGR_PASSWORD}     {{ .Values.ric.platform.components.rtmgr.password  }}
+{{- end }}
 #
 ${GLOBAL_INJECTED_DBAAS_IP_ADDR}      {{ printf "%s.%s" (include "common.servicename.dbaas.tcp" .) $ricplt  }}
 ${GLOBAL_DBAAS_SERVER_PORT}           {{ include "common.serviceport.dbaas.tcp" .  }}
@@ -47,4 +68,8 @@
 #
 ${GLOBAL_TEST_NODEB_NAME}             {{ default "AAAA456789" .Values.ric.robot.environment.gNodeB.name }}
 ${GLOBAL_TEST_NODEB_ADDRESS}          {{ default "10.0.0.3"   .Values.ric.robot.environment.gNodeB.address }}
-${GLOBAL_TEST_NODEB_PORT}             {{ default "36421"      .Values.ric.robot.environment.gNodeB.port }}
\ No newline at end of file
+${GLOBAL_TEST_NODEB_PORT}             {{ default "36421"      .Values.ric.robot.environment.gNodeB.port }}
+#
+${GLOBAL_DASH_SERVER_PROTOCOL}        {{ default "http"       .Values.ric.robot.environment.dashboard.protocol }}
+${GLOBAL_DASH_SERVER_PORT}            {{ default "31080"      .Values.ric.robot.environment.dashboard.port }}
+${GLOBAL_INJECTED_DASH_IP_ADDR}       {{ default "127.0.0.1"  .Values.ric.robot.environment.dashboard.port }}
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/properties/mcxapp_properties.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/properties/mcxapp_properties.robot
new file mode 100644
index 0000000..6d69dd9
--- /dev/null
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/properties/mcxapp_properties.robot
@@ -0,0 +1,23 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation        This file contains configuration specific to the MC xapp.
+
+*** Variables ***
+${GLOBAL_MCXAPP_LISTENER_NAME}        {{ default "mc-xapp-listener" .Values.ric.xapp.mcxapp.listener.containername }}
+${GLOBAL_MCXAPP_WRITER_NAME}          {{ default "mc-xapp-writer" .Values.ric.xapp.mcxapp.writer.containername }}
+@{GLOBAL_MCXAPP_WRITER_STATISTICS}    {{- range .Values.ric.xapp.mcxapp.writer.statistics }}
+...                                   {{.}}
+                                      {{- end }}
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ete.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ete.robot
index 8f8b282..35d12a3 100644
--- a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ete.robot
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ete.robot
@@ -1,3 +1,17 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
 *** Settings ***
 Documentation	  Executes the End To End Test cases
 ...
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/health-check.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/health-check.robot
index a8faacf..5e5fdba 100644
--- a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/health-check.robot
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/health-check.robot
@@ -1,20 +1,42 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
 *** Settings ***
-Documentation     Testing RIC components are available via calls.
-...
-...               Testing RIC components are available via calls.
-Test Timeout      10 second
-Resource          ../resources/appmgr/appmgr_interface.robot
-Resource          ../resources/e2mgr/e2mgr_interface.robot
-Resource          ../resources/rtmgr/rtmgr_interface.robot
+Documentation      Run basic health checks for all known components which have one
+
+Resource           /robot/resources/global_properties.robot
+
+Resource           /robot/resources/ric/ric_utils.robot
 
 *** Test Cases ***
-Basic AppMgr Health Check
-    [Tags]    health    
-    Run AppMgr Health Check
-Basic E2Mgr Health Check
-    [Tags]    health    
-    Run E2Mgr Health Check
-Basic RtMgr Health Check
-    [Tags]    health    
-    Run RtMgr Health Check
-
+Basic Component Health Checks
+  [Documentation]  For any defined RIC component with a health check keyword,
+  ...              Run that keyword.  "Health check" keywords have names of the
+  ...              form "Run ${component} Health Check".
+  # This could have been entirely implemented in Helm; however, I wanted to
+  # allow for the possibility that it would be used (with some modification)
+  # by the ric-robot, which does not perform template expansion on testsuites.
+  [Tags]  health
+  Set Test Variable    ${finalStatus}  PASS
+  :FOR   ${component}  IN              @{GLOBAL_RICPLT_COMPONENTS}
+  \  Run Keyword And Ignore Error
+  ...   Import Resource                /robot/resources/${component}/${component}_interface.robot
+  \  ${healthCheck} =  Set Variable    Run ${component} Health Check
+  \  ${status} =       Run Keyword If Present                   ${healthCheck}
+  \  ${finalStatus} =  Set Variable If   '${status}' == 'FAIL'  FAIL  ${finalStatus}
+  \  Run Keyword If    '${status}' == 'FAIL'
+  ...                  Log  ${component} is unhealthy
+  Run Keyword If       '${finalStatus}' == 'FAIL'
+  ...                  Fail  One or more Health Checks failed
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/mcxapp.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/mcxapp.robot
new file mode 100644
index 0000000..756ff23
--- /dev/null
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/mcxapp.robot
@@ -0,0 +1,82 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation  Tests for the Measurement Campaign XApp
+
+
+Resource       /robot/resources/global_properties.robot
+Resource       /robot/resources/mcxapp_properties.robot
+
+Resource       /robot/resources/ric/ric_utils.robot
+
+Library        Collections
+Library        KubernetesEntity          ${GLOBAL_XAPP_NAMESPACE}
+
+*** Variables ***
+${listenerContainerName}    mc-xapp-listener
+${listenerStatRegex}        ^[0-9]+\\s*\\[STAT\\]\\s*\\(mcl\\)
+${recentListenerDrops}      .*last 60s.*drops\\s*=\\s*([1-9][0-9]*)
+${recentListenerErrors}     .*last 60s.*errs\\s*=\\s*([1-9][0-9]*)
+${writerVesSuccesses}       .*successful\\s+ves\\s+posts\\s*-\\s*([1-9][0-9]*)
+${writerVesErrors}          .*failed\\s+ves\\s+posts\\s*-\\s*([1-9][0-9]*)
+
+*** Test Cases ***
+XApp Should Be Available
+  [Tags]  etetests  xapptests  mcxapptests
+  ${deploymentName} =  Get From Dictionary  ${GLOBAL_RICPLT_XAPPS}  mcxapp
+  Set Suite Variable   ${deploymentName}
+  ${deploy} =          Deployment           ${deploymentName}
+  ${status} =          Most Recent Availability Condition           @{deploy.status.conditions}
+  Should Be Equal As Strings   ${status}  True  ignore_case=True
+
+Listener Should Not Be Dropping Messages
+  [Tags]  etetests  xapptests  mcxapptests
+  ${log} =  Most Recent Container Logs  ${deploymentName}
+  ...                                   ${GLOBAL_MCXAPP_LISTENER_NAME}
+  ...                                   ${listenerStatRegex}
+  Should Not Contain Match             ${log}                   regexp=${recentListenerDrops}
+  
+Listener Should Not Be Producing Errors
+  [Tags]  etetests  xapptests  mcxapptests
+  ${log} =  Most Recent Container Logs  ${deploymentName}
+  ...                                   ${GLOBAL_MCXAPP_LISTENER_NAME}
+  ...                                   ${listenerStatRegex}
+  Should Not Contain Match             ${log}                   regexp=${recentListenerErrors}
+
+Writer Should Be Successfully Sending Statistics
+  [Tags]  etetests  xapptests  mcxapptests
+  Set Test Variable  ${finalStatus}  PASS
+  :FOR  ${stat}  IN  @{GLOBAL_MCXAPP_WRITER_STATISTICS}
+  \  ${statRE} =        Regexp Escape  ${stat}
+  \  ${log} =           Most Recent Container Logs    ${deploymentName}
+  ...                   ${GLOBAL_MCXAPP_WRITER_NAME}
+  ...                   ^${statRE}:\\s+successful\\s+ves\\s+posts\\.*
+  \  ${status}  ${u} =  Run Keyword And Ignore Error
+  ...                   Should Contain Match  ${log}  regexp=${writerVesSuccesses}
+  \  ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
+  ...                   FAIL
+  ...                   ${finalStatus}
+  \  Run Keyword If     "${status}" == "FAIL"
+  ...                   Log  No messages have been sent to VES for ${stat}
+  \  ${status}  ${u} =  Run Keyword And Ignore Error
+  ...                   Should Not Contain Match  ${log}  regexp=${writerVesErrors}
+  \  ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
+  ...                   FAIL
+  ...                   ${finalStatus}
+  \  Run Keyword If     "${status}" == "FAIL"
+  ...                   Log  ${stat} is producing errors logging to VES
+  Run Keyword If        "${finalStatus}" == "FAIL"
+  ...                   Fail  One or more statistics is not being succesfully logged
+
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ricdeployment.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ricdeployment.robot
index 3417675..85920f7 100644
--- a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ricdeployment.robot
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/ricdeployment.robot
@@ -18,6 +18,8 @@
 
 Resource       /robot/resources/global_properties.robot
 
+Resource       /robot/resources/ric/ric_utils.robot
+
 Library  KubernetesEntity  ${GLOBAL_RICPLT_NAMESPACE}
 Library  Collections
 Library  String
@@ -30,13 +32,3 @@
   \  ${deploy} =          Deployment           ${deploymentName}
   \  ${status} =          Most Recent Availability Condition                @{deploy.status.conditions}
   \  Should Be Equal As Strings  ${status}  True  ignore_case=True  msg=${Component} is not available
-
-*** Keywords ***
-Most Recent Availability Condition
-  # this makes the probably-unsafe assumption that the conditions are ordered
-  # temporally.
-  [Arguments]  @{Conditions}
-  ${status} =  Set Variable  'False'
-  :FOR  ${Condition}  IN  @{Conditions}
-  \  ${status} =  Set Variable If  '${Condition.type}' == 'Available'  ${Condition.status}  ${status}
-  [Return]  ${status}
diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/update_ric_page.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/update_ric_page.robot
index a2efd1c..5fab634 100644
--- a/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/update_ric_page.robot
+++ b/ric_robot_suite/helm/nanobot/configmap-src/public/testsuites/update_ric_page.robot
@@ -1,3 +1,17 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
 *** Settings ***
 Documentation	  Initializes RIC Test Web Page and Password
 
diff --git a/ric_robot_suite/helm/nanobot/templates/job-ric-robot-run.yaml b/ric_robot_suite/helm/nanobot/templates/job-ric-robot-run.yaml
index 2ca4ffb..c476853 100644
--- a/ric_robot_suite/helm/nanobot/templates/job-ric-robot-run.yaml
+++ b/ric_robot_suite/helm/nanobot/templates/job-ric-robot-run.yaml
@@ -72,7 +72,7 @@
   namespace: {{ $xappNamespace }}
 rules:
 - apiGroups: [""]
-  resources: ["pods", "services"]
+  resources: ["pods", "pods/log", "services"]
   verbs: ["get", "list"]
 - apiGroups: ["apps"]
   resources: ["deployments", "daemonsets", "replicasets", "statefulsets"]
@@ -103,10 +103,11 @@
   name: {{ $jobName }}-ric-robot-run
   namespace: {{ .Release.Namespace }}
 spec:
+  backoffLimit:  {{ default 0 .Values.ric.robot.job.backoffLimit }}
   template:
     spec:
       serviceAccountName: {{ $serviceAccountName }}
-      restartPolicy: Never
+      restartPolicy: {{ default "Never" .Values.ric.robot.job.restartPolicy }}
       initContainers:
         - name: {{ $jobName }}-generate-robot-kubeconfig
           {{ with .Values.images.ric.robot.job.init }}
diff --git a/ric_robot_suite/helm/nanobot/values.yaml b/ric_robot_suite/helm/nanobot/values.yaml
index 0abfda0..16ac5a6 100644
--- a/ric_robot_suite/helm/nanobot/values.yaml
+++ b/ric_robot_suite/helm/nanobot/values.yaml
@@ -54,20 +54,37 @@
   # platform source tree
   releaseName: r0
   components:
+   a1mediator:
    appmgr:
     user: test
     password: test
-   rtmgr:
-    user: test
-    password: test
+   dbaas:
    e2mgr:
     user: test
     password: test
    e2term:
-   a1mediator:
+   rtmgr:
+    user: test
+    password: test
+   submgr:
  xapp:
-  anr:
-   servicename: anr
+  mcxapp:
+   listener:
+    containername: mc-xapp-listener
+   writer:
+    containername: mc-xapp-writer
+    # statistics sent to ves by the writer.  the tests
+    # will check that these are actually being sent
+    statistics:
+    - mc_connected_cnt
+    - mc_connection_stats
+    - mc_connects_cnt
+    - mc_disconnects_cnt
+    - mc_unique_ue_cnt
+    - rrcx_pdf_serv_cell
+    - rrcx_pdf_serv_gnb
+    - rrcx_stats_serv_cell
+    - rrcx_stats_serv_gnb
  robot:
   release: r1
   #
@@ -96,7 +113,7 @@
    # set this to a true value to cause
    # the job to fail (and, typically, be resubmitted)
    # when tests fail
-   failOnTestFail: false
+   failOnTestFail: true
    serviceAccount:
     # by default, the job will create
     # a temporary serviceaccount and
@@ -123,3 +140,6 @@
      name: AAAA456789
      address: 10.0.0.3
      port: 36421
+    dashboard:
+     address: 10.1.0.1
+     port: 31080
\ No newline at end of file
diff --git a/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py b/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py
index 7b2535a..8944167 100644
--- a/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py
+++ b/ric_robot_suite/ric-python-utils/ricutils/KubernetesEntity.py
@@ -17,6 +17,7 @@
 import string
 import random
 import time
+import sys
 
 # This library provides a massively-simplified interface to the kubernetes
 # API library to reduce bloat in robot tests.
@@ -82,3 +83,19 @@
    timeout -= 1
   raise TimeoutError('Kubernetes timeout waiting for ' + name + ' to become available')
 
+ def RetrievePodsForDeployment(self, name):
+  # return the pod names associated with a deployment
+  d = self.Deployment(name)
+  labels = d.spec.selector.match_labels
+  pods = self._k8sCore.list_namespaced_pod(self._ns,
+                                           label_selector=",".join(map(lambda k: k + "=" + labels[k], 
+                                                                       labels)))
+  return map(lambda i: i.metadata.name, pods.items)
+ 
+ def RetrieveLogForPod(self, pod, container='', tail=sys.maxsize):
+  # not really an "entity" thing per se, but.
+  # kinda want to include timestamps, but i don't have a use case for them.
+  return self._k8sCore.read_namespaced_pod_log(namespace=self._ns,
+                                               name=pod,
+                                               container=container,
+                                               tail_lines=tail).split('\n')[0:-1]
diff --git a/ric_robot_suite/robot/resources/appmgr/appmgr_interface.robot b/ric_robot_suite/robot/resources/appmgr/appmgr_interface.robot
index 3f14604..c346e95 100644
--- a/ric_robot_suite/robot/resources/appmgr/appmgr_interface.robot
+++ b/ric_robot_suite/robot/resources/appmgr/appmgr_interface.robot
@@ -5,6 +5,8 @@
 
 Resource       ../global_properties.robot
 
+Resource       ../ric/ric_utils.robot
+
 *** Variables ***
 ${APPMGR_BASE_PATH}  /ric/v1/xapps
 ${APPMGR_ENDPOINT}   ${GLOBAL_APPMGR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_APPMGR_IP_ADDR}:${GLOBAL_APPMGR_SERVER_PORT}
@@ -104,20 +106,3 @@
      ${headers} =     Create Dictionary  Accept=application/json         Content-Type=application/json
      ${resp} =        Delete Request     roboAppmgrDelete                ${APPMGR_BASE_PATH}${path}  headers=${headers}
      [Return]         ${resp}
-
-
-# a few useful list routines that should probably live elsewhere
-Pluck
-     [Documentation]  Get the values of a specific key from a list of dictionaries
-     [Arguments]      ${k}      ${l}
-     @{names} =       Evaluate  filter(lambda v: v != None, [i.get('${k}', None) for i in ${l}])
-     [Return]         ${names}
-
-Subtract From List
-     [Documentation]  Remove the elements of the second argument from the first
-     [Arguments]      ${x}  ${y}
-     ${diff} =        Run Keyword If  ${y}
-     ...              Evaluate  filter(lambda v: v not in ${y}, ${x})
-     ...              ELSE
-     ...              Set Variable    ${x}
-     [Return]         ${diff}
diff --git a/ric_robot_suite/robot/resources/ric/placeholder_for_files b/ric_robot_suite/robot/resources/ric/placeholder_for_files
deleted file mode 100644
index e69de29..0000000
--- a/ric_robot_suite/robot/resources/ric/placeholder_for_files
+++ /dev/null
diff --git a/ric_robot_suite/robot/resources/ric/ric_utils.robot b/ric_robot_suite/robot/resources/ric/ric_utils.robot
new file mode 100644
index 0000000..30ed937
--- /dev/null
+++ b/ric_robot_suite/robot/resources/ric/ric_utils.robot
@@ -0,0 +1,90 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation  A library of utility keywords that may be useful
+...            in various test suites.
+
+Library        Collections
+
+*** Keywords ***
+#
+# Kubernetes Utilities
+Most Recent Availability Condition
+  # this makes the probably-unsafe assumption that the conditions are ordered
+  # temporally.
+  [Arguments]  @{Conditions}
+  ${status} =  Set Variable  'False'
+  :FOR  ${Condition}  IN  @{Conditions}
+  \  ${status} =  Set Variable If  '${Condition.type}' == 'Available'  ${Condition.status}  ${status}
+  [Return]  ${status}
+
+Most Recent Container Logs
+  [Arguments]  ${deployment}  ${container}=${EMPTY}  ${regex}=${EMPTY}
+  ${pods} =            Retrieve Pods For Deployment  ${deployment}
+  ${logs} =            Create List
+  :FOR  ${pod}  IN  @{pods}
+  \  ${log} =   Retrieve Log For Pod     ${pod}             ${container}
+  \  Should Not Be Empty        ${log}   No log entries for ${pod}/${container}
+  \  ${line} =  Run Keyword If           "${regex}" != "${EMPTY}"
+  ...                                    Most Recent Match  ${log}  ${regex}
+  ...           ELSE
+  ...                                    Get From List      ${log}  -1
+  \  Append To List             ${logs}  ${line}
+  [Return]                      ${logs}
+
+#
+# Robot metatools
+Run Keyword If Present
+  [Documentation]  Run the given keyword, ignoring errors and returning status, if it exists.
+  ...              Returns "PASS" if the keyword does not exist.
+  [Arguments]            ${kw}
+  ${exists}  ${u} =      Run Keyword And Ignore Error
+  ...                    Keyword Should Exist          ${kw}
+  ${status}  ${u} =      Run Keyword If                '${exists}' == 'PASS'
+  ...                    Run Keyword And Ignore Error  ${kw}
+  ...                    ELSE
+  ...                    Set Variable   PASS  unused
+  [Return]               ${status}
+
+#
+# Data manipulation
+Toggle Flag
+    [Documentation]      Apply "not" to a boolean flag
+    [Arguments]          ${flag}
+    ${bFlag} =           Convert To Boolean  ${flag}
+    ${bFlag} =           Set Variable If     ${bFlag}  ${false}  ${true}
+    [Return]             ${bFlag}
+
+Most Recent Match
+    [Arguments]    ${list}        ${regex}
+    ${matches} =   Get Matches    ${list}     regexp=${regex}
+    Should Not Be Empty           ${matches}  No log entries matching ${regex}
+    ${match} =     Get From List  ${matches}  -1
+    [Return]       ${match}
+  
+Pluck
+     [Documentation]  Get the values of a specific key from a list of dictionaries
+     [Arguments]      ${k}      ${l}
+     @{names} =       Evaluate  filter(lambda v: v != None, [i.get('${k}', None) for i in ${l}])
+     [Return]         ${names}
+
+Subtract From List
+     [Documentation]  Remove the elements of the second argument from the first
+     [Arguments]      ${x}  ${y}
+     ${diff} =        Run Keyword If  ${y}
+     ...              Evaluate  filter(lambda v: v not in ${y}, ${x})
+     ...              ELSE
+     ...              Set Variable    ${x}
+     [Return]         ${diff}
diff --git a/ric_robot_suite/robot/resources/xapps/mcxapp_properties.robot b/ric_robot_suite/robot/resources/xapps/mcxapp_properties.robot
new file mode 100644
index 0000000..c9ca587
--- /dev/null
+++ b/ric_robot_suite/robot/resources/xapps/mcxapp_properties.robot
@@ -0,0 +1,30 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation        This file contains configuration specific to the MC xapp.
+
+*** Variables ***
+${GLOBAL_MCXAPP_LISTENER_NAME}        mc-xapp-listener
+${GLOBAL_MCXAPP_WRITER_NAME}          mc-xapp-writer
+@{GLOBAL_MCXAPP_WRITER_STATISTICS}    
+...                                   mc_connected_cnt
+...                                   mc_connection_stats
+...                                   mc_connects_cnt
+...                                   mc_disconnects_cnt
+...                                   mc_unique_ue_cnt
+...                                   rrcx_pdf_serv_cell
+...                                   rrcx_pdf_serv_gnb
+...                                   rrcx_stats_serv_cell
+...                                   rrcx_stats_serv_gnb
diff --git a/ric_robot_suite/robot/resources/xapps/placeholder_for_files b/ric_robot_suite/robot/resources/xapps/placeholder_for_files
deleted file mode 100644
index e69de29..0000000
--- a/ric_robot_suite/robot/resources/xapps/placeholder_for_files
+++ /dev/null
diff --git a/ric_robot_suite/robot/testsuites/mcxapp.robot b/ric_robot_suite/robot/testsuites/mcxapp.robot
new file mode 100644
index 0000000..dd85e45
--- /dev/null
+++ b/ric_robot_suite/robot/testsuites/mcxapp.robot
@@ -0,0 +1,103 @@
+#   Copyright (c) 2019 AT&T Intellectual Property.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+*** Settings ***
+Documentation  Tests for the Measurement Campaign XApp
+
+Resource       ../resources/xapps/mcxapp_properties.robot
+Resource       ../resources/global_properties.robot
+
+Library        Collections
+Library        KubernetesEntity          ${GLOBAL_XAPP_NAMESPACE}
+
+*** Variables ***
+${deploymentName} =         ${GLOBAL_XAPP_NAMESPACE}-mcxapp
+${listenerContainerName} =  mc-xapp-listener
+${listenerStatRegex} =      ^[0-9]+\\s*\\[STAT\\]\\s*\\(mcl\\)
+${recentListenerDrops} =    last 60s.*drops\\s*=\\s*[1-9]
+${recentListenerErrors} =   last 60s.*errs\\s*=\\s*[1-9]
+
+*** Test Cases ***
+MC XApp Should Be Available
+  [Tags]  etetests  xapptests  mcxapptests
+  ${deploy} =          Deployment           ${deploymentName}
+  ${status} =          Most Recent Availability Condition           @{deploy.status.conditions}
+  Should Be Equal As Strings   ${status}  True  ignore_case=True
+
+MC XApp Listener Should Not Be Dropping Messages
+  [Tags]  etetests  xapptests  mcxapptests
+  ${log} =  Most Recent Container Log  ${listenerContainerName}  ${listenerStatRegex}
+  Should Not Contain Match             ${log}                    ${recentListenerDrops}
+  
+MC XApp Listener Should Not Be Producing Errors
+  [Tags]  etetests  xapptests  mcxapptests
+  ${log} =  Most Recent Container Log  ${listenerContainerName}  ${listenerStatRegex}
+  Should Not Contain Match             ${log}                    ${recentListenerErrors}
+
+Writer Should Be Successfully Sending Statistics
+  [Tags]  etetests  xapptests  mcxapptests
+  Set Test Variable  ${finalStatus}  PASS
+  :FOR  ${stat}  IN  @{GLOBAL_MCXAPP_WRITER_STATISTICS}
+  \  ${statRE} =        Regexp Escape  ${stat}
+  \  ${log} =           Most Recent Container Log
+  ...                   ${GLOBAL_MCXAPP_WRITER_NAME}
+  ...                   ^${statRE}:\\s+successful\\s+ves\\s+posts\\.*
+  \  ${status}  ${u} =  Run Keyword And Ignore Error
+  ...                   Should Contain Match  ${log}  regexp=${writerVesSuccesses}
+  \  ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
+  ...                   FAIL
+  ...                   ${finalStatus}
+  \  Run Keyword If     "${status}" == "FAIL"
+  ...                   Log  No messages have been sent to VES for ${stat}
+  \  ${status}  ${u} =  Run Keyword And Ignore Error
+  ...                   Should Not Contain Match  ${log}  regexp=${writerVesErrors}
+  \  ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
+  ...                   FAIL
+  ...                   ${finalStatus}
+  \  Run Keyword If     "${status}" == "FAIL"
+  ...                   Log  ${stat} is producing errors logging to VES
+  Run Keyword If        "${finalStatus}" == "FAIL"
+  ...                   Fail  One or more statistics is not being succesfully logged
+
+*** Keywords ***
+Most Recent Availability Condition
+  # this makes the probably-unsafe assumption that the conditions are ordered
+  # temporally.
+  [Arguments]  @{Conditions}
+  ${status} =  Set Variable  'False'
+  :FOR  ${Condition}  IN  @{Conditions}
+  \  ${status} =  Set Variable If  '${Condition.type}' == 'Available'  ${Condition.status}  ${status}
+  [Return]  ${status}
+
+Most Recent Match
+  [Arguments]    ${list}        ${regex}
+  ${matches} =   Get Matches    ${list}     regexp=${regex}
+  Should Not Be Empty           ${matches}  No log entries matching ${regex}
+  ${match} =     Get From List  ${matches}  -1
+  [Return]       ${match}
+  
+Most Recent Container Log
+  [Arguments]   ${container}=${EMPTY}  ${regex}=${EMPTY}
+  ${pods} =            Retrieve Pods For Deployment  ${deploymentName}
+  ${logs} =            Create List
+  :FOR  ${pod}  IN  @{pods}
+  \  ${log} =   Retrieve Log For Pod     ${pod}             ${container}
+  \  Should Not Be Empty        ${log}   No log entries for ${pod}/${container}
+  \  ${line} =  Run Keyword If           "${regex}" != "${EMPTY}"
+  ...                                    Most Recent Match  ${log}  ${regex}
+  ...           ELSE
+  ...                                    Get From List      ${log}  -1
+  \  Append To List             ${logs}  ${line}
+  [Return]                      ${logs}
+
diff --git a/ric_robot_suite/robot/testsuites/ricdeployment.robot b/ric_robot_suite/robot/testsuites/ricdeployment.robot
index 5bede0a..db952c2 100644
--- a/ric_robot_suite/robot/testsuites/ricdeployment.robot
+++ b/ric_robot_suite/robot/testsuites/ricdeployment.robot
@@ -16,7 +16,9 @@
 *** Settings ***
 Documentation   Tests for the existence and functionality of RIC components
 
-Resource       /robot/resources/global_properties.robot
+Resource       ../global_properties.robot
+
+Resource       ../ric/ric_utils.robot
 
 Library  KubernetesEntity  ${GLOBAL_RICPLT_NAMESPACE}
 Library  Collections
@@ -30,13 +32,3 @@
   \  ${deploy} =          Deployment           ${deploymentName}
   \  ${status} =          Most Recent Availability Condition                @{deploy.status.conditions}
   \  Should Be Equal As Strings  ${status}  True  ignore_case=True  msg=${Component} is not available
-
-*** Keywords ***
-Most Recent Availability Condition
-  # this makes the probably-unsafe assumption that the conditions are ordered
-  # temporally.
-  [Arguments]  @{Conditions}
-  ${status} =  Set Variable  'False'
-  :FOR  ${Condition}  IN  @{Conditions}
-  \  ${status} =  Set Variable If  '${Condition.type}' == 'Available'  ${Condition.status}  ${status}
-  [Return]  ${status}
diff --git a/simulators/e2sim/.gitignore b/simulators/e2sim/.gitignore
index 16821e3..4cc349e 100644
--- a/simulators/e2sim/.gitignore
+++ b/simulators/e2sim/.gitignore
@@ -3,7 +3,10 @@
 temp/
 .tags
 .tags1
+.asn
 tools/asn1c
-build_and_run_e2sim
-test_e2_termination
-upload_to_demo_laptop
+tools/asn_defs/*.asn
+tools/asn_defs/*.asn1
+
+test/WLG/build/
+test/X2/build/
diff --git a/simulators/e2sim/CMakeLists.txt b/simulators/e2sim/CMakeLists.txt
index 3349545..c4e867a 100644
--- a/simulators/e2sim/CMakeLists.txt
+++ b/simulators/e2sim/CMakeLists.txt
@@ -1,71 +1,61 @@
-# Copyright 2019 AT&T Intellectual Property
-# Copyright 2019 Nokia
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
+#/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+#******************************************************************************/
 
 cmake_minimum_required(VERSION 3.5.1)
 set(CMAKE_CXX_COMPILER "/usr/bin/g++")
 set(CMAKE_CXX_STANDARD 14)
 
+add_definitions("-D ASN_DISABLE_OER_SUPPORT")
+
 project(e2sim)
 
-set (HOME_DIR     $ENV{HOME})
+set (E2SIM_ROOT ./)
 
-include_directories("src")
-include_directories("src/ASN1/lib")
-include_directories("src/SCTP/")
-include_directories("src/E2AP")
-include_directories("src/X2AP")
+include_directories("${E2SIM_ROOT}/src")
+include_directories("${E2SIM_ROOT}/src/DEF")
+include_directories("${E2SIM_ROOT}/src/SCTP/")
+include_directories("${E2SIM_ROOT}/src/E2AP")
+include_directories("${E2SIM_ROOT}/src/E2AP/E2SM")
+include_directories("${E2SIM_ROOT}/ASN1c")
 
-#for ASN1_API
-#include_directories("src/ASN1")
-#include_directories("src/ASN1/asn")
-#include_directories("src/ASN1/generated")
-#add_library(ASN1_API
-#  "src/ASN1/lib/asn_x2ap.cpp"
-#)
+find_library( SCTP_STD_LIB sctp )  #needed for sctp_sendmsg
 
-link_directories("build")
-
-#-----------------------------------------------
-file(GLOB E2AGENT_SOURCES
-      "src/e2agent.cpp"
-      "src/e2sim_defs.cpp"
-      "src/SCTP/*.cpp"
-      "src/E2AP/*.cpp"
+#----------------------------------------------
+file(GLOB E2SIM_SOURCES
+      "${E2SIM_ROOT}/e2sim.cpp"
+      "${E2SIM_ROOT}/src/DEF/*.cpp"
+      "${E2SIM_ROOT}/src/SCTP/*.cpp"
+      "${E2SIM_ROOT}/src/E2AP/*.c"
+      "${E2SIM_ROOT}/src/E2AP/*.cpp"
+      "${E2SIM_ROOT}/ASN1c/*.c"
       )
-add_executable(e2agent ${E2AGENT_SOURCES})
+add_executable(e2sim ${E2SIM_SOURCES})
+target_link_libraries( e2sim ${SCTP_STD_LIB} )
 
-#for ASN1_API
-target_link_libraries(e2agent ASN1_API)
-
-#-----------------------------------------------
-file(GLOB E2TERM_SOURCES
-      "src/e2termination_test.cpp"
-      "src/e2sim_defs.cpp"
-      "src/SCTP/*.cpp"
-      "src/E2AP/*.cpp"
+#----------------------------------------------
+file(GLOB RICSIM_SOURCES
+      "${E2SIM_ROOT}/ricsim.cpp"
+      "${E2SIM_ROOT}/src/DEF/*.cpp"
+      "${E2SIM_ROOT}/src/SCTP/*.cpp"
+      "${E2SIM_ROOT}/src/E2AP/*.c"
+      "${E2SIM_ROOT}/src/E2AP/*.cpp"
+      "${E2SIM_ROOT}/ASN1c/*.c"
       )
-add_executable(e2term ${E2TERM_SOURCES})
-target_link_libraries(e2term ASN1_API)
-
-#-----------------------------------------------
-file(GLOB X2TERM_SOURCES
-      "src/x2termination_test.cpp"
-      "src/e2sim_defs.cpp"
-      "src/SCTP/*.cpp"
-      "src/X2AP/*.cpp"
-      )
-add_executable(x2term ${X2TERM_SOURCES})
-target_link_libraries(x2term ASN1_API)
+add_executable(ricsim ${RICSIM_SOURCES})
+target_link_libraries( ricsim ${SCTP_STD_LIB} )
diff --git a/simulators/e2sim/README.md b/simulators/e2sim/README.md
index 6c8d10c..db93deb 100644
--- a/simulators/e2sim/README.md
+++ b/simulators/e2sim/README.md
@@ -1,4 +1,4 @@
-/*****************************************************************************
+#/*****************************************************************************
 #                                                                            *
 # Copyright 2019 AT&T Intellectual Property                                  *
 # Copyright 2019 Nokia                                                       *
@@ -15,11 +15,11 @@
 # See the License for the specific language governing permissions and        *
 # limitations under the License.                                             *
 #                                                                            *
-******************************************************************************/
+#******************************************************************************/
 
-# INSTALLATION
-  * Tested environment: Ubuntu 16.04
-  * Install dependencies
+
+# INSTALLATION (tested on Ubuntu 16.04)
+  1. Install dependencies
     $ sudo apt-get update
     $ sudo apt-get install -y
         build-essential
@@ -35,40 +35,51 @@
         libboost-all-dev
     $ sudo apt-get clean
 
-  ## Build
+  2. SET ENVIRONMENT VARIABLE
+    Add this line to `~/.bashrc`
+      export E2SIM_DIR=<your e2sim directory>
+
+  3. Build the official e2sim
     $ ./build_e2sim
 
-# SET ENVIRONMENT VARIABLE
-  Add this line to `~/.bashrc`
-  $  export E2SIM_DIR=<your e2sim directory>
+# USAGE
+  $  $E2SIM_DIR/build/e2sim [SERVER IP] [PORT]
 
-# RUN E2SIM
-  $  cd $E2SIM_DIR/build/
-  $ ./e2agent [SERVER IP] [PORT]
-
-  By default, SERVER IP = 127.0.0.1, PORT = 36422 (X2AP Port)
+  By default, SERVER IP = 127.0.0.1, PORT = 36421
 
 # DOCKER
   Note: The commands in this section must be run from $E2SIM_DIR
 
   * Build docker image
-  $ ./build_docker
+  $ sudo docker build -f docker/Dockerfile -t [DOCKER_IMAGE]:[TAG] .
 
-  ## Run docker container
-  $ sudo docker run --rm --net host -it e2agent sh -c "./build/e2agent [SERVER IP] [PORT]"
+  * Example how to run docker container
+  $ sudo docker run --rm --net host -it [DOCKER_IMAGE]:[TAG] sh -c "./build/e2sim [SERVER IP] [PORT]"
 
-# SUPPORTED MESSAGE FLOWS (Last updated May 24, 2019)
+# SUPPORTED MESSAGE FLOWS
 
-- X2 SETUP REQUEST          (RIC -> RAN)
-- X2 SETUP RESPONSE         (RAN -> RIC)
+- RIC INDICATION            (RAN -> RIC)      version 1.3.0   September 13, 2019
+    SgNBAdditionRequest
+
+- RIC SUBSCRIPTION REQUEST  (RIC -> RAN)      version 1.2.0   May 24, 2019
+- RIC SUBSCRIPTION RESPONSE (RAN -> RIC)
+- RIC SUBSCRIPTION FAILURE  (RAN -> RIC)
 
 - ENDC X2 SETUP REQUEST     (RIC -> RAN)
 - ENDC X2 SETUP RESPONSE    (RAN -> RIC)
 
-- RIC SUBSCRIPTION REQUEST  (RIC -> RAN)
-- RIC SUBSCRIPTION RESPONSE (RAN -> RIC)
-- RIC SUBSCRIPTION FAILURE  (RAN -> RIC)
+- X2 SETUP REQUEST          (RIC -> RAN)
+- X2 SETUP RESPONSE         (RAN -> RIC)
 
+# GENERATING ASN1C CODES FOR E2AP, E2SM, X2AP
+ 1. Install asn1c compiler
+ ./tools/install_asn1c
+
+ 2. Generate asn1c codes using e2ap, e2sm and x2ap specs
+ Download the following files into tools/asn_defs
+  - e2ap-v031.asn
+  - e2sm-gNB-X2-release-1-v041.asn
+  - x2ap-no-desc-15-04.asn
 
 # Change logs:
   03/12/2019: currently supports sending and receiving X2 SETUP messages
diff --git a/simulators/e2sim/build_and_run_e2agent b/simulators/e2sim/build_and_run_e2agent
deleted file mode 100755
index 1af78d6..0000000
--- a/simulators/e2sim/build_and_run_e2agent
+++ /dev/null
@@ -1,32 +0,0 @@
-#*****************************************************************************
-#                                                                            *
-# Copyright 2019 AT&T Intellectual Property                                  *
-# Copyright 2019 Nokia                                                       *
-#                                                                            *
-# Licensed under the Apache License, Version 2.0 (the "License");            *
-# you may not use this file except in compliance with the License.           *
-# You may obtain a copy of the License at                                    *
-#                                                                            *
-#      http://www.apache.org/licenses/LICENSE-2.0                            *
-#                                                                            *
-# Unless required by applicable law or agreed to in writing, software        *
-# distributed under the License is distributed on an "AS IS" BASIS,          *
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
-# See the License for the specific language governing permissions and        *
-# limitations under the License.                                             *
-#                                                                            *
-#*****************************************************************************
-
-# Run a default build and run the e2sim executable
-
-set -e
-
-clear
-
-./build_e2sim --clean
-
-./build_e2sim
-
-echo "===================== Running E2 Agent Simulator ========================"
-
-./build/e2agent
diff --git a/simulators/e2sim/build_e2sim b/simulators/e2sim/build_e2sim
index a24ba14..ede61a7 100755
--- a/simulators/e2sim/build_e2sim
+++ b/simulators/e2sim/build_e2sim
@@ -1,105 +1,50 @@
 #!/bin/bash
-#
-#
-# Copyright 2019 AT&T Intellectual Property
-# Copyright 2019 Nokia
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# build utility for E2 Agent
+#/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+#******************************************************************************/
 
 set -e
 
-E2SIM_DIR=$PWD
-ASN1_C_DIR=$E2SIM_DIR/build/CMakeFiles/ASN1
-
+E2SIM_VERSION='1.3.0'
+export E2SIM_DIR=$PWD
 source $E2SIM_DIR/tools/build_helper.bash
+DOCKER_IMAGE='e2sim'
 
-print_help()
-{
+print_help() {
   echo "
     This program installs E2 Simulator
     You should have ubuntu 14.xx, updated, and the Linux kernel >= 3.14
     The program is run by default with no option
 
-    Options
+    USAGE:
+      ./build_e2sim [OPTIONS]
+
+    OPTIONS:
     --clean
        Erase all files to make a rebuild from start
+    --docker
+       Build docker image
     -h
        Print this help
     "
 }
 
-generate_asn1c_codes()
-{
-  X2AP_RELEASE="R14"
-  X2AP_ASN_FILES="x2ap-14.6.0.asn1"
-  ASN_SOURCE_X2AP=$E2SIM_DIR/src/X2AP/MESSAGES/ASN1/${X2AP_RELEASE}/${X2AP_ASN_FILES}
-
-  ASN_SOURCE_Pendulum=$E2SIM_DIR/src/ONS2019/pendulum.asn1
-
-  done_flag="$ASN1_C_DIR"/done
-
-  #-ot = older than, -nt = newer than
-
-  if [ "$done_flag" -ot $ASN_SOURCE_X2AP ] ; then
-    echo_info "Generate C codes for from source file"
-    #echo_info $ASN_SOURCE
-
-    rm -f "$ASN1_C_DIR"/*.c "$ASN1_C_DIR"/*.h
-    mkdir -p $ASN1_C_DIR
-    asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
-                -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_X2AP  \
-                |& egrep -v "^Copied|^Compiled" | sort -u
-
-    asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
-                -fno-include-deps -D $ASN1_C_DIR $ASN_SOURCE_Pendulum  \
-                |& egrep -v "^Copied|^Compiled" | sort -u
-
-    echo_success "ASN1 C codes generated at: $ASN1_C_DIR"
-  fi
-  touch $done_flag
-}
-
-install_rmr()
-{
-  echo_info "Will install rmr library"
-  /bin/bash rmr_interface/rmr_install.sh
-}
-
-compile_asn_api_lib()
-{
-  echo_info "Will complie ASN1_API library"
-  # rm -rf build/libASN1_API.a
-  # rm -rf build/asn_x2ap.o
-  # rm -rf build/asn_e2ap.o
-
-  g++ -O3  -std=c++14 -Wall \
-    -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/  \
-    -c src/ASN1/lib/asn_e2ap.cpp \
-    -o build/asn_e2ap.o
-    ar -crv build/libASN1_API.a build/asn_e2ap.o
-
-  g++ -O3  -std=c++14 -Wall \
-    -I./src/ASN1/ -I./src/ASN1/asn/ -I./src/ASN1/generated/  \
-    -c src/ASN1/lib/asn_x2ap.cpp \
-    -o build/asn_x2ap.o
-    ar -crv build/libASN1_API.a build/asn_x2ap.o
-}
-
-function main()
-{
-
+function main(){
   case "$1" in
     --clean)
       echo_info "Will clean all previously producted files under build/"
@@ -108,19 +53,15 @@
       exit
       ;;
 
+    --docker)
+      echo "Will build docker image ${DOCKER_IMAGE}:${E2SIM_VERSION}"
+      sudo docker build -f docker/Dockerfile -t $DOCKER_IMAGE:$E2SIM_VERSION .
+      exit
+      ;;
+
     "")
       ;;
 
-    --rmr)
-      install_rmr
-      exit
-      ;;
-
-    --lib)
-      compile_asn_api_lib
-      exit
-      ;;
-
     -h)
       print_help
       exit 1;;
@@ -132,11 +73,6 @@
 
   BUILD_DIR=$E2SIM_DIR/build
   mkdir -p $BUILD_DIR
-  mkdir -p $BUILD_DIR/log
-
-  # generate_asn1c_codes #X2AP, pendulum
-
-  compile_asn_api_lib
 
   echo_info "Will build e2sim"
   cd $BUILD_DIR
@@ -145,7 +81,6 @@
   make -j`nproc`
 
   echo_success "e2sim compiled"
-
 }
 
 main "$@"
diff --git a/simulators/e2sim/docker/Dockerfile b/simulators/e2sim/docker/Dockerfile
index f1b6b62..3bee1c0 100644
--- a/simulators/e2sim/docker/Dockerfile
+++ b/simulators/e2sim/docker/Dockerfile
@@ -36,6 +36,10 @@
 	bison \
 	flex \
   libboost-all-dev \
+	iputils-ping \
+	net-tools \
+	nano \
+	vim \
   && apt-get clean
 
 # Copy E2Sim sources into the container
diff --git a/simulators/e2sim/src/e2agent.cpp b/simulators/e2sim/e2sim.cpp
similarity index 84%
rename from simulators/e2sim/src/e2agent.cpp
rename to simulators/e2sim/e2sim.cpp
index 07d52cd..77f6be1 100644
--- a/simulators/e2sim/src/e2agent.cpp
+++ b/simulators/e2sim/e2sim.cpp
@@ -24,33 +24,12 @@
 
 #include "e2sim_defs.h"
 #include "e2sim_sctp.hpp"
-#include "asn_e2ap.hpp"
 #include "e2ap_message_handler.hpp"
 
 using namespace std;
 
-void test(void)
-{
-  e2ap_pdu_t* pdu = new_e2ap_pdu();
-
-  gNB_config gnb_cfg;
-
-  e2ap_create_ENDCX2SetupResponse(pdu, gnb_cfg);
-
-  e2ap_print_pdu(pdu);
-
-  //Encode into buffer
-  sctp_buffer_t data;
-  e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
-
-}
-
 int main(int argc, char* argv[]){
-
-  LOG_I("E2 Agent (E2 Simulator) Version %s", VERSION);
-
-  // test();
-  // return 0;
+  LOG_I("Start E2 Agent (E2 Simulator)");
 
   options_t ops = read_input_options(argc, argv);
 
@@ -60,6 +39,7 @@
   sctp_buffer_t recv_buf;
 
   LOG_I("[SCTP] Waiting for SCTP data");
+
   while(1) //constantly looking for data on SCTP interface
   {
     if(sctp_receive_data(client_fd, recv_buf) <= 0)
diff --git a/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl b/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl
index 8f7c954..35e01c4 100755
--- a/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl
+++ b/simulators/e2sim/helm/e2sim/templates/bin/_e2sim-run.sh.tpl
@@ -51,4 +51,4 @@
   echo "e2sim starting at ${E2SIM_BIND_ADDR}:${E2SIM_PORT:-36421}"
 fi
 
-${E2SIM:-/home/e2sim/build/e2agent} ${E2SIM_BIND_ADDR} ${E2SIM_PORT:-36421}
+${E2SIM:-/home/e2sim/build/e2sim} ${E2SIM_BIND_ADDR} ${E2SIM_PORT:-36421}
diff --git a/simulators/e2sim/ricsim.cpp b/simulators/e2sim/ricsim.cpp
new file mode 100644
index 0000000..e42e9d2
--- /dev/null
+++ b/simulators/e2sim/ricsim.cpp
@@ -0,0 +1,89 @@
+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "e2sim_sctp.hpp"
+#include "e2ap_message_handler.hpp"
+
+extern "C" {
+  #include "e2sim_defs.h"
+  #include "E2AP-PDU.h"
+  #include "e2ap_asn1c_codec.h"
+}
+
+using namespace std;
+
+void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
+{
+  uint8_t       *buf;
+  sctp_buffer_t data;
+
+  data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
+  memcpy(data.buffer, buf, data.len);
+
+  sctp_send_data(client_fd, data);
+}
+
+void wait_for_sctp_data(int client_fd)
+{
+  sctp_buffer_t recv_buf;
+  if(sctp_receive_data(client_fd, recv_buf) > 0)
+  {
+    LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
+    e2ap_handle_sctp_data(client_fd, recv_buf);
+  }
+}
+
+int main(int argc, char* argv[]){
+  LOG_I("Start RIC Simulator");
+
+  options_t ops = read_input_options(argc, argv);
+  int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
+
+  //1. Send ENDCX2Setup
+  E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml");
+  e2ap_asn1c_print_pdu(pdu_setup);
+  encode_and_send_sctp_data(pdu_setup, client_fd);
+  LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
+
+  //2. Receive ENDCX2SetupResponse
+  wait_for_sctp_data(client_fd);
+
+  //3. Send RICSubscriptionRequest
+  E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml");
+  e2ap_asn1c_print_pdu(pdu_sub);
+  encode_and_send_sctp_data(pdu_sub, client_fd);
+  LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST");
+
+  //4. Receive RICSubscriptionResponse
+  while(1){
+    wait_for_sctp_data(client_fd);
+  }
+
+
+  //---------------------------------------
+  close(client_fd);
+  LOG_I("[SCTP] Connection closed.");
+
+  return 0;
+
+}
diff --git a/simulators/e2sim/src/e2sim_defs.cpp b/simulators/e2sim/src/DEF/e2sim_defs.cpp
similarity index 100%
rename from simulators/e2sim/src/e2sim_defs.cpp
rename to simulators/e2sim/src/DEF/e2sim_defs.cpp
diff --git a/simulators/e2sim/src/e2sim_defs.h b/simulators/e2sim/src/DEF/e2sim_defs.h
similarity index 84%
rename from simulators/e2sim/src/e2sim_defs.h
rename to simulators/e2sim/src/DEF/e2sim_defs.h
index 30a0165..74bf619 100644
--- a/simulators/e2sim/src/e2sim_defs.h
+++ b/simulators/e2sim/src/DEF/e2sim_defs.h
@@ -20,12 +20,16 @@
 #ifndef E2SIM_DEFS_H
 #define E2SIM_DEFS_H
 
-#include <iostream>
+// #include <iostream>
+#include <stdio.h>
+#include <stdlib.h>
 
 #define VERSION             "1.2.0"      //May 2019
 #define DEFAULT_SCTP_IP     "127.0.0.1"
-#define X2AP_SCTP_PORT       36422
-#define MAX_SCTP_BUFFER      1024
+#define X2AP_PPID           (452984832) //27 = 1b, PPID = 1b000000(hex) -> 452984832(dec)
+#define X2AP_SCTP_PORT      36421
+#define RIC_SCTP_SRC_PORT   36422
+#define MAX_SCTP_BUFFER     1024
 #define WORKDIR_ENV         "E2SIM_DIR" //environment variable
 
 #define LOG_I(...) {printf(__VA_ARGS__); printf("\n");}
diff --git a/simulators/e2sim/src/E2AP/E2SM/e2sm.c b/simulators/e2sim/src/E2AP/E2SM/e2sm.c
new file mode 100644
index 0000000..6cad6cd
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/E2SM/e2sm.c
@@ -0,0 +1,196 @@
+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+#include "e2sm.h"
+
+#include "ActionParameter-Item.h"
+#include "ActionParameter-Value.h"
+#include "PLMN-Identity.h"
+#include "GlobalENB-ID.h"
+#include "GlobalGNB-ID.h"
+#include "Interface-ID.h"
+#include "ProtocolIE-Field.h"
+#include "InterfaceMessageType.h"
+#include "InterfaceProtocolIE-Item.h"
+
+static PLMN_Identity_t *createPLMN_ID(const unsigned char *data) {
+
+    PLMN_Identity_t *plmnId = calloc(1, sizeof(PLMN_Identity_t));
+    ASN_STRUCT_RESET(asn_DEF_PLMN_Identity, plmnId);
+    plmnId->size = 3;
+    plmnId->buf = calloc(1, 3);
+    memcpy(plmnId->buf, data, 3);
+
+    return plmnId;
+}
+
+static GNB_ID_t *createGnb_id(const unsigned char *data, int numOfBits) {
+
+    if (numOfBits < 22 || numOfBits > 32) {
+        printf("[Error] GNB_ID_t number of bits = %d, needs to be 22 .. 32", numOfBits);
+        return NULL;
+    }
+
+    GNB_ID_t *gnb = calloc(1, sizeof(GNB_ID_t));
+    ASN_STRUCT_RESET(asn_DEF_GNB_ID, gnb);
+
+    gnb->present = GNB_ID_PR_gNB_ID;
+    gnb->choice.gNB_ID.size = numOfBits % 8 == 0 ? (unsigned int)(numOfBits / 8) : (unsigned int)(numOfBits / 8 + 1);
+    gnb->choice.gNB_ID.bits_unused = gnb->choice.gNB_ID.size * 8 - numOfBits;
+    gnb->choice.gNB_ID.buf = calloc(1, gnb->choice.gNB_ID.size);
+    memcpy(gnb->choice.gNB_ID.buf, data, gnb->choice.gNB_ID.size);
+    gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] =
+            ((unsigned)(gnb->choice.gNB_ID.buf[gnb->choice.gNB_ID.size - 1] >> (unsigned)gnb->choice.gNB_ID.bits_unused)
+                  << (unsigned)gnb->choice.gNB_ID.bits_unused);
+
+    return gnb;
+}
+
+static GlobalGNB_ID_t *createGlobalGNB_ID(PLMN_Identity_t *plmnIdentity, GNB_ID_t *gnb) {
+
+    GlobalGNB_ID_t *ggnbId = calloc(1, sizeof(GlobalGNB_ID_t));
+    ASN_STRUCT_RESET(asn_DEF_GlobalGNB_ID, ggnbId);
+
+    memcpy(&ggnbId->pLMN_Identity, plmnIdentity, sizeof(PLMN_Identity_t));
+    memcpy(&ggnbId->gNB_ID, gnb, sizeof(GNB_ID_t));
+
+    return ggnbId;
+}
+
+static Interface_ID_t *createInterfaceIDForGnb(GlobalGNB_ID_t *gnb) {
+
+    Interface_ID_t *interfaceId = calloc(1, sizeof(Interface_ID_t));
+    ASN_STRUCT_RESET(asn_DEF_Interface_ID, interfaceId);
+
+    interfaceId->present = Interface_ID_PR_global_gNB_ID;
+    interfaceId->choice.global_gNB_ID = gnb;
+
+    return interfaceId;
+}
+
+static InterfaceMessageType_t *createInterfaceMessageInitiating(long procedureCode) {
+
+    InterfaceMessageType_t *intMsgT = calloc(1, sizeof(InterfaceMessageType_t));
+    ASN_STRUCT_RESET(asn_DEF_InterfaceMessageType, intMsgT);
+
+    intMsgT->procedureCode = procedureCode;
+    intMsgT->typeOfMessage = TypeOfMessage_initiating_message;
+
+    return intMsgT;
+}
+
+E2SM_gNB_X2_eventTriggerDefinition_t* create_eventTriggerDefinition(void)
+{
+  //PLMN_Identity
+  unsigned char plmnidData[3] = {0x33, 0xF4, 0x55};
+  PLMN_Identity_t *plmnid = createPLMN_ID(plmnidData);
+  // xer_fprint(stdout, &asn_DEF_PLMN_Identity, (void *)plmnid);
+
+  //GNB_ID
+  unsigned char gnbData[3] = {0x99, 0xaa, 0xbb};
+  GNB_ID_t *gnb = createGnb_id(gnbData, 26);
+  // xer_fprint(stdout, &asn_DEF_GNB_ID, (void *)gnb);
+
+  //GlobalGNB_ID
+  GlobalGNB_ID_t *globaGnb = createGlobalGNB_ID(plmnid, gnb);
+  // xer_fprint(stdout, &asn_DEF_GlobalGNB_ID, (void *)globaGnb);
+
+  //Interface_ID
+  Interface_ID_t *gnbInterfaceId = createInterfaceIDForGnb(globaGnb);
+  // xer_fprint(stdout, &asn_DEF_Interface_ID, (void *)gnbInterfaceId);
+
+  //InterfaceMessageType
+  InterfaceMessageType_t *initiatingInterface = createInterfaceMessageInitiating(35);
+
+  //EventTriggerDefinition
+  E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
+  ASN_STRUCT_RESET(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, eventTrigger);
+
+  memcpy(&eventTrigger->interface_ID , gnbInterfaceId, sizeof(Interface_ID_t));
+
+  eventTrigger->interfaceDirection = 0;
+  memcpy(&eventTrigger->interfaceMessageType, initiatingInterface, sizeof(InterfaceMessageType_t));
+
+  return eventTrigger;
+}
+
+#define E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID) \
+  do {\
+    IE_TYPE **ptr; \
+    ie = NULL; \
+    for (ptr = container->protocolIEs.list.array; \
+         ptr < &container->protocolIEs.list.array[container->protocolIEs.list.count]; \
+         ptr++) { \
+      if((*ptr)->id == IE_ID) { \
+        ie = *ptr; \
+        break; \
+      } \
+    } \
+  } while(0)
+
+
+void test_eventTriggerDefinition(void)
+{
+  E2SM_gNB_X2_eventTriggerDefinition_t *eventTrigger = create_eventTriggerDefinition();
+
+  xer_fprint(stdout, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, (void *)eventTrigger);
+  printf("\n");
+
+  uint8_t *eventBuff;
+  int eventBuff_len;
+
+  eventBuff_len = aper_encode_to_new_buffer(&asn_DEF_E2SM_gNB_X2_eventTriggerDefinition,
+                                        0, eventTrigger, (void **)&eventBuff);
+
+  LOG_I("Encoded eventBuff_len = %d", eventBuff_len);
+
+  //-----------------------------------------------------------------------
+  E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
+  e2ap_asn1c_print_pdu(pdu);
+
+  InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
+  xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage);
+
+  RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest;
+  xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request);
+
+  LOG_I("num of IEs = %d", request->protocolIEs.list.count);
+
+
+  RICsubscriptionRequest_IEs_t *ie;
+
+  ie = request->protocolIEs.list.array[2];
+
+  // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICsubscription);
+  // E2AP_ASN1C_FIND_PROTOCOLIE_BY_ID(RICsubscriptionRequest_IEs_t, ie, request, ProtocolIE_ID_id_RICrequestID);
+
+  assert( ie != NULL);
+
+  xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie);
+  // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)ie);
+
+
+}
+
+//
+// typedef struct ProtocolIE_Container_119P0 {
+// 	A_SEQUENCE_OF(struct RICsubscriptionRequest_IEs) list;
+//
+// 	/* Context for parsing across buffer boundaries */
+// 	asn_struct_ctx_t _asn_ctx;
+// } ProtocolIE_Container_119P0_t;
diff --git a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp b/simulators/e2sim/src/E2AP/E2SM/e2sm.h
similarity index 78%
rename from simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp
rename to simulators/e2sim/src/E2AP/E2SM/e2sm.h
index 6fd6170..19f30a2 100644
--- a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp
+++ b/simulators/e2sim/src/E2AP/E2SM/e2sm.h
@@ -1,34 +1,30 @@
-/*****************************************************************************

-#                                                                            *

-# Copyright 2019 AT&T Intellectual Property                                  *

-# Copyright 2019 Nokia                                                       *

-#                                                                            *

-# Licensed under the Apache License, Version 2.0 (the "License");            *

-# you may not use this file except in compliance with the License.           *

-# You may obtain a copy of the License at                                    *

-#                                                                            *

-#      http://www.apache.org/licenses/LICENSE-2.0                            *

-#                                                                            *

-# Unless required by applicable law or agreed to in writing, software        *

-# distributed under the License is distributed on an "AS IS" BASIS,          *

-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *

-# See the License for the specific language governing permissions and        *

-# limitations under the License.                                             *

-#                                                                            *

-******************************************************************************/

-#ifndef E2AP_ASN_CODEC_HPP

-#define E2AP_ASN_CODEC_HPP

-

-#include "e2sim_defs.h"

-#include "asn_e2ap.hpp"

-

-#define ERROR_MESSAGE_BUFFER 1024

-#define PDU_PRINT_BUFFER     4096

-

-void e2ap_encode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int buf_size, int &encoded_size);

-

-void e2ap_decode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int &encoded_size);

-

-void e2ap_print_pdu(e2ap_pdu_t* pdu);

-

-#endif

+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+#ifndef E2SM_H
+#define E2SM_H
+
+#include "E2SM-gNB-X2-eventTriggerDefinition.h"
+#include "E2AP-PDU.h"
+#include "e2ap_asn1c_codec.h"
+
+E2SM_gNB_X2_eventTriggerDefinition_t* create_eventTriggerDefinition(void);
+
+void test_eventTriggerDefinition(void);
+
+#endif
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml
new file mode 100644
index 0000000..633baee
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupFailure.xml
@@ -0,0 +1,21 @@
+<E2AP-PDU>
+    <unsuccessfulOutcome>
+        <procedureCode>36</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <ENDCX2SetupFailure>
+                <protocolIEs>
+                    <ENDCX2SetupFailure-IEs>
+                        <id>5</id>
+                        <criticality><ignore/></criticality>
+                        <value>
+                            <Cause>
+                                <radioNetwork><ho-target-not-allowed/></radioNetwork>
+                            </Cause>
+                        </value>
+                    </ENDCX2SetupFailure-IEs>
+                </protocolIEs>
+            </ENDCX2SetupFailure>
+        </value>
+    </unsuccessfulOutcome>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml
new file mode 100644
index 0000000..ddb071a
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupRequest.xml
@@ -0,0 +1,67 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>36</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <ENDCX2SetupRequest>
+                <protocolIEs>
+                    <ENDCX2SetupRequest-IEs>
+                        <id>244</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <InitiatingNodeType-EndcX2Setup>
+                                <init-eNB>
+                                    <ENB-ENDCX2SetupReqIEs>
+                                        <id>21</id>
+                                        <criticality><reject/></criticality>
+                                        <value>
+                                            <GlobalENB-ID>
+                                                <pLMN-Identity>61 62 63</pLMN-Identity>
+                                                <eNB-ID>
+                                                    <macro-eNB-ID>
+                                                        00110101000000000001
+                                                    </macro-eNB-ID>
+                                                </eNB-ID>
+                                            </GlobalENB-ID>
+                                        </value>
+                                    </ENB-ENDCX2SetupReqIEs>
+                                    <ENB-ENDCX2SetupReqIEs>
+                                        <id>250</id>
+                                        <criticality><reject/></criticality>
+                                        <value>
+                                            <ServedEUTRAcellsENDCX2ManagementList>
+                                                <SEQUENCE>
+                                                    <servedEUTRACellInfo>
+                                                        <pCI>0</pCI>
+                                                        <cellId>
+                                                            <pLMN-Identity>61 62 63</pLMN-Identity>
+                                                            <eUTRANcellIdentifier>
+                                                                0110010001100101011001100000
+                                                            </eUTRANcellIdentifier>
+                                                        </cellId>
+                                                        <tAC>61 62</tAC>
+                                                        <broadcastPLMNs>
+                                                            <PLMN-Identity>61 62 63</PLMN-Identity>
+                                                        </broadcastPLMNs>
+                                                        <eUTRA-Mode-Info>
+                                                            <fDD>
+                                                                <uL-EARFCN>21400</uL-EARFCN>
+                                                                <dL-EARFCN>3400</dL-EARFCN>
+                                                                <uL-Transmission-Bandwidth><bw25/></uL-Transmission-Bandwidth>
+                                                                <dL-Transmission-Bandwidth><bw50/></dL-Transmission-Bandwidth>
+                                                            </fDD>
+                                                        </eUTRA-Mode-Info>
+                                                    </servedEUTRACellInfo>
+                                                </SEQUENCE>
+                                            </ServedEUTRAcellsENDCX2ManagementList>
+                                        </value>
+                                    </ENB-ENDCX2SetupReqIEs>
+                                </init-eNB>
+                            </InitiatingNodeType-EndcX2Setup>
+                        </value>
+                    </ENDCX2SetupRequest-IEs>
+                </protocolIEs>
+            </ENDCX2SetupRequest>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml
new file mode 100644
index 0000000..896eed6
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_ENDCX2SetupResponse.xml
@@ -0,0 +1,97 @@
+<E2AP-PDU>
+    <successfulOutcome>
+        <procedureCode>36</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <ENDCX2SetupResponse>
+                <protocolIEs>
+                    <ENDCX2SetupResponse-IEs>
+                        <id>246</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RespondingNodeType-EndcX2Setup>
+                                <respond-en-gNB>
+                                    <En-gNB-ENDCX2SetupReqAckIEs>
+                                        <id>252</id>
+                                        <criticality><reject/></criticality>
+                                        <value>
+                                            <GlobalGNB-ID>
+                                                <pLMN-Identity>02 F8 29</pLMN-Identity>
+                                                <gNB-ID>
+                                                    <gNB-ID>
+                                                        000000000001001000110100
+                                                    </gNB-ID>
+                                                </gNB-ID>
+                                            </GlobalGNB-ID>
+                                        </value>
+                                    </En-gNB-ENDCX2SetupReqAckIEs>
+                                    <En-gNB-ENDCX2SetupReqAckIEs>
+                                        <id>253</id>
+                                        <criticality><reject/></criticality>
+                                        <value>
+                                            <ServedNRcellsENDCX2ManagementList>
+                                                <SEQUENCE>
+                                                    <servedNRCellInfo>
+                                                        <nrpCI>99</nrpCI>
+                                                        <nrCellID>
+                                                            <pLMN-Identity>02 F8 29</pLMN-Identity>
+                                                            <nRcellIdentifier>
+                                                                000000000000011110101011000000010010
+                                                            </nRcellIdentifier>
+                                                        </nrCellID>
+                                                        <broadcastPLMNs>
+                                                            <PLMN-Identity>02 F8 29</PLMN-Identity>
+                                                        </broadcastPLMNs>
+                                                        <nrModeInfo>
+                                                            <fdd>
+                                                                <ul-NRFreqInfo>
+                                                                    <nRARFCN>100</nRARFCN>
+                                                                    <freqBandListNr>
+                                                                        <FreqBandNrItem>
+                                                                            <freqBandIndicatorNr>9</freqBandIndicatorNr>
+                                                                            <supportedSULBandList>
+                                                                                <SupportedSULFreqBandItem>
+                                                                                    <freqBandIndicatorNr>9</freqBandIndicatorNr>
+                                                                                </SupportedSULFreqBandItem>
+                                                                            </supportedSULBandList>
+                                                                        </FreqBandNrItem>
+                                                                    </freqBandListNr>
+                                                                </ul-NRFreqInfo>
+                                                                <dl-NRFreqInfo>
+                                                                    <nRARFCN>100</nRARFCN>
+                                                                    <freqBandListNr>
+                                                                        <FreqBandNrItem>
+                                                                            <freqBandIndicatorNr>9</freqBandIndicatorNr>
+                                                                            <supportedSULBandList>
+                                                                                <SupportedSULFreqBandItem>
+                                                                                    <freqBandIndicatorNr>9</freqBandIndicatorNr>
+                                                                                </SupportedSULFreqBandItem>
+                                                                            </supportedSULBandList>
+                                                                        </FreqBandNrItem>
+                                                                    </freqBandListNr>
+                                                                </dl-NRFreqInfo>
+                                                                <ul-NR-TxBW>
+                                                                    <nRSCS><scs15/></nRSCS>
+                                                                    <nRNRB><nrb11/></nRNRB>
+                                                                </ul-NR-TxBW>
+                                                                <dl-NR-TxBW>
+                                                                    <nRSCS><scs15/></nRSCS>
+                                                                    <nRNRB><nrb11/></nRNRB>
+                                                                </dl-NR-TxBW>
+                                                            </fdd>
+                                                        </nrModeInfo>
+                                                        <measurementTimingConfiguration>04 05</measurementTimingConfiguration>
+                                                    </servedNRCellInfo>
+                                                </SEQUENCE>
+                                            </ServedNRcellsENDCX2ManagementList>
+                                        </value>
+                                    </En-gNB-ENDCX2SetupReqAckIEs>
+                                </respond-en-gNB>
+                            </RespondingNodeType-EndcX2Setup>
+                        </value>
+                    </ENDCX2SetupResponse-IEs>
+                </protocolIEs>
+            </ENDCX2SetupResponse>
+        </value>
+    </successfulOutcome>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml b/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml
new file mode 100644
index 0000000..8974693
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_ErrorIndication.xml
@@ -0,0 +1,21 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>3</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <ErrorIndication>
+                <protocolIEs>
+                    <ErrorIndication-IEs>
+                        <id>5</id>
+                        <criticality><ignore/></criticality>
+                        <value>
+                            <Cause>
+                                <radioNetwork><ho-target-not-allowed/></radioNetwork>
+                            </Cause>
+                        </value>
+                    </ErrorIndication-IEs>
+                </protocolIEs>
+            </ErrorIndication>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml
new file mode 100644
index 0000000..e4e3f38
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type1.xml
@@ -0,0 +1,74 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>205</procedureCode>
+        <criticality><ignore/></criticality>
+        <value>
+            <RICindication>
+                <protocolIEs>
+                    <RICindication-IEs>
+                        <id>60030</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICrequestID>
+                                <ricRequestorID>6</ricRequestorID>
+                                <ricRequestSequenceNumber>12</ricRequestSequenceNumber>
+                            </RICrequestID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60003</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RANfunctionID>10</RANfunctionID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60017</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICactionID>100</RICactionID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60028</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationSN>100</RICindicationSN>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60029</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationType><report/></RICindicationType>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60026</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationHeader>10 74 68 65 10 68 65 6C 40</RICindicationHeader>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60027</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationMessage>
+                                00 1B 40 80 80 00 00 08 00 6F 00 02 00 0C 00 F8
+                                00 05 08 4D 86 D6 40 00 CB 00 20 31 32 33 34 35
+                                36 37 38 39 31 32 33 34 35 36 37 38 39 31 32 33
+                                34 35 36 37 38 39 31 32 33 34 35 00 CC 00 06 08
+                                07 D0 20 03 E8 00 CE 00 0C 0B 49 6E 66 6F 72 6D
+                                61 74 69 6F 6E 01 17 00 08 00 33 32 31 34 35 36
+                                30 01 13 00 01 22 00 CD 00 1B 00 00 D1 00 16 1A
+                                11 50 00 08 21 09 E0 41 41 42 42 43 43 44 44 45
+                                45 5A 5A 59 58
+                            </RICindicationMessage>
+                        </value>
+                    </RICindication-IEs>
+                </protocolIEs>
+            </RICindication>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml
new file mode 100644
index 0000000..92bc727
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICindication_type2.xml
@@ -0,0 +1,74 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>205</procedureCode>
+        <criticality><ignore/></criticality>
+        <value>
+            <RICindication>
+                <protocolIEs>
+                    <RICindication-IEs>
+                        <id>60030</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICrequestID>
+                                <ricRequestorID>6</ricRequestorID>
+                                <ricRequestSequenceNumber>12</ricRequestSequenceNumber>
+                            </RICrequestID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60003</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RANfunctionID>10</RANfunctionID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60017</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICactionID>100</RICactionID>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60028</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationSN>100</RICindicationSN>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60029</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationType><report/></RICindicationType>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60026</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationHeader>10 74 68 65 10 68 65 6C 40</RICindicationHeader>
+                        </value>
+                    </RICindication-IEs>
+                    <RICindication-IEs>
+                        <id>60027</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICindicationMessage>
+                                00 1B 40 80 80 00 00 08 00 6F 00 02 00 0C 00 F8
+                                00 05 08 4D 86 D6 40 00 CB 00 20 31 32 33 34 35
+                                36 37 38 39 31 32 33 34 35 36 37 38 39 31 32 33
+                                34 35 36 37 38 39 31 32 33 34 35 00 CC 00 06 08
+                                07 D0 20 03 E8 00 CE 00 0C 0B 49 6E 66 6F 72 6D
+                                61 74 69 6F 6E 01 17 00 08 00 33 32 31 34 35 36
+                                30 01 13 00 01 23 00 CD 00 1B 00 00 D1 00 16 1A
+                                11 50 00 08 21 09 E0 41 41 42 42 43 43 44 44 45
+                                45 5A 5A 59 58
+                            </RICindicationMessage>
+                        </value>
+                    </RICindication-IEs>
+                </protocolIEs>
+            </RICindication>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml
new file mode 100644
index 0000000..ab3ea11
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest.xml
@@ -0,0 +1,50 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>201</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <RICsubscriptionRequest>
+                <protocolIEs>
+                    <RICsubscriptionRequest-IEs>
+                        <id>60030</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICrequestID>
+                                <ricRequestorID>1</ricRequestorID>
+                                <ricRequestSequenceNumber>200</ricRequestSequenceNumber>
+                            </RICrequestID>
+                        </value>
+                    </RICsubscriptionRequest-IEs>
+                    <RICsubscriptionRequest-IEs>
+                        <id>60003</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RANfunctionID>33</RANfunctionID>
+                        </value>
+                    </RICsubscriptionRequest-IEs>
+                    <RICsubscriptionRequest-IEs>
+                        <id>60033</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICsubscription>
+                                <ricEventTriggerDefinition>00 01 02 03 40 0b 16 02 00 23 40</ricEventTriggerDefinition>
+                                <ricAction-ToBeSetup-List>
+                                    <ProtocolIE-Single-Container>
+                                        <id>60011</id>
+                                        <criticality><ignore/></criticality>
+                                        <value>
+                                            <RICaction-ToBeSetup-Item>
+                                                <ricActionID>255</ricActionID>
+                                                <ricActionType><report/></ricActionType>
+                                            </RICaction-ToBeSetup-Item>
+                                        </value>
+                                    </ProtocolIE-Single-Container>
+                                </ricAction-ToBeSetup-List>
+                            </RICsubscription>
+                        </value>
+                    </RICsubscriptionRequest-IEs>
+                </protocolIEs>
+            </RICsubscriptionRequest>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml
new file mode 100644
index 0000000..524f7af
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionRequest_Ashwin.xml
@@ -0,0 +1,50 @@
+<E2AP-PDU>

+    <initiatingMessage>

+        <procedureCode>201</procedureCode>

+        <criticality><reject/></criticality>

+        <value>

+            <RICsubscriptionRequest>

+                <protocolIEs>

+                    <RICsubscriptionRequest-IEs>

+                        <id>60030</id>

+                        <criticality><reject/></criticality>

+                        <value>

+                            <RICrequestID>

+                                <ricRequestorID>2</ricRequestorID>

+                                <ricRequestSequenceNumber>1</ricRequestSequenceNumber>

+                            </RICrequestID>

+                        </value>

+                    </RICsubscriptionRequest-IEs>

+                    <RICsubscriptionRequest-IEs>

+                        <id>60003</id>

+                        <criticality><reject/></criticality>

+                        <value>

+                            <RANfunctionID>0</RANfunctionID>

+                        </value>

+                    </RICsubscriptionRequest-IEs>

+                    <RICsubscriptionRequest-IEs>

+                        <id>60033</id>

+                        <criticality><reject/></criticality>

+                        <value>

+                            <RICsubscription>

+                                <ricEventTriggerDefinition>10 54 65 73 10 54 65 73 40 1B 40</ricEventTriggerDefinition>

+                                <ricAction-ToBeSetup-List>

+                                    <ProtocolIE-Single-Container>

+                                        <id>60011</id>

+                                        <criticality><ignore/></criticality>

+                                        <value>

+                                            <RICaction-ToBeSetup-Item>

+                                                <ricActionID>4</ricActionID>

+                                                <ricActionType><report/></ricActionType>

+                                            </RICaction-ToBeSetup-Item>

+                                        </value>

+                                    </ProtocolIE-Single-Container>

+                                </ricAction-ToBeSetup-List>

+                            </RICsubscription>

+                        </value>

+                    </RICsubscriptionRequest-IEs>

+                </protocolIEs>

+            </RICsubscriptionRequest>

+        </value>

+    </initiatingMessage>

+</E2AP-PDU>

diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml
new file mode 100644
index 0000000..b7ea847
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_RICsubscriptionResponse.xml
@@ -0,0 +1,46 @@
+<E2AP-PDU>
+    <successfulOutcome>
+        <procedureCode>201</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <RICsubscriptionResponse>
+                <protocolIEs>
+                    <RICsubscriptionResponse-IEs>
+                        <id>60030</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICrequestID>
+                                <ricRequestorID>2</ricRequestorID>
+                                <ricRequestSequenceNumber>205</ricRequestSequenceNumber>
+                            </RICrequestID>
+                        </value>
+                    </RICsubscriptionResponse-IEs>
+                    <RICsubscriptionResponse-IEs>
+                        <id>60003</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RANfunctionID>0</RANfunctionID>
+                        </value>
+                    </RICsubscriptionResponse-IEs>
+                    <RICsubscriptionResponse-IEs>
+                        <id>60012</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <RICaction-Admitted-List>
+                                <ProtocolIE-Single-Container>
+                                    <id>60013</id>
+                                    <criticality><ignore/></criticality>
+                                    <value>
+                                        <RICaction-Admitted-Item>
+                                            <ricActionID>1</ricActionID>
+                                        </RICaction-Admitted-Item>
+                                    </value>
+                                </ProtocolIE-Single-Container>
+                            </RICaction-Admitted-List>
+                        </value>
+                    </RICsubscriptionResponse-IEs>
+                </protocolIEs>
+            </RICsubscriptionResponse>
+        </value>
+    </successfulOutcome>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml
new file mode 100644
index 0000000..53acf31
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupFailure.xml
@@ -0,0 +1,21 @@
+<E2AP-PDU>
+    <unsuccessfulOutcome>
+        <procedureCode>6</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <X2SetupFailure>
+                <protocolIEs>
+                    <X2SetupFailure-IEs>
+                        <id>5</id>
+                        <criticality><ignore/></criticality>
+                        <value>
+                            <Cause>
+                                <radioNetwork><ho-target-not-allowed/></radioNetwork>
+                            </Cause>
+                        </value>
+                    </X2SetupFailure-IEs>
+                </protocolIEs>
+            </X2SetupFailure>
+        </value>
+    </unsuccessfulOutcome>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml
new file mode 100644
index 0000000..9f0f286
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupRequest.xml
@@ -0,0 +1,57 @@
+<E2AP-PDU>
+    <initiatingMessage>
+        <procedureCode>6</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <X2SetupRequest>
+                <protocolIEs>
+                    <X2SetupRequest-IEs>
+                        <id>21</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <GlobalENB-ID>
+                                <pLMN-Identity>13 30 23</pLMN-Identity>
+                                <eNB-ID>
+                                    <macro-eNB-ID>
+                                        11111111111111111111
+                                    </macro-eNB-ID>
+                                </eNB-ID>
+                            </GlobalENB-ID>
+                        </value>
+                    </X2SetupRequest-IEs>
+                    <X2SetupRequest-IEs>
+                        <id>20</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <ServedCells>
+                                <SEQUENCE>
+                                    <servedCellInfo>
+                                        <pCI>503</pCI>
+                                        <cellId>
+                                            <pLMN-Identity>13 30 23</pLMN-Identity>
+                                            <eUTRANcellIdentifier>
+                                                1111111111111111111100000000
+                                            </eUTRANcellIdentifier>
+                                        </cellId>
+                                        <tAC>00 00</tAC>
+                                        <broadcastPLMNs>
+                                            <PLMN-Identity>13 30 23</PLMN-Identity>
+                                        </broadcastPLMNs>
+                                        <eUTRA-Mode-Info>
+                                            <fDD>
+                                                <uL-EARFCN>0</uL-EARFCN>
+                                                <dL-EARFCN>0</dL-EARFCN>
+                                                <uL-Transmission-Bandwidth><bw6/></uL-Transmission-Bandwidth>
+                                                <dL-Transmission-Bandwidth><bw15/></dL-Transmission-Bandwidth>
+                                            </fDD>
+                                        </eUTRA-Mode-Info>
+                                    </servedCellInfo>
+                                </SEQUENCE>
+                            </ServedCells>
+                        </value>
+                    </X2SetupRequest-IEs>
+                </protocolIEs>
+            </X2SetupRequest>
+        </value>
+    </initiatingMessage>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml
new file mode 100644
index 0000000..03682d9
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/E2AP_X2SetupResponse.xml
@@ -0,0 +1,69 @@
+<E2AP-PDU>
+    <successfulOutcome>
+        <procedureCode>6</procedureCode>
+        <criticality><reject/></criticality>
+        <value>
+            <X2SetupResponse>
+                <protocolIEs>
+                    <X2SetupResponse-IEs>
+                        <id>21</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <GlobalENB-ID>
+                                <pLMN-Identity>02 F8 39</pLMN-Identity>
+                                <eNB-ID>
+                                    <macro-eNB-ID>
+                                        00000000111000110000
+                                    </macro-eNB-ID>
+                                </eNB-ID>
+                            </GlobalENB-ID>
+                        </value>
+                    </X2SetupResponse-IEs>
+                    <X2SetupResponse-IEs>
+                        <id>20</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <ServedCells>
+                                <SEQUENCE>
+                                    <servedCellInfo>
+                                        <pCI>0</pCI>
+                                        <cellId>
+                                            <pLMN-Identity>02 F8 39</pLMN-Identity>
+                                            <eUTRANcellIdentifier>
+                                                0000000011100011000000000000
+                                            </eUTRANcellIdentifier>
+                                        </cellId>
+                                        <tAC>00 01</tAC>
+                                        <broadcastPLMNs>
+                                            <PLMN-Identity>02 F8 39</PLMN-Identity>
+                                        </broadcastPLMNs>
+                                        <eUTRA-Mode-Info>
+                                            <fDD>
+                                                <uL-EARFCN>21400</uL-EARFCN>
+                                                <dL-EARFCN>3400</dL-EARFCN>
+                                                <uL-Transmission-Bandwidth><bw50/></uL-Transmission-Bandwidth>
+                                                <dL-Transmission-Bandwidth><bw50/></dL-Transmission-Bandwidth>
+                                            </fDD>
+                                        </eUTRA-Mode-Info>
+                                    </servedCellInfo>
+                                </SEQUENCE>
+                            </ServedCells>
+                        </value>
+                    </X2SetupResponse-IEs>
+                    <X2SetupResponse-IEs>
+                        <id>24</id>
+                        <criticality><reject/></criticality>
+                        <value>
+                            <GUGroupIDList>
+                                <GU-Group-ID>
+                                    <pLMN-Identity>02 F8 39</pLMN-Identity>
+                                    <mME-Group-ID>00 00</mME-Group-ID>
+                                </GU-Group-ID>
+                            </GUGroupIDList>
+                        </value>
+                    </X2SetupResponse-IEs>
+                </protocolIEs>
+            </X2SetupResponse>
+        </value>
+    </successfulOutcome>
+</E2AP-PDU>
diff --git a/simulators/e2sim/src/E2AP/XML/reference_constants.txt b/simulators/e2sim/src/E2AP/XML/reference_constants.txt
new file mode 100644
index 0000000..b9a3b54
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/XML/reference_constants.txt
@@ -0,0 +1,16 @@
+/* Dependencies */
+typedef enum Criticality {
+	Criticality_reject	= 0,
+	Criticality_ignore	= 1,
+	Criticality_notify	= 2
+} e_Criticality;
+
+
+-- Event Trigger Definition OCTET STRING contents
+E2SM-gNB-X2-eventTriggerDefinition ::= SEQUENCE{
+	interface-ID				Interface-ID,
+	interfaceDirection			InterfaceDirection,
+	interfaceMessageType		InterfaceMessageType,
+	interfaceProtocolIE-List	SEQUENCE (SIZE(1..maxofInterfaceProtocolIE)) OF InterfaceProtocolIE-Item OPTIONAL,
+	...
+}
diff --git a/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c
new file mode 100644
index 0000000..5205b16
--- /dev/null
+++ b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.c
@@ -0,0 +1,143 @@
+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+#include "e2ap_asn1c_codec.h"
+
+void e2ap_asn1c_print_pdu(const E2AP_PDU_t* pdu)
+{
+  xer_fprint(stdout, &asn_DEF_E2AP_PDU, (void *)pdu);
+  printf("\n");
+}
+
+void asn1c_xer_print(asn_TYPE_descriptor_t *typeDescriptor, void *data)
+{
+  xer_fprint(stdout, typeDescriptor, (void *)data);
+  printf("\n");
+}
+
+
+E2AP_PDU_t* e2ap_xml_to_pdu(char const* xml_message)
+{
+  // E2AP_PDU_t *pdu = new E2AP_PDU_t();
+  E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
+
+  assert(pdu != 0);
+
+  uint8_t         buf[MAX_XML_BUFFER];
+  asn_dec_rval_t  rval;
+  size_t          size;
+  FILE            *f;
+
+  char XML_path[300];
+  char *work_dir = getenv(WORKDIR_ENV);
+
+  strcpy(XML_path, work_dir);
+  strcat(XML_path, E2AP_XML_DIR);
+  strcat(XML_path, xml_message);
+
+  LOG_D("Generate E2AP PDU from XML file: %s\n", XML_path);
+  memset(buf, 0, sizeof(buf));
+
+  f = fopen(XML_path, "r");
+  if(!f){
+     LOG_E("Unable to open %s. Make sure you have set the Environment Variable E2SIM_DIR, see README", XML_path)
+  }
+
+  assert(f);
+
+  size = fread(buf, 1, sizeof(buf), f);
+  if(size == 0 || size == sizeof(buf))
+  {
+    LOG_E("Input too long: %s", XML_path);
+    exit(1);
+  }
+
+  fclose(f);
+
+  rval = xer_decode(0, &asn_DEF_E2AP_PDU, (void **)&pdu, buf, size);
+
+  assert(rval.code == RC_OK);
+
+  return pdu;
+}
+
+int e2ap_asn1c_encode_pdu(E2AP_PDU_t* pdu, unsigned char **buffer)
+{
+  int len;
+
+  *buffer = NULL;
+  assert(pdu != NULL);
+  assert(buffer != NULL);
+
+  len = aper_encode_to_new_buffer(&asn_DEF_E2AP_PDU, 0, pdu, (void **)buffer);
+
+  if (len < 0)  {
+    LOG_E("[E2AP ASN] Unable to aper encode");
+    exit(1);
+  }
+  else {
+    LOG_D("[E2AP ASN] Encoded succesfully, encoded size = %d", len);
+  }
+
+  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_E2AP_PDU, pdu);
+
+  return len;
+}
+
+void e2ap_asn1c_decode_pdu(E2AP_PDU_t* pdu, unsigned char *buffer, int len)
+{
+  asn_dec_rval_t dec_ret;
+
+  assert(buffer != NULL);
+
+  dec_ret = aper_decode(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, len, 0, 0);
+
+  if (dec_ret.code != RC_OK) {
+    LOG_E("[E2AP ASN] Failed to decode pdu");
+    exit(1);
+  }
+  else {
+    LOG_D("[E2AP ASN] Decoded succesfully");
+  }
+}
+
+int e2ap_asn1c_get_procedureCode(E2AP_PDU_t* pdu)
+{
+  int procedureCode = -1;
+
+  switch(pdu->present)
+  {
+    case E2AP_PDU_PR_initiatingMessage:
+      procedureCode = pdu->choice.initiatingMessage->procedureCode;
+      break;
+
+    case E2AP_PDU_PR_successfulOutcome:
+      procedureCode = pdu->choice.successfulOutcome->procedureCode;
+      break;
+
+    case E2AP_PDU_PR_unsuccessfulOutcome:
+      procedureCode = pdu->choice.unsuccessfulOutcome->procedureCode;
+      break;
+
+    default:
+      LOG_E("[E2AP] Error: Unknown index %d in E2AP PDU", (int)pdu->present);
+      break;
+  }
+
+  return procedureCode;
+}
diff --git a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h
similarity index 68%
copy from simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp
copy to simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h
index 6fd6170..1362638 100644
--- a/simulators/e2sim/src/E2AP/e2ap_asn_codec.hpp
+++ b/simulators/e2sim/src/E2AP/e2ap_asn1c_codec.h
@@ -1,34 +1,44 @@
-/*****************************************************************************

-#                                                                            *

-# Copyright 2019 AT&T Intellectual Property                                  *

-# Copyright 2019 Nokia                                                       *

-#                                                                            *

-# Licensed under the Apache License, Version 2.0 (the "License");            *

-# you may not use this file except in compliance with the License.           *

-# You may obtain a copy of the License at                                    *

-#                                                                            *

-#      http://www.apache.org/licenses/LICENSE-2.0                            *

-#                                                                            *

-# Unless required by applicable law or agreed to in writing, software        *

-# distributed under the License is distributed on an "AS IS" BASIS,          *

-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *

-# See the License for the specific language governing permissions and        *

-# limitations under the License.                                             *

-#                                                                            *

-******************************************************************************/

-#ifndef E2AP_ASN_CODEC_HPP

-#define E2AP_ASN_CODEC_HPP

-

-#include "e2sim_defs.h"

-#include "asn_e2ap.hpp"

-

-#define ERROR_MESSAGE_BUFFER 1024

-#define PDU_PRINT_BUFFER     4096

-

-void e2ap_encode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int buf_size, int &encoded_size);

-

-void e2ap_decode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int &encoded_size);

-

-void e2ap_print_pdu(e2ap_pdu_t* pdu);

-

-#endif

+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+#ifndef E2AP_ASN1C_CODEC_H
+#define E2AP_ASN1C_CODEC_H
+
+#include "e2sim_defs.h"
+#include "E2AP-PDU.h"
+#include "InitiatingMessage.h"
+#include "SuccessfulOutcome.h"
+#include "UnsuccessfulOutcome.h"
+
+#define ASN1C_PDU_PRINT_BUFFER     4096
+#define MAX_XML_BUFFER             10000
+#define E2AP_XML_DIR               "/src/E2AP/XML/"
+
+void e2ap_asn1c_print_pdu(const E2AP_PDU_t* pdu);
+
+void asn1c_xer_print(asn_TYPE_descriptor_t *typeDescriptor, void *data);
+
+E2AP_PDU_t* e2ap_xml_to_pdu(char const* xml_message);
+
+int e2ap_asn1c_encode_pdu(E2AP_PDU_t* pdu, unsigned char **buffer);
+
+void e2ap_asn1c_decode_pdu(E2AP_PDU_t* pdu, unsigned char *buffer, int len);
+
+int e2ap_asn1c_get_procedureCode(E2AP_PDU_t* pdu);
+
+#endif
diff --git a/simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp b/simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp
deleted file mode 100644
index a1a6bee..0000000
--- a/simulators/e2sim/src/E2AP/e2ap_asn_codec.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*****************************************************************************

-#                                                                            *

-# Copyright 2019 AT&T Intellectual Property                                  *

-# Copyright 2019 Nokia                                                       *

-#                                                                            *

-# Licensed under the Apache License, Version 2.0 (the "License");            *

-# you may not use this file except in compliance with the License.           *

-# You may obtain a copy of the License at                                    *

-#                                                                            *

-#      http://www.apache.org/licenses/LICENSE-2.0                            *

-#                                                                            *

-# Unless required by applicable law or agreed to in writing, software        *

-# distributed under the License is distributed on an "AS IS" BASIS,          *

-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *

-# See the License for the specific language governing permissions and        *

-# limitations under the License.                                             *

-#                                                                            *

-******************************************************************************/

-

-#include "e2ap_asn_codec.hpp"

-

-void e2ap_encode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int buf_size, int &encoded_size)

-{

-  char err_buf[ERROR_MESSAGE_BUFFER];

-

-  encoded_size = e2ap_asn_per_encode(pdu, buf, buf_size, err_buf, sizeof(err_buf));

-

-  if(encoded_size != -1)

-  {

-    LOG_D("[E2AP] ASN Encode successful, encoded_size = %d", encoded_size);

-  }

-  else

-  {

-    LOG_E("[E2AP] Encode error: %s", err_buf);

-    exit(1);

-  }

-

-}

-

-void e2ap_decode_pdu(e2ap_pdu_t* pdu, unsigned char* buf, int &encoded_size)

-{

-  char err_buf[ERROR_MESSAGE_BUFFER];

-

-  int rc = e2ap_asn_per_decode(pdu, buf, encoded_size, err_buf, sizeof(err_buf));

-  if(rc == -1) {

-    LOG_E("[E2AP] Decode error: %s", err_buf);

-  } else {

-    LOG_D("[E2AP] ASN decode successful");

-  }

-}

-

-void e2ap_print_pdu(e2ap_pdu_t* pdu)

-{

-  char pdu_str[PDU_PRINT_BUFFER];

-

-  e2ap_asn_print(pdu, pdu_str, sizeof(pdu_str));

-

-  LOG_D("[E2AP] %s", pdu_str);

-}

diff --git a/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp b/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp
index d511949..d8f5e6b 100644
--- a/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp
+++ b/simulators/e2sim/src/E2AP/e2ap_message_handler.cpp
@@ -17,37 +17,38 @@
 #                                                                            *

 ******************************************************************************/

 #include "e2ap_message_handler.hpp"

+#include <unistd.h>

 

 void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data)

 {

   //decode the data into E2AP-PDU

-  e2ap_pdu_t* pdu = new_e2ap_pdu();

+  E2AP_PDU_t* pdu = new E2AP_PDU_t();

 

-  e2ap_decode_pdu(pdu, data.buffer, data.len);

+  e2ap_asn1c_decode_pdu(pdu, data.buffer, data.len);

 

-  e2ap_print_pdu(pdu);

+  e2ap_asn1c_print_pdu(pdu);

 

-  int index = e2ap_get_index(pdu);

-  int procedureCode = e2ap_get_procedureCode(pdu);

+  int procedureCode = e2ap_asn1c_get_procedureCode(pdu);

+  int index = (int)pdu->present;

 

-  LOG_I("[E2AP] Unpacked E2AP-PDU: index = %d, procedureCode = %d\n", index, procedureCode);

+  LOG_D("[E2AP] Unpacked E2AP-PDU: index = %d, procedureCode = %d\n",

+                            index, procedureCode);

 

   switch(procedureCode)

   {

-    case 6: //X2Setup

+    case ProcedureCode_id_x2Setup: //X2Setup = 6

       switch(index)

       {

-        case 1: //initiatingMessage

-          LOG_D("[E2AP] Received X2-SETUP-REQUEST");

+        case E2AP_PDU_PR_initiatingMessage: //initiatingMessage

+          LOG_I("[E2AP] Received X2-SETUP-REQUEST");

           e2ap_handle_X2SetupRequest(pdu, socket_fd);

           break;

 

-        case 2: //successfulOutcome

-          LOG_D("[E2AP] Received X2-SETUP-RESPONSE");

-          //e2ap_handle_X2SetupResponse(pdu, socket_fd);

+        case E2AP_PDU_PR_successfulOutcome: //successfulOutcome

+          LOG_I("[E2AP] Received X2-SETUP-RESPONSE");

           break;

 

-        case 3:

+        case E2AP_PDU_PR_unsuccessfulOutcome:

           break;

 

         default:

@@ -56,21 +57,22 @@
       }

       break;

 

-    case 36: //ENDCX2Setup

+    case ProcedureCode_id_endcX2Setup: //ENDCX2Setup = 36

       switch(index)

       {

-        case 1: //initiatingMessage

-          LOG_D("[E2AP] Received ENDC-X2-SETUP-REQUEST");

+        case E2AP_PDU_PR_initiatingMessage: //initiatingMessage

+          LOG_I("[E2AP] Received ENDC-X2-SETUP-REQUEST");

           e2ap_handle_ENDCX2SetupRequest(pdu, socket_fd);

           break;

 

-        case 2: //successfulOutcome

-          LOG_D("[E2AP] Received ENDC-X2-SETUP-RESPONSE");

-          //x2ap_handle_X2SetupResponse(pdu, socket_fd);

+        case E2AP_PDU_PR_successfulOutcome: //successfulOutcome

+          LOG_I("[E2AP] Received ENDC-X2-SETUP-RESPONSE");

+          //no handler yet

           break;

 

-        case 3:

-          LOG_D("[E2AP] Received ENDC-X2-SETUP-FAILURE");

+        case E2AP_PDU_PR_unsuccessfulOutcome:

+          LOG_I("[E2AP] Received ENDC-X2-SETUP-FAILURE");

+          //no handler yet

           break;

 

         default:

@@ -79,25 +81,60 @@
       }

       break;

 

-    case 201: //RIC SUBSCRIPTION

+    case ProcedureCode_id_reset: //reset = 7

       switch(index)

       {

-        case 1: //initiatingMessage

-          LOG_D("[E2AP] Received RIC-SUBSCRIPTION-REQUEST");

-          e2ap_handle_RICSubscriptionRequest(pdu, socket_fd);

+        case E2AP_PDU_PR_initiatingMessage:

+          LOG_I("[E2AP] Received RESET-REQUEST");

           break;

 

-        case 2:

-          LOG_D("[E2AP] Received RIC-SUBSCRIPTION-RESPONSE");

+        case E2AP_PDU_PR_successfulOutcome:

           break;

 

-        case 3:

-          LOG_D("[E2AP] Received RIC-SUBSCRIPTION-FAILURE");

+        case E2AP_PDU_PR_unsuccessfulOutcome:

           break;

 

         default:

-        LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index);

-        break;

+          LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index);

+          break;

+      }

+      break;

+

+    case ProcedureCode_id_ricSubscription: //RIC SUBSCRIPTION = 201

+      switch(index)

+      {

+        case E2AP_PDU_PR_initiatingMessage: //initiatingMessage

+          LOG_I("[E2AP] Received RIC-SUBSCRIPTION-REQUEST");

+          //e2ap_handle_RICSubscriptionRequest(pdu, socket_fd);

+          e2ap_handle_RICSubscriptionRequest_securityDemo(pdu, socket_fd);

+          break;

+

+        case E2AP_PDU_PR_successfulOutcome:

+          LOG_I("[E2AP] Received RIC-SUBSCRIPTION-RESPONSE");

+          break;

+

+        case E2AP_PDU_PR_unsuccessfulOutcome:

+          LOG_I("[E2AP] Received RIC-SUBSCRIPTION-FAILURE");

+          break;

+

+        default:

+          LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU", index);

+          break;

+      }

+      break;

+

+    case ProcedureCode_id_ricIndication: // 205

+      switch(index)

+      {

+        case E2AP_PDU_PR_initiatingMessage: //initiatingMessage

+          LOG_I("[E2AP] Received RIC-INDICATION");

+          // e2ap_handle_RICSubscriptionRequest(pdu, socket_fd);

+          break;

+

+        default:

+          LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index,

+                                    (int)ProcedureCode_id_ricIndication);

+          break;

       }

       break;

 

@@ -107,55 +144,49 @@
   }

 }

 

-void e2ap_handle_X2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd)

+/*

+Simply send back X2SetupResponse

+Todo: add more handling options (failure, duplicated request, etc.)

+*/

+void e2ap_handle_X2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd)

 {

-  /*

-  Simply send back X2SetupResponse

-  Todo: add more handling options (failure, duplicated request, etc.)

-  */

+  E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_X2SetupResponse.xml");

 

-  e2ap_pdu_t* res_pdu = new_e2ap_pdu();

-  eNB_config cfg;

+  LOG_D("[E2AP] Created X2-SETUP-RESPONSE");

 

-  e2ap_create_X2SetupResponse(res_pdu, cfg);

-  LOG_D("[E2AP] Created X2-SETUP-RESPONSE")

+  e2ap_asn1c_print_pdu(res_pdu);

 

-  e2ap_print_pdu(res_pdu);

+  uint8_t       *buf;

+  sctp_buffer_t data;

 

-  //encode response pdu into buffer

-  sctp_buffer_t res_data;

-  e2ap_encode_pdu(res_pdu, res_data.buffer, sizeof(res_data.buffer), res_data.len);

+  data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf);

+  memcpy(data.buffer, buf, data.len);

 

   //send response data over sctp

-  if(sctp_send_data(socket_fd, res_data) > 0) {

+  if(sctp_send_data(socket_fd, data) > 0) {

     LOG_I("[SCTP] Sent X2-SETUP-RESPONSE");

   } else {

     LOG_E("[SCTP] Unable to send X2-SETUP-RESPONSE to peer");

   }

 }

 

-void e2ap_handle_X2SetupResponse(e2ap_pdu_t* pdu, int &socket_fd)

+/*

+Simply send back ENDCX2SetupResponse

+Todo: add more handling options (failure, duplicated request, etc.)

+*/

+void e2ap_handle_ENDCX2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd)

 {

-  ;

-}

+  E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupResponse.xml");

 

-void e2ap_handle_ENDCX2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd)

-{

-  /*

-  Simply send back ENDCX2SetupResponse

-  Todo: add more handling options (failure, duplicated request, etc.)

-  */

-

-  e2ap_pdu_t* res_pdu = new_e2ap_pdu();

-  gNB_config gnb_cfg;

-

-  e2ap_create_ENDCX2SetupResponse(res_pdu, gnb_cfg);

   LOG_D("[E2AP] Created ENDC-X2-SETUP-RESPONSE");

 

-  e2ap_print_pdu(res_pdu);

+  e2ap_asn1c_print_pdu(res_pdu);

 

+  uint8_t       *buf;

   sctp_buffer_t data;

-  e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len);

+

+  data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf);

+  memcpy(data.buffer, buf, data.len);

 

   //send response data over sctp

   if(sctp_send_data(socket_fd, data) > 0) {

@@ -165,76 +196,159 @@
   }

 }

 

-void e2ap_handle_RICSubscriptionRequest(e2ap_pdu_t* pdu, int &socket_fd)

+/*

+Simply send back hard-coded RICSubscriptionResponse

+Todo: add more handling options (failure, duplicated request, etc.)

+*/

+void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd)

 {

-  RICsubscription_params_t params;

-  e2ap_parse_RICsubscriptionRequest(pdu, params);

+  E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml");

 

-  /* Example handling logic

-  - Accept if request id is even-numbered -> send back response

-    in this case, accept every other actions

+  LOG_D("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE");

 

-  - Reject if request id is odd-numbered -> send back failure

-  */

+  e2ap_asn1c_print_pdu(res_pdu);

 

-  e2ap_pdu_t* res_pdu = new_e2ap_pdu();

-  bool is_failure = false;

-

-  if(params.request_id % 2 == 0)

-  {

-    for(size_t i = 0; i < params.actionList.size(); i++)

-    {

-      if(i%2 == 0){

-        params.actionList[i].isAdmitted = true;

-      } else {

-        params.actionList[i].isAdmitted = false;

-        params.actionList[i].notAdmitted_cause = RICcause_radioNetwork;

-        params.actionList[i].notAdmitted_subCause = 5;

-      }

-    }

-

-    e2ap_create_RICsubscriptionResponse(res_pdu, params);

-    LOG_I("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE");

-  }

-  else

-  {

-    is_failure = true;

-

-    for(size_t i = 0; i < params.actionList.size(); i++)

-    {

-      params.actionList[i].isAdmitted = false;

-      params.actionList[i].notAdmitted_cause = RICcause_radioNetwork;

-      params.actionList[i].notAdmitted_subCause = 5;

-    }

-

-    e2ap_create_RICsubscriptionFailure(res_pdu, params);

-    LOG_I("[E2AP] Created RIC-SUBSCRIPTION-FAILURE");

-  }

-

-  e2ap_print_pdu(res_pdu);

-

-  //Encode into buffer

+  uint8_t       *buf;

   sctp_buffer_t data;

-  e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len);

+

+  data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf);

+  memcpy(data.buffer, buf, data.len);

 

   //send response data over sctp

-  if(sctp_send_data(socket_fd, data) > 0)

-  {

-    if(is_failure) {

-      LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-FAILURE");

-    }

-    else {

-      LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE");

-    }

+  if(sctp_send_data(socket_fd, data) > 0) {

+    LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE");

+  } else {

+    LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE to peer");

   }

-  else

-  {

-    if(is_failure) {

-      LOG_I("[SCTP] Unable to send RIC-SUBSCRIPTION-FAILURE");

-    }

-    else {

-      LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE");

-    }

+}

+

+void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socket_fd)

+{

+  E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml");

+

+  LOG_D("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE");

+

+  e2ap_asn1c_print_pdu(res_pdu);

+

+  uint8_t       *buf;

+  sctp_buffer_t data;

+

+  data.len = e2ap_asn1c_encode_pdu(res_pdu, &buf);

+  memcpy(data.buffer, buf, data.len);

+

+  //send response data over sctp

+  if(sctp_send_data(socket_fd, data) > 0) {

+    LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE");

+  } else {

+    LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE to peer");

   }

 

+  //Start sending RIC Indication

+  int count1 = 0, count2 = 0;

+

+  E2AP_PDU_t* indication_type1 = e2ap_xml_to_pdu("E2AP_RICindication_type1.xml");

+  E2AP_PDU_t* indication_type2 = e2ap_xml_to_pdu("E2AP_RICindication_type2.xml");

+

+  uint8_t *buf1, *buf2;

+  sctp_buffer_t data1, data2;

+  data1.len = e2ap_asn1c_encode_pdu(indication_type1, &buf1);

+  memcpy(data1.buffer, buf1, data1.len);

+

+  data2.len = e2ap_asn1c_encode_pdu(indication_type2, &buf2);

+  memcpy(data2.buffer, buf2, data2.len);

+

+  while(1){

+    sleep(1);

+    //type1

+    if(sctp_send_data(socket_fd, data1) > 0) {

+      count1++;

+      LOG_I("[SCTP] Sent RIC-INDICATION SgNBAdditionRequest Type 1, count1 = %d", count1);

+    } else {

+      LOG_E("[SCTP] Unable to send RIC-INDICATION to peer");

+    }

+

+    sleep(1);

+    //type2

+    if(sctp_send_data(socket_fd, data2) > 0) {

+      count2++;

+      LOG_I("[SCTP] Sent RIC-INDICATION SgNBAdditionRequest Type 2, count2 = %d", count2);

+    } else {

+      LOG_E("[SCTP] Unable to send RIC-INDICATION to peer");

+    }

+  } //end while

+

 }

+

+// void e2ap_handle_RICSubscriptionRequest_old(e2ap_pdu_t* pdu, int &socket_fd)

+// {

+//   RICsubscription_params_t params;

+//   e2ap_parse_RICsubscriptionRequest(pdu, params);

+//

+//   /* Example handling logic

+//   - Accept if request id is even-numbered -> send back response

+//     in this case, accept every other actions

+//

+//   - Reject if request id is odd-numbered -> send back failure

+//   */

+//

+//   e2ap_pdu_t* res_pdu = new_e2ap_pdu();

+//   bool is_failure = false;

+//

+//   if(params.request_id % 2 == 0)

+//   {

+//     for(size_t i = 0; i < params.actionList.size(); i++)

+//     {

+//       if(i%2 == 0){

+//         params.actionList[i].isAdmitted = true;

+//       } else {

+//         params.actionList[i].isAdmitted = false;

+//         params.actionList[i].notAdmitted_cause = RICcause_radioNetwork;

+//         params.actionList[i].notAdmitted_subCause = 5;

+//       }

+//     }

+//

+//     e2ap_create_RICsubscriptionResponse(res_pdu, params);

+//     LOG_I("[E2AP] Created RIC-SUBSCRIPTION-RESPONSE");

+//   }

+//   else

+//   {

+//     is_failure = true;

+//

+//     for(size_t i = 0; i < params.actionList.size(); i++)

+//     {

+//       params.actionList[i].isAdmitted = false;

+//       params.actionList[i].notAdmitted_cause = RICcause_radioNetwork;

+//       params.actionList[i].notAdmitted_subCause = 5;

+//     }

+//

+//     e2ap_create_RICsubscriptionFailure(res_pdu, params);

+//     LOG_I("[E2AP] Created RIC-SUBSCRIPTION-FAILURE");

+//   }

+//

+//   e2ap_print_pdu(res_pdu);

+//

+//   //Encode into buffer

+//   sctp_buffer_t data;

+//   e2ap_encode_pdu(res_pdu, data.buffer, sizeof(data.buffer), data.len);

+//

+//   //send response data over sctp

+//   if(sctp_send_data(socket_fd, data) > 0)

+//   {

+//     if(is_failure) {

+//       LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-FAILURE");

+//     }

+//     else {

+//       LOG_I("[SCTP] Sent RIC-SUBSCRIPTION-RESPONSE");

+//     }

+//   }

+//   else

+//   {

+//     if(is_failure) {

+//       LOG_I("[SCTP] Unable to send RIC-SUBSCRIPTION-FAILURE");

+//     }

+//     else {

+//       LOG_E("[SCTP] Unable to send RIC-SUBSCRIPTION-RESPONSE");

+//     }

+//   }

+//

+// }

diff --git a/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp b/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp
index 42bb80f..c7af948 100644
--- a/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp
+++ b/simulators/e2sim/src/E2AP/e2ap_message_handler.hpp
@@ -19,19 +19,23 @@
 #ifndef E2AP_MESSAGE_HANDLER_HPP

 #define E2AP_MESSAGE_HANDLER_HPP

 

-#include "e2sim_defs.h"

 #include "e2sim_sctp.hpp"

-#include "asn_e2ap.hpp"

-#include "e2ap_asn_codec.hpp"

+

+extern "C" {

+  #include "e2sim_defs.h"

+  #include "e2ap_asn1c_codec.h"

+}

 

 void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data);

 

-void e2ap_handle_X2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd);

+void e2ap_handle_X2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd);

 

-void e2ap_handle_X2SetupResponse(e2ap_pdu_t* pdu, int &socket_fd);

+void e2ap_handle_X2SetupResponse(E2AP_PDU_t* pdu, int &socket_fd);

 

-void e2ap_handle_ENDCX2SetupRequest(e2ap_pdu_t* pdu, int &socket_fd);

+void e2ap_handle_ENDCX2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd);

 

-void e2ap_handle_RICSubscriptionRequest(e2ap_pdu_t* pdu, int &socket_fd);

+void e2ap_handle_RICSubscriptionRequest(E2AP_PDU_t* pdu, int &socket_fd);

+

+void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socket_fd);

 

 #endif

diff --git a/simulators/e2sim/src/SCTP/e2sim_sctp.cpp b/simulators/e2sim/src/SCTP/e2sim_sctp.cpp
index 3d808c5..15892d4 100644
--- a/simulators/e2sim/src/SCTP/e2sim_sctp.cpp
+++ b/simulators/e2sim/src/SCTP/e2sim_sctp.cpp
@@ -29,6 +29,16 @@
 #include "e2sim_sctp.hpp"
 // #include "e2sim_defs.h"
 
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/sctp.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
 int sctp_start_server(const char *server_ip_str, const int server_port)
 {
   if(server_port < 1 || server_port > 65535) {
@@ -108,18 +118,14 @@
   {
     server4_addr.sin_family = AF_INET;
     server4_addr.sin_port   = htons(server_port);
-
     server_addr = (struct sockaddr*)&server4_addr;
-    af          = AF_INET;
     addr_len    = sizeof(server4_addr);
   }
   else if(inet_pton(AF_INET6, server_ip_str, &server6_addr.sin6_addr) == 1)
   {
     server6_addr.sin6_family = AF_INET6;
     server6_addr.sin6_port   = htons(server_port);
-
     server_addr = (struct sockaddr*)&server6_addr;
-    af          = AF_INET6;
     addr_len    = sizeof(server6_addr);
   }
   else {
@@ -127,25 +133,47 @@
     exit(1);
   }
 
-  if((client_fd = socket(af, SOCK_STREAM, IPPROTO_SCTP)) == -1)
+  if((client_fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) == -1)
   {
      perror("socket");
      exit(1);
   }
 
-  LOG_I("[SCTP] Connecting to server at %s:%d ...", server_ip_str, server_port);
+  //--------------------------------
+  //Bind before connect
+  auto optval = 1;
+  if( setsockopt(client_fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof optval) != 0 ){
+    perror("setsockopt port");
+    exit(1);
+  }
 
+  if( setsockopt(client_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval) != 0 ){
+    perror("setsockopt addr");
+    exit(1);
+  }
+
+  struct sockaddr_in6  client6_addr {};
+  client6_addr.sin6_family = AF_INET6;
+  client6_addr.sin6_port   = htons(RIC_SCTP_SRC_PORT);
+  client6_addr.sin6_addr   = in6addr_any;
+
+  LOG_I("[SCTP] Binding client socket to source port %d", RIC_SCTP_SRC_PORT);
+  if(bind(client_fd, (struct sockaddr*)&client6_addr, sizeof(client6_addr)) == -1) {
+    perror("bind");
+    exit(1);
+  }
+  // end binding ---------------------
+
+  LOG_I("[SCTP] Connecting to server at %s:%d ...", server_ip_str, server_port);
   if(connect(client_fd, server_addr, addr_len) == -1) {
     perror("connect");
     exit(1);
   }
-
   assert(client_fd != 0);
 
   LOG_I("[SCTP] Connection established");
 
   return client_fd;
-
 }
 
 int sctp_accept_connection(const char *server_ip_str, const int server_fd)
@@ -193,6 +221,18 @@
   return sent_len;
 }
 
+int sctp_send_data_X2AP(int &socket_fd, sctp_buffer_t &data)
+{
+  int sent_len = sctp_sendmsg(socket_fd, (void*)(&(data.buffer[0])), data.len,
+                  NULL, 0, (uint32_t) X2AP_PPID, 0, 0, 0, 0);
+
+  if(sent_len == -1) {
+    perror("[SCTP] sctp_send_data");
+    exit(1);
+  }
+
+}
+
 /*
 Receive data from SCTP socket
 Outcome of recv()
diff --git a/simulators/e2sim/src/SCTP/e2sim_sctp.hpp b/simulators/e2sim/src/SCTP/e2sim_sctp.hpp
index 636f4e7..b16fcf6 100644
--- a/simulators/e2sim/src/SCTP/e2sim_sctp.hpp
+++ b/simulators/e2sim/src/SCTP/e2sim_sctp.hpp
@@ -32,8 +32,8 @@
 
 int sctp_send_data(int &socket_fd, sctp_buffer_t &data);
 
+int sctp_send_data_X2AP(int &socket_fd, sctp_buffer_t &data);
+
 int sctp_receive_data(int &socket_fd, sctp_buffer_t &data);
 
-
-
 #endif
diff --git a/simulators/e2sim/src/e2sim.c b/simulators/e2sim/src/e2sim.c
deleted file mode 100644
index 2f49bea..0000000
--- a/simulators/e2sim/src/e2sim.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- *
- * Copyright 2019 AT&T Intellectual Property
- * Copyright 2019 Nokia
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <assert.h>
-#include <unistd.h>             //for close()
-#include <arpa/inet.h>  //for inet_ntop()
-
-#include "e2sim_defs.h"
-#include "e2sim_sctp.h"
-#include "x2ap_message_handler.h"
-
-//OSN 2019
-#include "Pendulum_asn_codec.h"
-#include "adruino_serial.h"
-
-//rmr
-#include <errno.h>
-#include <sys/epoll.h>
-#include <rmr/rmr.h>
-#include "rmr_wrapper.h"
-
-static void pendulum_control_E2_agent(int client_fd)
-{
- printf("--------------------------------------\n");
- printf("E2 AGENT - START PENDULUM CONTROL\n");
- printf("--------------------------------------\n");
-
- uint8_t   *buffer;
- uint32_t  len;
- clock_t   begin;
- double    rtt; //ms
-
- uint8_t recv_buf[MAX_SCTP_BUFFER];
- int     recv_len;
-
- double angle;
- double torque;
- long   sqn;
- int    count = 0;
-
- //serial
- int serial_fd;
- char serial_buffer[MAX_SERIAL_BUFFER];
- serial_fd = start_serial_inferface(DEFAULT_BAUDRATE, DEFAULT_SERIAL_PORT);
-
- int MSG_NUM = 10;
-
- // printf("Enter number of messages: ");
- // scanf("%d", &MSG_NUM);
- //
- // //fgets(serial_buffer, MAX_SERIAL_BUFFER, stdin);
- // serialport_write(serial_fd, serial_buffer);
-
- serialport_write(serial_fd, "hello arduino\n");
-
- // for(int i = 0; i < MSG_NUM; i++)
- while(1)
- {
-
-   printf("----------------\n");
-   count += 1;
-   buffer  = NULL;
-   len     = 0;
-
-   //1.Read from serial
-   serial_readline(serial_fd, serial_buffer, MAX_SERIAL_BUFFER);
-   if(serial_buffer[0] == '\n')
-   {
-     //printf("RECEIVED EOL\n");
-     continue;
-   }
-   //printf("[Adruino] %s", serial_buffer);
-
-   begin = clock();
-
-   //2. Encode pendulum angle to ASN1 message
-   len = pendulum_create_asn_msg(&buffer, 0, 0, 0, serial_buffer);
-
-   //3. Send ASN1 message to socket
-   if(sctp_send_to_socket(client_fd, buffer, (size_t)len) > 0){
-     printf("Sent ASN1 message to E2 Termination\n");
-   }
-
-   // 4. Receive response from E2 Termination
-   memset(recv_buf, 0, sizeof(recv_buf));
-   recv_len = 0;
-   recv_len = recv(client_fd, &recv_buf, sizeof(recv_buf), 0);
-   if(recv_len == -1)
-   {
-     perror("recv()");
-     return;
-   }
-
-   char *recv_str;
-   recv_str = pendulum_get_strval(recv_buf, recv_len);
-   printf("Received response message #%d from xApp: %s\n", count, recv_str);
-
-   // 5. TODO: Send response to serial
-   serial_writeline(serial_fd, recv_str);
-
-   //serialport_write(serial_fd, "hello\n");
-
-   begin = clock() - begin;
-   rtt = 1000*((double)begin)/CLOCKS_PER_SEC; // in ms
-   printf("E2Agent-RIC-E2Agent RTT = %f ms\n", rtt);
- }
-
-
- close(client_fd);
-}
-
-int main(int argc, char *argv[])
-{
- printf("E2 Simulator. Version %s\n", VERSION);
- // test_rmr(); return 0;
- // test_adruino_serial(); return 0;
-
- char* server_ip         = DEFAULT_SCTP_IP;
- int server_port         = X2AP_SCTP_PORT;
-
- int             server_fd;
- int             client_fd;
- struct sockaddr client_addr;
- socklen_t       client_addr_size;
-
- //read input
- if(argc == 3) //user provided IP and PORT
- {
-   server_ip = argv[1];
-   server_port = atoi(argv[2]);
-   if(server_port < 1 || server_port > 65535) {
-     printf("Invalid port number (%d). Valid values are between 1 and 65535.\n"            , server_port);
-     return -1;
-   }
- }
- else if(argc == 2) //user provided only IP
- {
-   server_ip = argv[1];
- }
- else if(argc == 1)
- {
-   server_ip = DEFAULT_SCTP_IP;
- }
- else
- {
-   printf("Unrecognized option.\n");
-   printf("Usage: %s [SERVER IP ADDRESS] [SERVER PORT]\n", argv[0]);
-   return -1;
- }
-
- server_fd = sctp_start_server(server_ip, server_port);
-
- printf("Waiting for connection...\n");
- client_fd = accept(server_fd, &client_addr, &client_addr_size);
- if(client_fd == -1){
-   perror("accept()");
-   close(client_fd);
-   return -1;
- }
-
- //Todo: retrieve client ip addr
- struct sockaddr_in* client_ipv4 = (struct sockaddr_in*)&client_addr;
- char client_ip_addr[INET_ADDRSTRLEN];
- inet_ntop(AF_INET, &(client_ipv4->sin_addr), client_ip_addr, INET_ADDRSTRLEN);
-
- printf("New client connected from %s\n", client_ip_addr);
-
- // while(1) //put while loop if want to receive from multiple clients
- // {
-   uint8_t recv_buf[MAX_SCTP_BUFFER];
-   int     recv_len = 0;
-
-   memset(recv_buf, 0, sizeof(recv_buf));
-
-   printf("------------------------\n");
-   recv_len = recv(client_fd, &recv_buf, sizeof(recv_buf), 0);
-   if(recv_len == -1)
-   {
-     perror("recv()");
-     return -1;
-   }
-   else if(recv_len == 0)
-   {
-     printf("\nConnection from %s closed by remote peer\n", client_ip_addr);
-     if(close(client_fd) == -1)
-     {
-       perror("close");
-     }
-     return -1;
-   }
-
-   //printf("Received a message of size %d\n", recv_len);
-
-   //TODO: check PPID here before calling x2ap handler
-
-   sctp_data_t response = {NULL, 0};
-   x2ap_eNB_handle_message(recv_buf, recv_len, &response);
-
-   //=======================================================================
-   //reply to client
-   assert(response.data != NULL);
-   if(sctp_send_to_socket(client_fd, response.data, (size_t)response.len) > 0){
-     printf("Sent X2 SETUP RESPONSE \n");
-   } else{
-     perror("send to socket");
-     return -1;
-   }
-
-   printf("X2 Setup Completed \n");
-
-   //=========================================================================
-   // Pendulum interaction
-   // Send pendulum state to E2 Termination and receive response
-   pendulum_control_E2_agent(client_fd);
- // } //end while
-
- close(client_fd);
-
- return 0;
-}
diff --git a/simulators/e2sim/test/Misc/CMakeLists.txt b/simulators/e2sim/test/Misc/CMakeLists.txt
new file mode 100644
index 0000000..bf6c51c
--- /dev/null
+++ b/simulators/e2sim/test/Misc/CMakeLists.txt
@@ -0,0 +1,86 @@
+#/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+#******************************************************************************/
+
+cmake_minimum_required(VERSION 3.5.1)
+set(CMAKE_CXX_COMPILER "/usr/bin/g++")
+set(CMAKE_CXX_STANDARD 14)
+
+add_definitions("-D ASN_DISABLE_OER_SUPPORT")
+
+project(e2sim)
+
+set (HOME_DIR $ENV{HOME})
+#set (E2SIM_ROOT ../../../)
+
+include_directories("src")
+include_directories("src/SCTP/")
+include_directories("src/E2AP")
+include_directories("src/E2AP/E2SM")
+include_directories("ASN1c")
+
+find_library( SCTP_LIBRARY sctp )  #needed for sctp_sendmsg
+
+#----------------------------------------------
+file(GLOB E2AGENT_SOURCES
+      "src/e2agent.cpp"
+      "src/e2sim_defs.cpp"
+      "src/SCTP/*.cpp"
+      "src/E2AP/*.c"
+      "src/E2AP/*.cpp"
+      "ASN1c/*.c"
+      )
+add_executable(e2agent ${E2AGENT_SOURCES})
+target_link_libraries( e2agent ${SCTP_LIBRARY} )
+
+#----------------------------------------------
+file(GLOB RICSIM_SOURCES
+      "src/ric_sim.cpp"
+      "src/e2sim_defs.cpp"
+      "src/SCTP/*.cpp"
+      "src/E2AP/*.c"
+      "src/E2AP/*.cpp"
+      "ASN1c/*.c"
+      )
+add_executable(ric_sim ${RICSIM_SOURCES})
+target_link_libraries( ric_sim ${SCTP_LIBRARY} )
+
+
+#----------------------------------------------
+file(GLOB X2TERM_SOURCES
+      "src/x2term.cpp"
+      "src/e2sim_defs.cpp"
+      "src/SCTP/*.cpp"
+      "src/E2AP/*.c"
+      "src/E2AP/*.cpp"
+      "ASN1c/*.c"
+      )
+add_executable(x2term ${X2TERM_SOURCES})
+target_link_libraries( x2term ${SCTP_LIBRARY} )
+
+
+#-----------------------------------------------
+file(GLOB TEST
+      "src/test_asn1c.cpp"
+      "src/e2sim_defs.cpp"
+#      "src/SCTP/*.cpp"
+      "ASN1c/*.c"
+      "src/E2AP/*.c"
+      "src/E2AP/E2SM/*.c"
+      )
+add_executable(test_asn1c ${TEST})
diff --git a/simulators/e2sim/test/Misc/test_asn1c.cpp b/simulators/e2sim/test/Misc/test_asn1c.cpp
new file mode 100644
index 0000000..d10273c
--- /dev/null
+++ b/simulators/e2sim/test/Misc/test_asn1c.cpp
@@ -0,0 +1,79 @@
+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+#include <string>
+#include <iostream>
+
+extern "C" {
+  #include "e2sim_defs.h"
+  #include "E2AP-PDU.h"
+  #include "e2ap_asn1c_codec.h"
+  #include "e2sm.h"
+
+}
+
+using namespace std;
+
+int main(int argc, char* argv[]){
+
+  LOG_I("Test ASN1c");
+
+  test_eventTriggerDefinition();
+  return 0;
+
+  E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupRequest.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupResponse.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_X2SetupFailure.xml");
+
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupResponse.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ENDCX2SetupFailure.xml");
+
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml");
+  // E2AP_PDU_t* pdu = e2ap_xml_to_pdu("E2AP_ErrorIndication.xml");
+
+  e2ap_asn1c_print_pdu(pdu);
+
+  /* Test encoding */
+  uint8_t       *buf;
+  sctp_buffer_t data;
+
+  data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
+  memcpy(data.buffer, buf, data.len);
+
+  /* Test decoding */
+  E2AP_PDU_t* pdu1 = new E2AP_PDU_t();
+
+  e2ap_asn1c_decode_pdu(pdu1, data.buffer, data.len);
+
+  e2ap_asn1c_print_pdu(pdu1);
+
+  int index = (int)pdu1->present;
+
+  int pCode = e2ap_asn1c_get_procedureCode(pdu1);
+
+  LOG_I("Index = %d, procedureCode = %d", index, pCode);
+
+
+  return 0;
+}
diff --git a/simulators/e2sim/src/ONS2019/Pendulum_asn_codec.c b/simulators/e2sim/test/Pendulum/Pendulum_asn_codec.c
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Pendulum_asn_codec.c
rename to simulators/e2sim/test/Pendulum/Pendulum_asn_codec.c
diff --git a/simulators/e2sim/src/ONS2019/Pendulum_asn_codec.h b/simulators/e2sim/test/Pendulum/Pendulum_asn_codec.h
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Pendulum_asn_codec.h
rename to simulators/e2sim/test/Pendulum/Pendulum_asn_codec.h
diff --git a/simulators/e2sim/src/ONS2019/Serial/adruino_serial.c b/simulators/e2sim/test/Pendulum/Serial/adruino_serial.c
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Serial/adruino_serial.c
rename to simulators/e2sim/test/Pendulum/Serial/adruino_serial.c
diff --git a/simulators/e2sim/src/ONS2019/Serial/adruino_serial.h b/simulators/e2sim/test/Pendulum/Serial/adruino_serial.h
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Serial/adruino_serial.h
rename to simulators/e2sim/test/Pendulum/Serial/adruino_serial.h
diff --git a/simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.c b/simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.c
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.c
rename to simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.c
diff --git a/simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.h b/simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.h
similarity index 100%
rename from simulators/e2sim/src/ONS2019/Serial/arduino-serial-lib.h
rename to simulators/e2sim/test/Pendulum/Serial/arduino-serial-lib.h
diff --git a/simulators/e2sim/src/ONS2019/demo_setup.txt b/simulators/e2sim/test/Pendulum/demo_setup.txt
similarity index 100%
rename from simulators/e2sim/src/ONS2019/demo_setup.txt
rename to simulators/e2sim/test/Pendulum/demo_setup.txt
diff --git a/simulators/e2sim/src/e2sim_closedloop.c b/simulators/e2sim/test/Pendulum/e2sim_closedloop.c
similarity index 100%
rename from simulators/e2sim/src/e2sim_closedloop.c
rename to simulators/e2sim/test/Pendulum/e2sim_closedloop.c
diff --git a/simulators/e2sim/src/e2sim_serial.c b/simulators/e2sim/test/Pendulum/e2sim_serial.c
similarity index 100%
rename from simulators/e2sim/src/e2sim_serial.c
rename to simulators/e2sim/test/Pendulum/e2sim_serial.c
diff --git a/simulators/e2sim/src/e2sim_test_client.c b/simulators/e2sim/test/Pendulum/e2sim_test_client.c
similarity index 100%
rename from simulators/e2sim/src/e2sim_test_client.c
rename to simulators/e2sim/test/Pendulum/e2sim_test_client.c
diff --git a/simulators/e2sim/src/e2termination_test.cpp b/simulators/e2sim/test/Pendulum/e2termination_test.cpp
similarity index 100%
rename from simulators/e2sim/src/e2termination_test.cpp
rename to simulators/e2sim/test/Pendulum/e2termination_test.cpp
diff --git a/simulators/e2sim/src/ONS2019/pendulum.asn1 b/simulators/e2sim/test/Pendulum/pendulum.asn1
similarity index 100%
rename from simulators/e2sim/src/ONS2019/pendulum.asn1
rename to simulators/e2sim/test/Pendulum/pendulum.asn1
diff --git a/simulators/e2sim/test/WLG/CMakeLists.txt b/simulators/e2sim/test/WLG/CMakeLists.txt
new file mode 100644
index 0000000..4faee6a
--- /dev/null
+++ b/simulators/e2sim/test/WLG/CMakeLists.txt
@@ -0,0 +1,59 @@
+#/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+#******************************************************************************/
+
+cmake_minimum_required(VERSION 3.5.1)
+set(CMAKE_CXX_COMPILER "/usr/bin/g++")
+set(CMAKE_CXX_STANDARD 14)
+
+add_definitions("-D ASN_DISABLE_OER_SUPPORT")
+
+set (E2SIM_ROOT ../../)
+
+include_directories("${E2SIM_ROOT}/src")
+include_directories("${E2SIM_ROOT}/src/DEF")
+include_directories("${E2SIM_ROOT}/src/SCTP/")
+include_directories("${E2SIM_ROOT}/src/E2AP")
+include_directories("${E2SIM_ROOT}/src/E2AP/E2SM")
+include_directories("${E2SIM_ROOT}/ASN1c")
+
+find_library( SCTP_STD_LIB sctp )  #needed for sctp_sendmsg
+
+#----------------------------------------------
+file(GLOB WLG_SOURCES
+      "${E2SIM_ROOT}/test/WLG/ric_wlg.cpp"
+      "${E2SIM_ROOT}/src/DEF/*.cpp"
+      "${E2SIM_ROOT}/src/SCTP/*.cpp"
+      "${E2SIM_ROOT}/src/E2AP/*.c"
+      "${E2SIM_ROOT}/src/E2AP/*.cpp"
+      "${E2SIM_ROOT}/ASN1c/*.c"
+      )
+add_executable(ric_wlg ${WLG_SOURCES})
+target_link_libraries( ric_wlg  ${SCTP_STD_LIB} )
+
+#----------------------------------------------
+file(GLOB RICPERF_SOURCES
+      "${E2SIM_ROOT}/test/WLG/ric_perf.cpp"
+      "${E2SIM_ROOT}/src/DEF/*.cpp"
+      "${E2SIM_ROOT}/src/SCTP/*.cpp"
+      "${E2SIM_ROOT}/src/E2AP/*.c"
+      "${E2SIM_ROOT}/src/E2AP/*.cpp"
+      "${E2SIM_ROOT}/ASN1c/*.c"
+      )
+add_executable(ric_perf ${RICPERF_SOURCES})
+target_link_libraries( ric_perf ${SCTP_STD_LIB} )
diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/test/WLG/build_wlg.sh
similarity index 94%
rename from simulators/e2sim/build_docker
rename to simulators/e2sim/test/WLG/build_wlg.sh
index b04e565..2f81b56 100755
--- a/simulators/e2sim/build_docker
+++ b/simulators/e2sim/test/WLG/build_wlg.sh
@@ -19,4 +19,9 @@
 #******************************************************************************/
 
 set -e
-sudo docker build -f docker/Dockerfile -t e2agent .
+
+mkdir -p build
+cd build
+rm -rf CMakeCache.txt
+cmake ..
+make -j`nproc`
diff --git a/simulators/e2sim/test/WLG/ric_perf.cpp b/simulators/e2sim/test/WLG/ric_perf.cpp
new file mode 100644
index 0000000..ae140f8
--- /dev/null
+++ b/simulators/e2sim/test/WLG/ric_perf.cpp
@@ -0,0 +1,287 @@
+/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+******************************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "e2sim_sctp.hpp"
+#include "e2ap_message_handler.hpp"
+
+extern "C" {
+  #include "e2sim_defs.h"
+  #include "E2AP-PDU.h"
+  #include "e2ap_asn1c_codec.h"
+
+  #include "ProtocolIE-Field.h"
+}
+
+using namespace std;
+
+void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
+{
+  uint8_t       *buf;
+  sctp_buffer_t data;
+
+  data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
+  memcpy(data.buffer, buf, data.len);
+
+  sctp_send_data(client_fd, data);
+}
+
+void wait_for_sctp_data(int client_fd)
+{
+  sctp_buffer_t recv_buf;
+  if(sctp_receive_data(client_fd, recv_buf) > 0)
+  {
+    LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
+    e2ap_handle_sctp_data(client_fd, recv_buf);
+  }
+}
+
+void set_seqnum(E2AP_PDU_t* pdu)
+{
+  InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
+  // xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage);
+
+  RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest;
+  xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request);
+
+  LOG_I("num of IEs = %d", request->protocolIEs.list.count);
+
+  RICsubscriptionRequest_IEs_t *ie;
+
+  ie = request->protocolIEs.list.array[2];
+
+  xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie);
+
+  // e2ap_asn1c_print_pdu(pdu);
+}
+
+int subresponse_get_sequenceNum(E2AP_PDU_t* pdu)
+{
+  SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome;
+
+  RICrequestID_t *requestid;
+
+  int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count;
+
+  for(int edx = 0; edx < num_IEs; edx++)
+  {
+    RICsubscriptionResponse_IEs_t *memb_ptr =
+      responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx];
+
+    switch(memb_ptr->id)
+    {
+      case (ProtocolIE_ID_id_RICrequestID):
+        requestid = &memb_ptr->value.choice.RICrequestID;
+        // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
+        return requestid->ricRequestSequenceNumber;
+        break;
+    }
+  }
+}
+
+void subrequest_set_sequenceNum(E2AP_PDU_t* pdu, int seq)
+{
+  InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
+
+  RICrequestID_t *requestid;
+
+  int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count;
+
+  for(int edx = 0; edx < num_IEs; edx++)
+  {
+    RICsubscriptionRequest_IEs_t *memb_ptr =
+      initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx];
+
+    switch(memb_ptr->id)
+    {
+      case (ProtocolIE_ID_id_RICrequestID):
+        requestid = &memb_ptr->value.choice.RICrequestID;
+        requestid->ricRequestSequenceNumber = seq;
+        break;
+    }
+  }
+
+}
+
+void subscription_response_get_field(E2AP_PDU_t* pdu)
+{
+  SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome;
+
+  RICrequestID_t *requestid;
+  RANfunctionID_t * ranfunctionid;
+  RICsubscription_t * ricsubscription;
+
+  int requestID_val, sequenceNum;
+
+  int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count;
+
+  LOG_I("num of IEs = %d", num_IEs);
+
+  for(int edx = 0; edx < num_IEs; edx++)
+  {
+    RICsubscriptionResponse_IEs_t *memb_ptr =
+      responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx];
+
+    switch(memb_ptr->id)
+    {
+      case (ProtocolIE_ID_id_RICrequestID):
+      	requestid = &memb_ptr->value.choice.RICrequestID;
+        xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
+        requestID_val = requestid->ricRequestorID;
+        sequenceNum = requestid->ricRequestSequenceNumber;
+        requestid->ricRequestSequenceNumber = 202;
+      	break;
+
+      case (ProtocolIE_ID_id_RANfunctionID):
+        ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
+        xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid);
+        break;
+
+      // case (ProtocolIE_ID_id_RICsubscription):
+      //   ricsubscription = &memb_ptr->value.choice.RICsubscription;
+      //   xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription);
+      //   break;
+    }
+  }
+
+  LOG_I("Request ID = %d, seq = %d", requestID_val, sequenceNum);
+}
+
+void subscription_request_get_field(E2AP_PDU_t* pdu)
+{
+  InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
+
+  RICrequestID_t *requestid;
+  RANfunctionID_t * ranfunctionid;
+  RICsubscription_t * ricsubscription;
+
+  int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count;
+
+  LOG_I("num of IEs = %d", num_IEs);
+
+  for(int edx = 0; edx < num_IEs; edx++)
+  {
+    RICsubscriptionRequest_IEs_t *memb_ptr =
+      initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx];
+
+    switch(memb_ptr->id)
+    {
+      case (ProtocolIE_ID_id_RICrequestID):
+      	requestid = &memb_ptr->value.choice.RICrequestID;
+        xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
+      	break;
+
+      case (ProtocolIE_ID_id_RANfunctionID):
+        ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
+        xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid);
+        break;
+
+      case (ProtocolIE_ID_id_RICsubscription):
+        ricsubscription = &memb_ptr->value.choice.RICsubscription;
+        xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription);
+        break;
+    }
+  }
+}
+
+int main(int argc, char* argv[]){
+  LOG_I("Start RIC Simulator - Performance Test");
+
+  options_t ops = read_input_options(argc, argv);
+  int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
+
+  //1. Send ENDCX2Setup
+  E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml");
+  // e2ap_asn1c_print_pdu(pdu_setup);
+  encode_and_send_sctp_data(pdu_setup, client_fd);
+  LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
+
+  //2. Receive ENDCX2SetupResponse
+  wait_for_sctp_data(client_fd);
+
+  //3. Send RICSubscriptionRequest
+  E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml");
+  e2ap_asn1c_print_pdu(pdu_sub);
+  encode_and_send_sctp_data(pdu_sub, client_fd);
+  LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST");
+
+
+  //4. Receive RIC SUBSCRIPT RESPONSE
+  int count = 0;
+
+  while(1)
+  {
+    usleep(1000); //sleep for one ms
+
+    sctp_buffer_t recv_buf;
+
+    int res_seq;
+
+    if(sctp_receive_data(client_fd, recv_buf) > 0)
+    {
+      LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
+      // e2ap_handle_sctp_data(client_fd, recv_buf);
+
+      E2AP_PDU_t* res_pdu = new E2AP_PDU_t();
+
+      e2ap_asn1c_decode_pdu(res_pdu, recv_buf.buffer, recv_buf.len);
+
+      int procedureCode = e2ap_asn1c_get_procedureCode(res_pdu);
+      int index = (int)res_pdu->present;
+
+      if(index == E2AP_PDU_PR_successfulOutcome && \
+        procedureCode == ProcedureCode_id_ricSubscription)
+      {
+        res_seq =subresponse_get_sequenceNum(res_pdu);
+        count++;
+
+        LOG_I("Received RIC SUBSCRIPTION RESPONSE, seq = %d, totalCount = %d",\
+                res_seq, count);
+
+        //Put res_seq in new subscription request
+        E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
+        subrequest_set_sequenceNum(req_pdu, res_seq);
+        // e2ap_asn1c_print_pdu(req_pdu);
+
+        encode_and_send_sctp_data(req_pdu, client_fd);
+        LOG_I("Send new SUBSCRIPT REQUEST, seq = %d", res_seq);
+      }
+
+    }
+  }
+
+
+  // E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml");
+  //
+  // //Extract subscription response sequence number
+  // int res_seq = subresponse_get_sequenceNum(res_pdu);
+  // LOG_I("Subscription Response SeqNo = %d", res_seq);
+  //
+  // //Put responseSeq in new subscription request
+  // E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
+  //
+  // subrequest_set_sequenceNum(req_pdu, res_seq);
+
+  // e2ap_asn1c_print_pdu(req_pdu);
+
+  return 0;
+}
diff --git a/simulators/e2sim/src/e2agent.cpp b/simulators/e2sim/test/WLG/ric_wlg.cpp
similarity index 82%
copy from simulators/e2sim/src/e2agent.cpp
copy to simulators/e2sim/test/WLG/ric_wlg.cpp
index 07d52cd..309153d 100644
--- a/simulators/e2sim/src/e2agent.cpp
+++ b/simulators/e2sim/test/WLG/ric_wlg.cpp
@@ -19,38 +19,24 @@
 
 #include <stdio.h>
 #include <unistd.h>
-#include <string>
-#include <iostream>
+#include <assert.h>
 
-#include "e2sim_defs.h"
 #include "e2sim_sctp.hpp"
-#include "asn_e2ap.hpp"
 #include "e2ap_message_handler.hpp"
 
+extern "C" {
+  #include "e2sim_defs.h"
+  #include "E2AP-PDU.h"
+  #include "e2ap_asn1c_codec.h"
+
+  #include "ProtocolIE-Field.h"
+}
+
 using namespace std;
 
-void test(void)
-{
-  e2ap_pdu_t* pdu = new_e2ap_pdu();
-
-  gNB_config gnb_cfg;
-
-  e2ap_create_ENDCX2SetupResponse(pdu, gnb_cfg);
-
-  e2ap_print_pdu(pdu);
-
-  //Encode into buffer
-  sctp_buffer_t data;
-  e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
-
-}
 
 int main(int argc, char* argv[]){
-
-  LOG_I("E2 Agent (E2 Simulator) Version %s", VERSION);
-
-  // test();
-  // return 0;
+  LOG_I("Start RIC WLG");
 
   options_t ops = read_input_options(argc, argv);
 
@@ -60,6 +46,7 @@
   sctp_buffer_t recv_buf;
 
   LOG_I("[SCTP] Waiting for SCTP data");
+
   while(1) //constantly looking for data on SCTP interface
   {
     if(sctp_receive_data(client_fd, recv_buf) <= 0)
@@ -69,6 +56,6 @@
 
     e2ap_handle_sctp_data(client_fd, recv_buf);
   }
-
+    
   return 0;
 }
diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/test/X2/CMakeLists.txt
old mode 100755
new mode 100644
similarity index 60%
copy from simulators/e2sim/build_docker
copy to simulators/e2sim/test/X2/CMakeLists.txt
index b04e565..b257505
--- a/simulators/e2sim/build_docker
+++ b/simulators/e2sim/test/X2/CMakeLists.txt
@@ -1,4 +1,3 @@
-#!/bin/bash
 #/*****************************************************************************
 #                                                                            *
 # Copyright 2019 AT&T Intellectual Property                                  *
@@ -18,5 +17,33 @@
 #                                                                            *
 #******************************************************************************/
 
-set -e
-sudo docker build -f docker/Dockerfile -t e2agent .
+cmake_minimum_required(VERSION 3.5.1)
+set(CMAKE_CXX_COMPILER "/usr/bin/g++")
+set(CMAKE_CXX_STANDARD 14)
+
+add_definitions("-D ASN_DISABLE_OER_SUPPORT")
+
+project(x2term)
+
+set (E2SIM_ROOT ../../)
+
+include_directories("${E2SIM_ROOT}/src")
+include_directories("${E2SIM_ROOT}/src/DEF")
+include_directories("${E2SIM_ROOT}/src/SCTP/")
+include_directories("${E2SIM_ROOT}/src/E2AP")
+include_directories("${E2SIM_ROOT}/src/E2AP/E2SM")
+include_directories("${E2SIM_ROOT}/ASN1c")
+
+find_library( SCTP_STD_LIB sctp )  #needed for sctp_sendmsg
+
+#----------------------------------------------
+file(GLOB X2TERM_SOURCES
+      "${E2SIM_ROOT}/test/X2/x2term.cpp"
+      "${E2SIM_ROOT}/src/DEF/*.cpp"
+      "${E2SIM_ROOT}/src/SCTP/*.cpp"
+      "${E2SIM_ROOT}/src/E2AP/*.c"
+      "${E2SIM_ROOT}/src/E2AP/*.cpp"
+      "${E2SIM_ROOT}/ASN1c/*.c"
+      )
+add_executable(x2term ${X2TERM_SOURCES})
+target_link_libraries( x2term  ${SCTP_STD_LIB} )
diff --git a/simulators/e2sim/src/x2agent.cpp b/simulators/e2sim/test/X2/x2agent.cpp
similarity index 100%
rename from simulators/e2sim/src/x2agent.cpp
rename to simulators/e2sim/test/X2/x2agent.cpp
diff --git a/simulators/e2sim/src/e2agent.cpp b/simulators/e2sim/test/X2/x2term.cpp
similarity index 69%
copy from simulators/e2sim/src/e2agent.cpp
copy to simulators/e2sim/test/X2/x2term.cpp
index 07d52cd..9feccca 100644
--- a/simulators/e2sim/src/e2agent.cpp
+++ b/simulators/e2sim/test/X2/x2term.cpp
@@ -19,56 +19,54 @@
 
 #include <stdio.h>
 #include <unistd.h>
-#include <string>
-#include <iostream>
+#include <assert.h>
 
-#include "e2sim_defs.h"
 #include "e2sim_sctp.hpp"
-#include "asn_e2ap.hpp"
 #include "e2ap_message_handler.hpp"
 
+extern "C" {
+  #include "e2sim_defs.h"
+  #include "E2AP-PDU.h"
+  #include "e2ap_asn1c_codec.h"
+}
+
 using namespace std;
 
-void test(void)
+void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
 {
-  e2ap_pdu_t* pdu = new_e2ap_pdu();
-
-  gNB_config gnb_cfg;
-
-  e2ap_create_ENDCX2SetupResponse(pdu, gnb_cfg);
-
-  e2ap_print_pdu(pdu);
-
-  //Encode into buffer
+  uint8_t       *buf;
   sctp_buffer_t data;
-  e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
 
+  data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
+  memcpy(data.buffer, buf, data.len);
+
+  // sctp_send_data(client_fd, data);
+  sctp_send_data_X2AP(client_fd, data);
 }
 
-int main(int argc, char* argv[]){
-
-  LOG_I("E2 Agent (E2 Simulator) Version %s", VERSION);
-
-  // test();
-  // return 0;
-
-  options_t ops = read_input_options(argc, argv);
-
-  int server_fd = sctp_start_server(ops.server_ip, ops.server_port);
-  int client_fd = sctp_accept_connection(ops.server_ip, server_fd);
-
+void wait_for_sctp_data(int client_fd)
+{
   sctp_buffer_t recv_buf;
-
-  LOG_I("[SCTP] Waiting for SCTP data");
-  while(1) //constantly looking for data on SCTP interface
+  if(sctp_receive_data(client_fd, recv_buf) > 0)
   {
-    if(sctp_receive_data(client_fd, recv_buf) <= 0)
-      break;
-
     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
-
     e2ap_handle_sctp_data(client_fd, recv_buf);
   }
+}
 
-  return 0;
+
+int main(int argc, char* argv[]){
+  LOG_I("Start RIC Simulator");
+
+  options_t ops = read_input_options(argc, argv);
+  int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
+
+  //Send X2 Setup Request
+  E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_X2SetupRequest.xml");
+  e2ap_asn1c_print_pdu(pdu_setup);
+
+  encode_and_send_sctp_data(pdu_setup, client_fd);
+
+  //wait to receive X2SetupResponse
+  wait_for_sctp_data(client_fd);
 }
diff --git a/simulators/e2sim/src/x2termination_test.cpp b/simulators/e2sim/test/X2/x2termination_test.cpp
similarity index 98%
rename from simulators/e2sim/src/x2termination_test.cpp
rename to simulators/e2sim/test/X2/x2termination_test.cpp
index c6c9138..1953ce6 100644
--- a/simulators/e2sim/src/x2termination_test.cpp
+++ b/simulators/e2sim/test/X2/x2termination_test.cpp
@@ -111,8 +111,8 @@
 
   int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
 
-  // test_X2Setup(client_fd);
-  test_ENDCX2Setup(client_fd);
+  test_X2Setup(client_fd);
+  // test_ENDCX2Setup(client_fd);
 
 
   return 0;
diff --git a/simulators/e2sim/src/rmr_interface/README b/simulators/e2sim/test/rmr_interface/README
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/README
rename to simulators/e2sim/test/rmr_interface/README
diff --git a/simulators/e2sim/src/rmr_interface/rmr_install.sh b/simulators/e2sim/test/rmr_interface/rmr_install.sh
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/rmr_install.sh
rename to simulators/e2sim/test/rmr_interface/rmr_install.sh
diff --git a/simulators/e2sim/src/rmr_interface/tests/receiver/build_and_run_recvr.sh b/simulators/e2sim/test/rmr_interface/tests/receiver/build_and_run_recvr.sh
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/tests/receiver/build_and_run_recvr.sh
rename to simulators/e2sim/test/rmr_interface/tests/receiver/build_and_run_recvr.sh
diff --git a/simulators/e2sim/src/rmr_interface/tests/receiver/rmr_rcvr.c b/simulators/e2sim/test/rmr_interface/tests/receiver/rmr_rcvr.c
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/tests/receiver/rmr_rcvr.c
rename to simulators/e2sim/test/rmr_interface/tests/receiver/rmr_rcvr.c
diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/build_and_run_sender.sh b/simulators/e2sim/test/rmr_interface/tests/sender/build_and_run_sender.sh
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/tests/sender/build_and_run_sender.sh
rename to simulators/e2sim/test/rmr_interface/tests/sender/build_and_run_sender.sh
diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/rmr_sender.c b/simulators/e2sim/test/rmr_interface/tests/sender/rmr_sender.c
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/tests/sender/rmr_sender.c
rename to simulators/e2sim/test/rmr_interface/tests/sender/rmr_sender.c
diff --git a/simulators/e2sim/src/rmr_interface/tests/sender/rmr_wrapper.h b/simulators/e2sim/test/rmr_interface/tests/sender/rmr_wrapper.h
similarity index 100%
rename from simulators/e2sim/src/rmr_interface/tests/sender/rmr_wrapper.h
rename to simulators/e2sim/test/rmr_interface/tests/sender/rmr_wrapper.h
diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes
similarity index 66%
copy from simulators/e2sim/build_docker
copy to simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes
index b04e565..87ced95 100755
--- a/simulators/e2sim/build_docker
+++ b/simulators/e2sim/tools/asn_defs/generate_e2ap_e2sm_codes
@@ -18,5 +18,22 @@
 #                                                                            *
 #******************************************************************************/
 
-set -e
-sudo docker build -f docker/Dockerfile -t e2agent .
+E2AP_asn="e2ap-v031.asn"
+E2SM_asn="e2sm-gNB-X2-release-1-v041.asn"
+X2AP_asn="x2ap-no-desc-15-04.asn"
+
+GEN_DIR=../../src/ASN1c/
+
+rm -f $GEN_DIR/*.c $GEN_DIR/*.h
+
+asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
+            -fno-include-deps -D $GEN_DIR $E2AP_asn $X2AP_asn  \
+            |& egrep -v "^Copied|^Compiled" | sort -u
+
+asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example \
+            -fno-include-deps -D $GEN_DIR $E2SM_asn $X2AP_asn  \
+            |& egrep -v "^Copied|^Compiled" | sort -u
+
+echo "ASN1 C codes generated at $GEN_DIR"
+
+# asn1c -fcompound-names -fno-include-deps -findirect-choice -gen-PER -no-gen-OER  /tmp/e2ap-v031.asn /tmp/x2ap-no-desc-15-04.asn
diff --git a/simulators/e2sim/tools/build_helper.bash b/simulators/e2sim/tools/build_helper.bash
index 647d597..1759621 100644
--- a/simulators/e2sim/tools/build_helper.bash
+++ b/simulators/e2sim/tools/build_helper.bash
@@ -1,20 +1,21 @@
-# 
-#
-# Copyright 2019 AT&T Intellectual Property
-# Copyright 2019 Nokia
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
+#/*****************************************************************************
+#                                                                            *
+# Copyright 2019 AT&T Intellectual Property                                  *
+# Copyright 2019 Nokia                                                       *
+#                                                                            *
+# Licensed under the Apache License, Version 2.0 (the "License");            *
+# you may not use this file except in compliance with the License.           *
+# You may obtain a copy of the License at                                    *
+#                                                                            *
+#      http://www.apache.org/licenses/LICENSE-2.0                            *
+#                                                                            *
+# Unless required by applicable law or agreed to in writing, software        *
+# distributed under the License is distributed on an "AS IS" BASIS,          *
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
+# See the License for the specific language governing permissions and        *
+# limitations under the License.                                             *
+#                                                                            *
+#******************************************************************************/
 
 #######################################
 #            Helper Func
diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/tools/install_asn1c
similarity index 87%
copy from simulators/e2sim/build_docker
copy to simulators/e2sim/tools/install_asn1c
index b04e565..7d1391f 100755
--- a/simulators/e2sim/build_docker
+++ b/simulators/e2sim/tools/install_asn1c
@@ -18,5 +18,14 @@
 #                                                                            *
 #******************************************************************************/
 
-set -e
-sudo docker build -f docker/Dockerfile -t e2agent .
+echo "Will install asn1c"
+sudo rm -rf asn1c
+git clone https://gerrit.o-ran-sc.org/r/com/asn1c.git
+cd asn1c/
+autoreconf -iv
+./configure
+cd examples
+chmod u+x crfc2asn1.pl
+cd ..
+make
+sudo make install
diff --git a/simulators/e2sim/build_docker b/simulators/e2sim/tools/install_dependencies
similarity index 84%
copy from simulators/e2sim/build_docker
copy to simulators/e2sim/tools/install_dependencies
index b04e565..c5b3d7b 100755
--- a/simulators/e2sim/build_docker
+++ b/simulators/e2sim/tools/install_dependencies
@@ -18,5 +18,21 @@
 #                                                                            *
 #******************************************************************************/
 
-set -e
-sudo docker build -f docker/Dockerfile -t e2agent .
+sudo apt-get update \
+	&& sudo apt-get install -y \
+	build-essential \
+	git \
+	cmake \
+	libsctp-dev \
+	lksctp-tools \
+	autoconf \
+	automake \
+	libtool \
+	bison \
+	flex \
+  libboost-all-dev \
+	iputils-ping \
+	net-tools \
+	nano \
+	vim \
+  && sudo apt-get clean